code: 
  
  
  import unittest
  
  import numpy as np
  import timeout_decorator  # noqa
  
  from transformers import MarianConfig, is_flax_available
  from transformers.testing_utils import require_flax, require_sentencepiece, require_tokenizers, slow
  from transformers.utils import cached_property
  
  from ...generation.test_flax_utils import FlaxGenerationTesterMixin
  from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor
  
  
  if is_flax_available():
   import os
  
   # The slow tests are often failing with OOM error on GPU
   # This makes JAX allocate exactly what is needed on demand, and deallocate memory that is no longer needed
   # but will be slower as stated here https://jax.readthedocs.io/en/latest/gpu_memory_allocation.html
   _SCREAMING_SNAKE_CASE    :				List[str]       =					"platform"
  
   import jax
   import jax.numpy as jnp
  
   from transformers import MarianTokenizer
   from transformers.models.marian.modeling_flax_marian import FlaxMarianModel, FlaxMarianMTModel, shift_tokens_right
  def     UpperCAmelCase__		(UpperCamelCase_							,UpperCamelCase_							,UpperCamelCase_=None							,UpperCamelCase_=None							,UpperCamelCase_=None							,UpperCamelCase_=None							,UpperCamelCase_=None							,UpperCamelCase_=None							,):
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       if attention_mask is None:
            snake_case					=       np.where(input_ids != config.pad_token_id							,1							,0       )
       if decoder_attention_mask is None:
            snake_case					=       np.where(decoder_input_ids != config.pad_token_id							,1							,0       )
       if head_mask is None:
            snake_case					=       np.ones((config.encoder_layers, config.encoder_attention_heads)       )
       if decoder_head_mask is None:
            snake_case					=       np.ones((config.decoder_layers, config.decoder_attention_heads)       )
       if cross_attn_head_mask is None:
            snake_case					=       np.ones((config.decoder_layers, config.decoder_attention_heads)       )
       return {
           "input_ids": input_ids,
           "decoder_input_ids": decoder_input_ids,
           "attention_mask": attention_mask,
           "decoder_attention_mask": attention_mask,
       }
  
  class 						A__      :
  
  
  
  
  
  
  
      """simple docstring"""
  
      def __init__( self    ,      __snake_case    ,      __snake_case=1_3    ,      __snake_case=7    ,      __snake_case=True    ,      __snake_case=False    ,      __snake_case=9_9    ,      __snake_case=1_6    ,      __snake_case=2    ,      __snake_case=4    ,      __snake_case=4    ,      __snake_case="gelu"    ,      __snake_case=0.1    ,      __snake_case=0.1    ,      __snake_case=3_2    ,      __snake_case=2    ,      __snake_case=1    ,      __snake_case=0    ,      __snake_case=0.02    ,      ):
           snake_case					=       parent
           snake_case					=       batch_size
           snake_case					=       seq_length
           snake_case					=       is_training
           snake_case					=       use_labels
           snake_case					=       vocab_size
           snake_case					=       hidden_size
           snake_case					=       num_hidden_layers
           snake_case					=       num_attention_heads
           snake_case					=       intermediate_size
           snake_case					=       hidden_act
           snake_case					=       hidden_dropout_prob
           snake_case					=       attention_probs_dropout_prob
           snake_case					=       max_position_embeddings
           snake_case					=       eos_token_id
           snake_case					=       pad_token_id
           snake_case					=       bos_token_id
           snake_case					=       initializer_range
      def 	a_    ( self					):
           snake_case					=       np.clip(ids_tensor([self.batch_size, self.seq_length - 1]    ,      self.vocab_size					)    ,      3    ,      self.vocab_size					)
           snake_case					=       np.concatenate((input_ids, 2 * np.ones((self.batch_size, 1)    ,      dtype=np.intaa					))    ,      -1					)
  
           snake_case					=       shift_tokens_right(__snake_case    ,      1    ,      2					)
  
           snake_case					=       MarianConfig(
               vocab_size=self.vocab_size    ,      d_model=self.hidden_size    ,      encoder_layers=self.num_hidden_layers    ,      decoder_layers=self.num_hidden_layers    ,      encoder_attention_heads=self.num_attention_heads    ,      decoder_attention_heads=self.num_attention_heads    ,      encoder_ffn_dim=self.intermediate_size    ,      decoder_ffn_dim=self.intermediate_size    ,      dropout=self.hidden_dropout_prob    ,      attention_dropout=self.attention_probs_dropout_prob    ,      max_position_embeddings=self.max_position_embeddings    ,      eos_token_id=self.eos_token_id    ,      bos_token_id=self.bos_token_id    ,      pad_token_id=self.pad_token_id    ,      initializer_range=self.initializer_range    ,      use_cache=__snake_case    ,      )
           snake_case					=       prepare_marian_inputs_dict(__snake_case    ,      __snake_case    ,      __snake_case					)
           return config, inputs_dict
      def 	a_    ( self					):
           snake_case				,						snake_case					=       self.prepare_config_and_inputs()
           return config, inputs_dict
      def 	a_    ( self    ,      __snake_case    ,      __snake_case    ,      __snake_case					):
           snake_case					=       2_0
           snake_case					=       model_class_name(__snake_case					)
  
           snake_case					=       model.encode(inputs_dict['''input_ids''']					)
  
           snake_case				,						snake_case					=       (
               inputs_dict['''decoder_input_ids'''],
               inputs_dict['''decoder_attention_mask'''],
           )
  
           snake_case					=       model.init_cache(decoder_input_ids.shape[0]    ,      __snake_case    ,      __snake_case					)
           snake_case					=       jnp.ones((decoder_input_ids.shape[0], max_decoder_length)    ,      dtype='''i4'''					)
  
           snake_case					=       jnp.broadcast_to(
               jnp.arange(decoder_input_ids.shape[-1] - 1					)[None, :]    ,      (decoder_input_ids.shape[0], decoder_input_ids.shape[-1] - 1)    ,      )
           snake_case					=       model.decode(
               decoder_input_ids[:, :-1]    ,      __snake_case    ,      decoder_attention_mask=__snake_case    ,      past_key_values=__snake_case    ,      decoder_position_ids=__snake_case    ,      )
  
           snake_case					=       jnp.array(decoder_input_ids.shape[0] * [[decoder_input_ids.shape[-1] - 1]]    ,      dtype='''i4'''					)
           snake_case					=       model.decode(
               decoder_input_ids[:, -1:]    ,      __snake_case    ,      decoder_attention_mask=__snake_case    ,      past_key_values=outputs_cache.past_key_values    ,      decoder_position_ids=__snake_case    ,      )
  
           snake_case					=       model.decode(__snake_case    ,      __snake_case					)
  
           snake_case					=       np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])					)					)
           self.parent.assertTrue(diff < 1E-3    ,      msg=F'''Max diff is {diff}'''					)
  
  
  
  
      def 	a_    ( self    ,      __snake_case    ,      __snake_case    ,      __snake_case					):
           snake_case					=       2_0
           snake_case					=       model_class_name(__snake_case					)
  
           snake_case					=       model.encode(inputs_dict['''input_ids''']					)
  
           snake_case				,						snake_case					=       (
               inputs_dict['''decoder_input_ids'''],
               inputs_dict['''decoder_attention_mask'''],
           )
  
           snake_case					=       jnp.concatenate(
               [
                   decoder_attention_mask,
                   jnp.zeros((decoder_attention_mask.shape[0], max_decoder_length - decoder_attention_mask.shape[1])					),
               ]    ,      axis=-1    ,      )
  
           snake_case					=       model.init_cache(decoder_input_ids.shape[0]    ,      __snake_case    ,      __snake_case					)
           snake_case					=       jnp.broadcast_to(
               jnp.arange(decoder_input_ids.shape[-1] - 1					)[None, :]    ,      (decoder_input_ids.shape[0], decoder_input_ids.shape[-1] - 1)    ,      )
  
           snake_case					=       model.decode(
               decoder_input_ids[:, :-1]    ,      __snake_case    ,      decoder_attention_mask=__snake_case    ,      past_key_values=__snake_case    ,      decoder_position_ids=__snake_case    ,      )
           snake_case					=       jnp.array(decoder_input_ids.shape[0] * [[decoder_input_ids.shape[-1] - 1]]    ,      dtype='''i4'''					)
           snake_case					=       model.decode(
               decoder_input_ids[:, -1:]    ,      __snake_case    ,      past_key_values=outputs_cache.past_key_values    ,      decoder_attention_mask=__snake_case    ,      decoder_position_ids=__snake_case    ,      )
  
           snake_case					=       model.decode(__snake_case    ,      __snake_case    ,      decoder_attention_mask=__snake_case					)
  
           snake_case					=       np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])					)					)
           self.parent.assertTrue(diff < 1E-3    ,      msg=F'''Max diff is {diff}'''					)
  
  
  
  
  
  
  @require_flax
  class 						A__      (					snake_case__ ,      unittest.TestCase ,      snake_case__			):
  
  
  
  
  
  
  
      """simple docstring"""
  
      __magic_name__    						=	True
      __magic_name__    						=	(FlaxMarianModel, FlaxMarianMTModel) if is_flax_available() else ()
      __magic_name__    						=	(FlaxMarianMTModel,) if is_flax_available() else ()
      def 	a_    ( self					):
           snake_case					=       FlaxMarianModelTester(self					)
      def 	a_    ( self					):
           snake_case				,						snake_case					=       self.model_tester.prepare_config_and_inputs()
           for model_class in self.all_model_classes:
                self.model_tester.check_use_cache_forward(__snake_case    ,      __snake_case    ,      __snake_case					)
      def 	a_    ( self					):
           snake_case				,						snake_case					=       self.model_tester.prepare_config_and_inputs()
           for model_class in self.all_model_classes:
                self.model_tester.check_use_cache_forward_with_attn_mask(__snake_case    ,      __snake_case    ,      __snake_case					)
      def 	a_    ( self					):
           snake_case				,						snake_case					=       self.model_tester.prepare_config_and_inputs_for_common()
  
           for model_class in self.all_model_classes:
                with self.subTest(model_class.__name__					):
                     snake_case					=       self._prepare_for_class(__snake_case    ,      __snake_case					)
                     snake_case					=       model_class(__snake_case					)
  
                     @jax.jit
                     def encode_jitted(__snake_case    ,      __snake_case=None    ,      **__snake_case					):
                          return model.encode(input_ids=__snake_case    ,      attention_mask=__snake_case					)
  
                     with self.subTest('''JIT Enabled'''					):
                          snake_case					=       encode_jitted(**__snake_case					).to_tuple()
  
                     with self.subTest('''JIT Disabled'''					):
                          with jax.disable_jit():
                               snake_case					=       encode_jitted(**__snake_case					).to_tuple()
  
                     self.assertEqual(len(__snake_case					)    ,      len(__snake_case					)					)
                     for jitted_output, output in zip(__snake_case    ,      __snake_case					):
                          self.assertEqual(jitted_output.shape    ,      output.shape					)
      def 	a_    ( self					):
           snake_case				,						snake_case					=       self.model_tester.prepare_config_and_inputs_for_common()
  
           for model_class in self.all_model_classes:
                with self.subTest(model_class.__name__					):
                     snake_case					=       model_class(__snake_case					)
                     snake_case					=       model.encode(inputs_dict['''input_ids''']    ,      inputs_dict['''attention_mask''']					)
  
                     snake_case					=       {
                         '''decoder_input_ids''': inputs_dict['''decoder_input_ids'''],
                         '''decoder_attention_mask''': inputs_dict['''decoder_attention_mask'''],
                         '''encoder_outputs''': encoder_outputs,
                     }
  
                     @jax.jit
                     def decode_jitted(__snake_case    ,      __snake_case    ,      __snake_case					):
                          return model.decode(
                              decoder_input_ids=__snake_case    ,      decoder_attention_mask=__snake_case    ,      encoder_outputs=__snake_case    ,      )
  
                     with self.subTest('''JIT Enabled'''					):
                          snake_case					=       decode_jitted(**__snake_case					).to_tuple()
  
                     with self.subTest('''JIT Disabled'''					):
                          with jax.disable_jit():
                               snake_case					=       decode_jitted(**__snake_case					).to_tuple()
  
                     self.assertEqual(len(__snake_case					)    ,      len(__snake_case					)					)
                     for jitted_output, output in zip(__snake_case    ,      __snake_case					):
                          self.assertEqual(jitted_output.shape    ,      output.shape					)
  
  
  
  
      @slow
      def 	a_    ( self					):
           for model_class_name in self.all_model_classes:
                snake_case					=       model_class_name.from_pretrained('''Helsinki-NLP/opus-mt-en-de'''					)
                # FlaxMarianForSequenceClassification expects eos token in input_ids
                snake_case					=       np.ones((1, 1)					) * model.config.eos_token_id
                snake_case					=       model(__snake_case					)
                self.assertIsNotNone(__snake_case					)
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						A__      (					unittest.TestCase			):
  
  
  
  
  
  
  
      """simple docstring"""
  
      __magic_name__    						=	None
      __magic_name__    						=	None
      @classmethod
      def 	a_    ( cls					):
           snake_case					=       F'''Helsinki-NLP/opus-mt-{cls.src}-{cls.tgt}'''
           return cls
      @cached_property
      def 	a_    ( self					):
           return MarianTokenizer.from_pretrained(self.model_name					)
      @property
      def 	a_    ( self					):
           return self.tokenizer.eos_token_id
      @cached_property
      def 	a_    ( self					):
           snake_case					=       FlaxMarianMTModel.from_pretrained(self.model_name					)
           self.assertEqual(model.config.decoder_start_token_id    ,      model.config.pad_token_id					)
           return model
      def 	a_    ( self    ,      **__snake_case					):
           snake_case					=       self.translate_src_text(**__snake_case					)
           self.assertListEqual(self.expected_text    ,      __snake_case					)
  
  
  
  
      def 	a_    ( self    ,      **__snake_case					):
           snake_case					=       self.tokenizer(self.src_text    ,      padding=__snake_case    ,      return_tensors='''np'''    ,      **__snake_case					)
           snake_case					=       self.model.generate(
               model_inputs.input_ids    ,      attention_mask=model_inputs.attention_mask    ,      num_beams=2    ,      max_length=1_2_8    ,      ).sequences
           snake_case					=       self.tokenizer.batch_decode(__snake_case    ,      skip_special_tokens=__snake_case					)
           return generated_words
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						A__      (					snake_case__			):
  
  
  
  
  
  
  
      """simple docstring"""
  
      __magic_name__    						=	'en'
      __magic_name__    						=	'fr'
      __magic_name__    						=	[
          'I am a small frog.',
          'Now I can forget the 100 words of german that I know.',
      ]
      __magic_name__    						=	[
          'Je suis une petite grenouille.',
          'Maintenant, je peux oublier les 100 mots d\'allemand que je connais.',
      ]
      @slow
      def 	a_    ( self					):
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						A__      (					snake_case__			):
  
  
  
  
  
  
  
      """simple docstring"""
  
      __magic_name__    						=	'fr'
      __magic_name__    						=	'en'
      __magic_name__    						=	[
          'Donnez moi le micro.',
          'Tom et Mary étaient assis à une table.',  # Accents
      ]
      __magic_name__    						=	[
          'Give me the microphone.',
          'Tom and Mary were sitting at a table.',
      ]
      @slow
      def 	a_    ( self					):
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						A__      (					snake_case__			):
  
  
  
  
  
  
  
      """simple docstring"""
  
      __magic_name__    						=	'mt'
      __magic_name__    						=	'en'
      __magic_name__    						=	['Billi messu b\'mod ġentili, Ġesù fejjaq raġel li kien milqut bil - marda kerha tal - ġdiem.']
      __magic_name__    						=	['Touching gently, Jesus healed a man who was affected by the sad disease of leprosy.']
      @slow
      def 	a_    ( self					):
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						A__      (					snake_case__			):
  
  
  
  
  
  
  
      """simple docstring"""
  
      __magic_name__    						=	'en'
      __magic_name__    						=	'de'
      __magic_name__    						=	[
          'I am a small frog.',
          'Now I can forget the 100 words of german that I know.',
          'Tom asked his teacher for advice.',
          'That\'s how I would do it.',
          'Tom really admired Mary\'s courage.',
          'Turn around and close your eyes.',
      ]
      __magic_name__    						=	[
          'Ich bin ein kleiner Frosch.',
          'Jetzt kann ich die 100 Wörter des Deutschen vergessen, die ich kenne.',
          'Tom bat seinen Lehrer um Rat.',
          'So würde ich das machen.',
          'Tom bewunderte Marias Mut wirklich.',
          'Drehen Sie sich um und schließen Sie die Augen.',
      ]
      @slow
      def 	a_    ( self					):
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						A__      (					snake_case__			):
  
  
  
  
  
  
  
      """simple docstring"""
  
      __magic_name__    						=	'en'
      __magic_name__    						=	'zh'
      __magic_name__    						=	['My name is Wolfgang and I live in Berlin']
      __magic_name__    						=	['我叫沃尔夫冈 我住在柏林']
      @slow
      def 	a_    ( self					):
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						A__      (					snake_case__			):
  
  
  
  
  
  
  
      """simple docstring"""
  
      __magic_name__    						=	'ru'
      __magic_name__    						=	'fr'
      __magic_name__    						=	['Он показал мне рукопись своей новой пьесы.']
      __magic_name__    						=	['Il m\'a montré le manuscrit de sa nouvelle pièce.']
      @slow
      def 	a_    ( self					):
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						A__      (					snake_case__			):
  
  
  
  
  
  
  
      """simple docstring"""
  
      __magic_name__    						=	'en'
      __magic_name__    						=	'ROMANCE'
      __magic_name__    						=	[
          '>>fr<< Don\'t spend so much time watching TV.',
          '>>pt<< Your message has been sent.',
          '>>es<< He\'s two years older than me.',
      ]
      __magic_name__    						=	[
          'Ne passez pas autant de temps à regarder la télé.',
          'A sua mensagem foi enviada.',
          'Es dos años más viejo que yo.',
      ]
      @slow
      def 	a_    ( self					):
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
style_context: 
  
  
  import gc
  import unittest
  
  import numpy as np
  import torch
  from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer
  
  from diffusers import (
      AutoencoderKL,
      DDIMParallelScheduler,
      DDPMParallelScheduler,
      StableDiffusionParadigmsPipeline,
      UNetaDConditionModel,
  )
  from diffusers.utils import slow, torch_device
  from diffusers.utils.testing_utils import (
      enable_full_determinism,
      require_torch_gpu,
  )
  
  from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
  from ..test_pipelines_common import PipelineLatentTesterMixin, PipelineTesterMixin
  
  
  enable_full_determinism()
  
  class 						A__      (					snake_case__ ,      snake_case__ ,      unittest.TestCase			):
  
  
  
  
  
  
  
      """simple docstring"""
  
      __magic_name__    						=	StableDiffusionParadigmsPipeline
      __magic_name__    						=	TEXT_TO_IMAGE_PARAMS
      __magic_name__    						=	TEXT_TO_IMAGE_BATCH_PARAMS
      __magic_name__    						=	TEXT_TO_IMAGE_IMAGE_PARAMS
      __magic_name__    						=	TEXT_TO_IMAGE_IMAGE_PARAMS
      def 	a_    ( self					):
           torch.manual_seed(0					)
           snake_case					=       UNetaDConditionModel(
               block_out_channels=(3_2, 6_4)    ,      layers_per_block=2    ,      sample_size=3_2    ,      in_channels=4    ,      out_channels=4    ,      down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')    ,      up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')    ,      cross_attention_dim=3_2    ,      attention_head_dim=(2, 4)    ,      use_linear_projection=__snake_case    ,      )
           snake_case					=       DDIMParallelScheduler(
               beta_start=0.0_0085    ,      beta_end=0.012    ,      beta_schedule='''scaled_linear'''    ,      clip_sample=__snake_case    ,      set_alpha_to_one=__snake_case    ,      )
           torch.manual_seed(0					)
           snake_case					=       AutoencoderKL(
               block_out_channels=[3_2, 6_4]    ,      in_channels=3    ,      out_channels=3    ,      down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']    ,      up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']    ,      latent_channels=4    ,      sample_size=1_2_8    ,      )
           torch.manual_seed(0					)
           snake_case					=       CLIPTextConfig(
               bos_token_id=0    ,      eos_token_id=2    ,      hidden_size=3_2    ,      intermediate_size=3_7    ,      layer_norm_eps=1E-05    ,      num_attention_heads=4    ,      num_hidden_layers=5    ,      pad_token_id=1    ,      vocab_size=1_0_0_0    ,      hidden_act='''gelu'''    ,      projection_dim=5_1_2    ,      )
           snake_case					=       CLIPTextModel(__snake_case					)
           snake_case					=       CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''					)
  
           snake_case					=       {
               '''unet''': unet,
               '''scheduler''': scheduler,
               '''vae''': vae,
               '''text_encoder''': text_encoder,
               '''tokenizer''': tokenizer,
               '''safety_checker''': None,
               '''feature_extractor''': None,
           }
           return components
      def 	a_    ( self    ,      __snake_case    ,      __snake_case=0					):
           if str(__snake_case					).startswith('''mps'''					):
                snake_case					=       torch.manual_seed(__snake_case					)
           else:
                snake_case					=       torch.Generator(device=__snake_case					).manual_seed(__snake_case					)
           snake_case					=       {
               '''prompt''': '''a photograph of an astronaut riding a horse''',
               '''generator''': generator,
               '''num_inference_steps''': 1_0,
               '''guidance_scale''': 6.0,
               '''output_type''': '''numpy''',
               '''parallel''': 3,
               '''debug''': True,
           }
           return inputs
      def 	a_    ( self					):
           snake_case					=       '''cpu'''  # ensure determinism for the device-dependent torch.Generator
           snake_case					=       self.get_dummy_components()
           snake_case					=       StableDiffusionParadigmsPipeline(**__snake_case					)
           snake_case					=       sd_pipe.to(__snake_case					)
           sd_pipe.set_progress_bar_config(disable=__snake_case					)
  
           snake_case					=       self.get_dummy_inputs(__snake_case					)
           snake_case					=       sd_pipe(**__snake_case					).images
           snake_case					=       image[0, -3:, -3:, -1]
           assert image.shape == (1, 6_4, 6_4, 3)
  
           snake_case					=       np.array([0.4773, 0.5417, 0.4723, 0.4925, 0.5631, 0.4752, 0.5240, 0.4935, 0.5023]					)
  
           assert np.abs(image_slice.flatten() - expected_slice					).max() < 1E-2
      def 	a_    ( self					):
           snake_case					=       '''cpu'''  # ensure determinism for the device-dependent torch.Generator
           snake_case					=       self.get_dummy_components()
           torch.manual_seed(0					)
           snake_case					=       DDPMParallelScheduler()
           torch.manual_seed(0					)
           snake_case					=       StableDiffusionParadigmsPipeline(**__snake_case					)
           snake_case					=       sd_pipe.to(__snake_case					)
           sd_pipe.set_progress_bar_config(disable=__snake_case					)
  
           snake_case					=       self.get_dummy_inputs(__snake_case					)
           snake_case					=       sd_pipe(**__snake_case					).images
           snake_case					=       image[0, -3:, -3:, -1]
           assert image.shape == (1, 6_4, 6_4, 3)
  
           snake_case					=       np.array([0.3573, 0.4420, 0.4960, 0.4799, 0.3796, 0.3879, 0.4819, 0.4365, 0.4468]					)
  
           assert np.abs(image_slice.flatten() - expected_slice					).max() < 1E-2
      def 	a_    ( self					):
           super().test_inference_batch_consistent(batch_sizes=[1, 2]					)
      def 	a_    ( self					):
           super().test_inference_batch_single_identical(batch_size=2    ,      expected_max_diff=3E-3					)
  
  
  
  
      def 	a_    ( self					):
           snake_case					=       '''cpu'''  # ensure determinism for the device-dependent torch.Generator
           snake_case					=       self.get_dummy_components()
           snake_case					=       StableDiffusionParadigmsPipeline(**__snake_case					)
           snake_case					=       sd_pipe.to(__snake_case					)
           sd_pipe.set_progress_bar_config(disable=__snake_case					)
  
           snake_case					=       self.get_dummy_inputs(__snake_case					)
           snake_case					=       '''french fries'''
           snake_case					=       sd_pipe(**__snake_case    ,      negative_prompt=__snake_case					)
           snake_case					=       output.images
           snake_case					=       image[0, -3:, -3:, -1]
  
           assert image.shape == (1, 6_4, 6_4, 3)
  
           snake_case					=       np.array([0.4771, 0.5420, 0.4683, 0.4918, 0.5636, 0.4725, 0.5230, 0.4923, 0.5015]					)
  
           assert np.abs(image_slice.flatten() - expected_slice					).max() < 1E-2
  
  
  
  
  
  
  @slow
  @require_torch_gpu
  class 						A__      (					unittest.TestCase			):
  
  
  
  
  
  
  
      """simple docstring"""
  
      def 	a_    ( self					):
           super().tearDown()
           gc.collect()
           torch.cuda.empty_cache()
      def 	a_    ( self    ,      __snake_case=0					):
           snake_case					=       torch.Generator(device=__snake_case					).manual_seed(__snake_case					)
           snake_case					=       {
               '''prompt''': '''a photograph of an astronaut riding a horse''',
               '''generator''': generator,
               '''num_inference_steps''': 1_0,
               '''guidance_scale''': 7.5,
               '''output_type''': '''numpy''',
               '''parallel''': 3,
               '''debug''': True,
           }
           return inputs
  
  
  
  
      def 	a_    ( self					):
           snake_case					=       '''stabilityai/stable-diffusion-2-base'''
           snake_case					=       DDIMParallelScheduler.from_pretrained(__snake_case    ,      subfolder='''scheduler'''					)
           snake_case					=       StableDiffusionParadigmsPipeline.from_pretrained(__snake_case    ,      scheduler=__snake_case    ,      safety_checker=__snake_case					)
           pipe.to(__snake_case					)
           pipe.set_progress_bar_config(disable=__snake_case					)
           pipe.enable_attention_slicing()
  
           snake_case					=       self.get_inputs()
           snake_case					=       pipe(**__snake_case					).images
           snake_case					=       image[0, -3:, -3:, -1].flatten()
  
           assert image.shape == (1, 5_1_2, 5_1_2, 3)
  
           snake_case					=       np.array([0.9622, 0.9602, 0.9748, 0.9591, 0.9630, 0.9691, 0.9661, 0.9631, 0.9741]					)
  
           assert np.abs(expected_slice - image_slice					).max() < 1E-2
  
  
  
  
  