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
         lowercase__			=	'''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	(  snake_case	,     snake_case	,     snake_case=None	,     snake_case=None	,     snake_case=None	,     snake_case=None	,     snake_case=None	,     snake_case=None	,     ):
  
  
  
  
     '''simple docstring'''
  
     if attention_mask is None:
        SCREAMING_SNAKE_CASE__			:				Any       						= np.where(input_ids != config.pad_token_id	,     1	,     0   )
     if decoder_attention_mask is None:
        SCREAMING_SNAKE_CASE__			:				List[Any]       						= np.where(decoder_input_ids != config.pad_token_id	,     1	,     0   )
     if head_mask is None:
        SCREAMING_SNAKE_CASE__			:				str       						= np.ones((config.encoder_layers, config.encoder_attention_heads)   )
     if decoder_head_mask is None:
        SCREAMING_SNAKE_CASE__			:				List[str]       						= np.ones((config.decoder_layers, config.decoder_attention_heads)   )
     if cross_attn_head_mask is None:
        SCREAMING_SNAKE_CASE__			:				Dict       						= 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 						lowercase     :
  
  
  
  
  
  
        def __init__(self ,  a__ ,  a__=1_3 ,  a__=7 ,  a__=True ,  a__=False ,  a__=9_9 ,  a__=1_6 ,  a__=2 ,  a__=4 ,  a__=4 ,  a__="gelu" ,  a__=0.1 ,  a__=0.1 ,  a__=3_2 ,  a__=2 ,  a__=1 ,  a__=0 ,  a__=0.02 ,  )       ->   Any:
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= parent
           SCREAMING_SNAKE_CASE__			:				Any       						= batch_size
           SCREAMING_SNAKE_CASE__			:				Dict       						= seq_length
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= is_training
           SCREAMING_SNAKE_CASE__			:				int       						= use_labels
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= vocab_size
           SCREAMING_SNAKE_CASE__			:				Tuple       						= hidden_size
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= num_hidden_layers
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= num_attention_heads
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= intermediate_size
           SCREAMING_SNAKE_CASE__			:				Tuple       						= hidden_act
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= hidden_dropout_prob
           SCREAMING_SNAKE_CASE__			:				Dict       						= attention_probs_dropout_prob
           SCREAMING_SNAKE_CASE__			:				Dict       						= max_position_embeddings
           SCREAMING_SNAKE_CASE__			:				Tuple       						= eos_token_id
           SCREAMING_SNAKE_CASE__			:				Any       						= pad_token_id
           SCREAMING_SNAKE_CASE__			:				int       						= bos_token_id
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= initializer_range
  
  
  
  
  
  
        def    A__(self					)       ->   List[Any]:
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= np.clip(ids_tensor([self.batch_size, self.seq_length - 1] ,  self.vocab_size					) ,  3 ,  self.vocab_size					)
           SCREAMING_SNAKE_CASE__			:				str       						= np.concatenate((input_ids, 2 * np.ones((self.batch_size, 1) ,  dtype=np.intaa					)) ,  -1					)
  
           SCREAMING_SNAKE_CASE__			:				str       						= shift_tokens_right(a__ ,  1 ,  2					)
  
           SCREAMING_SNAKE_CASE__			:				List[str]       						= 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=a__ ,  )
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= prepare_marian_inputs_dict(a__ ,  a__ ,  a__					)
           return config, inputs_dict
  
  
  
  
  
  
        def    A__(self					)       ->   Tuple:
           SCREAMING_SNAKE_CASE__			:				Tuple       						= self.prepare_config_and_inputs()
           return config, inputs_dict
  
  
  
  
  
  
        def    A__(self ,  a__ ,  a__ ,  a__					)       ->   int:
           SCREAMING_SNAKE_CASE__			:				Tuple       						= 2_0
           SCREAMING_SNAKE_CASE__			:				List[str]       						= model_class_name(a__					)
  
           SCREAMING_SNAKE_CASE__			:				Tuple       						= model.encode(inputs_dict['''input_ids''']					)
  
           SCREAMING_SNAKE_CASE__			:				Tuple       						= (
               inputs_dict['''decoder_input_ids'''],
               inputs_dict['''decoder_attention_mask'''],
           )
  
           SCREAMING_SNAKE_CASE__			:				Tuple       						= model.init_cache(decoder_input_ids.shape[0] ,  a__ ,  a__					)
           SCREAMING_SNAKE_CASE__			:				Tuple       						= jnp.ones((decoder_input_ids.shape[0], max_decoder_length) ,  dtype='''i4'''					)
  
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= jnp.broadcast_to(
               jnp.arange(decoder_input_ids.shape[-1] - 1					)[None, :] ,  (decoder_input_ids.shape[0], decoder_input_ids.shape[-1] - 1) ,  )
           SCREAMING_SNAKE_CASE__			:				Any       						= model.decode(
               decoder_input_ids[:, :-1] ,  a__ ,  decoder_attention_mask=a__ ,  past_key_values=a__ ,  decoder_position_ids=a__ ,  )
  
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= jnp.array(decoder_input_ids.shape[0] * [[decoder_input_ids.shape[-1] - 1]] ,  dtype='''i4'''					)
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= model.decode(
               decoder_input_ids[:, -1:] ,  a__ ,  decoder_attention_mask=a__ ,  past_key_values=outputs_cache.past_key_values ,  decoder_position_ids=a__ ,  )
  
           SCREAMING_SNAKE_CASE__			:				int       						= model.decode(a__ ,  a__					)
  
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= 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 ,  a__ ,  a__ ,  a__					)       ->   List[Any]:
           SCREAMING_SNAKE_CASE__			:				Dict       						= 2_0
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= model_class_name(a__					)
  
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= model.encode(inputs_dict['''input_ids''']					)
  
           SCREAMING_SNAKE_CASE__			:				List[str]       						= (
               inputs_dict['''decoder_input_ids'''],
               inputs_dict['''decoder_attention_mask'''],
           )
  
           SCREAMING_SNAKE_CASE__			:				List[str]       						= jnp.concatenate(
               [
                   decoder_attention_mask,
                   jnp.zeros((decoder_attention_mask.shape[0], max_decoder_length - decoder_attention_mask.shape[1])					),
               ] ,  axis=-1 ,  )
  
           SCREAMING_SNAKE_CASE__			:				List[str]       						= model.init_cache(decoder_input_ids.shape[0] ,  a__ ,  a__					)
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= jnp.broadcast_to(
               jnp.arange(decoder_input_ids.shape[-1] - 1					)[None, :] ,  (decoder_input_ids.shape[0], decoder_input_ids.shape[-1] - 1) ,  )
  
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= model.decode(
               decoder_input_ids[:, :-1] ,  a__ ,  decoder_attention_mask=a__ ,  past_key_values=a__ ,  decoder_position_ids=a__ ,  )
           SCREAMING_SNAKE_CASE__			:				Tuple       						= jnp.array(decoder_input_ids.shape[0] * [[decoder_input_ids.shape[-1] - 1]] ,  dtype='''i4'''					)
           SCREAMING_SNAKE_CASE__			:				Any       						= model.decode(
               decoder_input_ids[:, -1:] ,  a__ ,  past_key_values=outputs_cache.past_key_values ,  decoder_attention_mask=a__ ,  decoder_position_ids=a__ ,  )
  
           SCREAMING_SNAKE_CASE__			:				List[str]       						= model.decode(a__ ,  a__ ,  decoder_attention_mask=a__					)
  
           SCREAMING_SNAKE_CASE__			:				Any       						= 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 						lowercase     (   UpperCAmelCase_				,			unittest.TestCase				,			UpperCAmelCase_):
        __lowercase 		=  True
        __lowercase 		=  (FlaxMarianModel, FlaxMarianMTModel) if is_flax_available() else ()
        __lowercase 		=  (FlaxMarianMTModel,) if is_flax_available() else ()
  
  
  
  
  
  
        def    A__(self					)       ->   List[str]:
           SCREAMING_SNAKE_CASE__			:				str       						= FlaxMarianModelTester(self					)
  
  
  
  
  
  
        def    A__(self					)       ->   str:
           SCREAMING_SNAKE_CASE__			:				str       						= self.model_tester.prepare_config_and_inputs()
           for model_class in self.all_model_classes:
              self.model_tester.check_use_cache_forward(a__ ,  a__ ,  a__					)
  
  
  
  
  
  
        def    A__(self					)       ->   List[str]:
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= 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(a__ ,  a__ ,  a__					)
  
  
  
  
  
  
        def    A__(self					)       ->   Tuple:
           SCREAMING_SNAKE_CASE__			:				Dict       						= self.model_tester.prepare_config_and_inputs_for_common()
  
           for model_class in self.all_model_classes:
              with self.subTest(model_class.__name__					):
                 SCREAMING_SNAKE_CASE__			:				int       						= self._prepare_for_class(a__ ,  a__					)
                 SCREAMING_SNAKE_CASE__			:				Any       						= model_class(a__					)
  
                 @jax.jit
                 def encode_jitted(a__ ,  a__=None ,  **a__					):
                    return model.encode(input_ids=a__ ,  attention_mask=a__					)
  
                 with self.subTest('''JIT Enabled'''					):
                    SCREAMING_SNAKE_CASE__			:				int       						= encode_jitted(**a__					).to_tuple()
  
                 with self.subTest('''JIT Disabled'''					):
                    with jax.disable_jit():
                       SCREAMING_SNAKE_CASE__			:				List[str]       						= encode_jitted(**a__					).to_tuple()
  
                 self.assertEqual(len(a__					) ,  len(a__					)					)
                 for jitted_output, output in zip(a__ ,  a__					):
                    self.assertEqual(jitted_output.shape ,  output.shape					)
  
  
  
  
  
  
        def    A__(self					)       ->   Any:
           SCREAMING_SNAKE_CASE__			:				Tuple       						= self.model_tester.prepare_config_and_inputs_for_common()
  
           for model_class in self.all_model_classes:
              with self.subTest(model_class.__name__					):
                 SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= model_class(a__					)
                 SCREAMING_SNAKE_CASE__			:				Tuple       						= model.encode(inputs_dict['''input_ids'''] ,  inputs_dict['''attention_mask''']					)
  
                 SCREAMING_SNAKE_CASE__			:				int       						= {
                     '''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(a__ ,  a__ ,  a__					):
                    return model.decode(
                        decoder_input_ids=a__ ,  decoder_attention_mask=a__ ,  encoder_outputs=a__ ,  )
  
                 with self.subTest('''JIT Enabled'''					):
                    SCREAMING_SNAKE_CASE__			:				int       						= decode_jitted(**a__					).to_tuple()
  
                 with self.subTest('''JIT Disabled'''					):
                    with jax.disable_jit():
                       SCREAMING_SNAKE_CASE__			:				List[Any]       						= decode_jitted(**a__					).to_tuple()
  
                 self.assertEqual(len(a__					) ,  len(a__					)					)
                 for jitted_output, output in zip(a__ ,  a__					):
                    self.assertEqual(jitted_output.shape ,  output.shape					)
  
  
  
  
  
  
        @slow
        def    A__(self					)       ->   Optional[int]:
           for model_class_name in self.all_model_classes:
              SCREAMING_SNAKE_CASE__			:				List[str]       						= model_class_name.from_pretrained('''Helsinki-NLP/opus-mt-en-de'''					)
              # FlaxMarianForSequenceClassification expects eos token in input_ids
              SCREAMING_SNAKE_CASE__			:				int       						= np.ones((1, 1)					) * model.config.eos_token_id
              SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= model(a__					)
              self.assertIsNotNone(a__					)
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						lowercase     (   unittest.TestCase):
        __lowercase 		=  None
        __lowercase 		=  None
  
  
  
  
  
  
        @classmethod
        def    A__(cls					)       ->   None:
           SCREAMING_SNAKE_CASE__			:				Any       						= f"""Helsinki-NLP/opus-mt-{cls.src}-{cls.tgt}"""
           return cls
  
  
  
  
  
  
        @cached_property
        def    A__(self					)       ->   str:
           return MarianTokenizer.from_pretrained(self.model_name					)
  
  
  
  
  
  
        @property
        def    A__(self					)       ->   int:
           return self.tokenizer.eos_token_id
  
  
  
  
  
  
        @cached_property
        def    A__(self					)       ->   Dict:
           SCREAMING_SNAKE_CASE__			:				FlaxMarianMTModel       						= FlaxMarianMTModel.from_pretrained(self.model_name					)
           self.assertEqual(model.config.decoder_start_token_id ,  model.config.pad_token_id					)
           return model
  
  
  
  
  
  
        def    A__(self ,  **a__					)       ->   Optional[Any]:
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= self.translate_src_text(**a__					)
           self.assertListEqual(self.expected_text ,  a__					)
  
  
  
  
  
  
        def    A__(self ,  **a__					)       ->   List[str]:
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= self.tokenizer(self.src_text ,  padding=a__ ,  return_tensors='''np''' ,  **a__					)
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= self.model.generate(
               model_inputs.input_ids ,  attention_mask=model_inputs.attention_mask ,  num_beams=2 ,  max_length=1_2_8 ,  ).sequences
           SCREAMING_SNAKE_CASE__			:				int       						= self.tokenizer.batch_decode(a__ ,  skip_special_tokens=a__					)
           return generated_words
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						lowercase     (   UpperCAmelCase_):
        __lowercase 		=  '''en'''
        __lowercase 		=  '''fr'''
        __lowercase 		=  [
            '''I am a small frog.''',
            '''Now I can forget the 100 words of german that I know.''',
        ]
        __lowercase 		=  [
            '''Je suis une petite grenouille.''',
            '''Maintenant, je peux oublier les 100 mots d\'allemand que je connais.''',
        ]
  
  
  
  
  
  
        @slow
        def    A__(self					)       ->   Union[str, Any]:
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						lowercase     (   UpperCAmelCase_):
        __lowercase 		=  '''fr'''
        __lowercase 		=  '''en'''
        __lowercase 		=  [
            '''Donnez moi le micro.''',
            '''Tom et Mary étaient assis à une table.''',  # Accents
        ]
        __lowercase 		=  [
            '''Give me the microphone.''',
            '''Tom and Mary were sitting at a table.''',
        ]
  
  
  
  
  
  
        @slow
        def    A__(self					)       ->   Optional[Any]:
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						lowercase     (   UpperCAmelCase_):
        __lowercase 		=  '''mt'''
        __lowercase 		=  '''en'''
        __lowercase 		=  ['''Billi messu b\'mod ġentili, Ġesù fejjaq raġel li kien milqut bil - marda kerha tal - ġdiem.''']
        __lowercase 		=  ['''Touching gently, Jesus healed a man who was affected by the sad disease of leprosy.''']
  
  
  
  
  
  
        @slow
        def    A__(self					)       ->   Optional[Any]:
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						lowercase     (   UpperCAmelCase_):
        __lowercase 		=  '''en'''
        __lowercase 		=  '''de'''
        __lowercase 		=  [
            '''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.''',
        ]
        __lowercase 		=  [
            '''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					)       ->   int:
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						lowercase     (   UpperCAmelCase_):
        __lowercase 		=  '''en'''
        __lowercase 		=  '''zh'''
        __lowercase 		=  ['''My name is Wolfgang and I live in Berlin''']
        __lowercase 		=  ['''我叫沃尔夫冈 我住在柏林''']
  
  
  
  
  
  
        @slow
        def    A__(self					)       ->   List[Any]:
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						lowercase     (   UpperCAmelCase_):
        __lowercase 		=  '''ru'''
        __lowercase 		=  '''fr'''
        __lowercase 		=  ['''Он показал мне рукопись своей новой пьесы.''']
        __lowercase 		=  ['''Il m\'a montré le manuscrit de sa nouvelle pièce.''']
  
  
  
  
  
  
        @slow
        def    A__(self					)       ->   Dict:
           self._assert_generated_batch_equal_expected()
  
  
  
  
  
  
  @require_flax
  @require_sentencepiece
  @require_tokenizers
  class 						lowercase     (   UpperCAmelCase_):
        __lowercase 		=  '''en'''
        __lowercase 		=  '''ROMANCE'''
        __lowercase 		=  [
            '''>>fr<< Don\'t spend so much time watching TV.''',
            '''>>pt<< Your message has been sent.''',
            '''>>es<< He\'s two years older than me.''',
        ]
        __lowercase 		=  [
            '''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					)       ->   int:
           self._assert_generated_batch_equal_expected()
  
  
style_context: 
  
  
  
  
  '''simple docstring'''
  
  
  
  
  
  import unittest
  
  import requests
  
  from transformers import MODEL_FOR_VISION_2_SEQ_MAPPING, TF_MODEL_FOR_VISION_2_SEQ_MAPPING, is_vision_available
  from transformers.pipelines import pipeline
  from transformers.testing_utils import (
      is_pipeline_test,
      is_torch_available,
      require_tf,
      require_torch,
      require_vision,
      slow,
  )
  
  from .test_pipelines_common import ANY
  
  
  if is_torch_available():
         from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
  else:
         lowercase__			=	False
  
  
  if is_vision_available():
         from PIL import Image
  else:
  
  
  
  
  
  
         class 						lowercase     :
  
  
  
  
  
  
               @staticmethod
               def    A__(*a__ ,  **a__					)       ->   Optional[Any]:
                  pass
  
  
  
  
  
  
  @is_pipeline_test
  @require_vision
  class 						lowercase     (   unittest.TestCase):
        __lowercase 		=  MODEL_FOR_VISION_2_SEQ_MAPPING
        __lowercase 		=  TF_MODEL_FOR_VISION_2_SEQ_MAPPING
  
  
  
  
  
  
        def    A__(self ,  a__ ,  a__ ,  a__					)       ->   Optional[Any]:
           SCREAMING_SNAKE_CASE__			:				Tuple       						= pipeline('''image-to-text''' ,  model=a__ ,  tokenizer=a__ ,  image_processor=a__					)
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= [
               Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''					),
               '''./tests/fixtures/tests_samples/COCO/000000039769.png''',
           ]
           return pipe, examples
  
  
  
  
  
  
        def    A__(self ,  a__ ,  a__					)       ->   Any:
           SCREAMING_SNAKE_CASE__			:				Tuple       						= pipe(a__					)
           self.assertEqual(
               a__ ,  [
                   [{'''generated_text''': ANY(a__					)}],
                   [{'''generated_text''': ANY(a__					)}],
               ] ,  )
  
  
  
  
  
  
        @require_tf
        def    A__(self					)       ->   List[str]:
           SCREAMING_SNAKE_CASE__			:				List[str]       						= pipeline('''image-to-text''' ,  model='''hf-internal-testing/tiny-random-vit-gpt2''' ,  framework='''tf'''					)
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= '''./tests/fixtures/tests_samples/COCO/000000039769.png'''
  
           SCREAMING_SNAKE_CASE__			:				str       						= pipe(a__					)
           self.assertEqual(
               a__ ,  [
                   {
                       '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                   },
               ] ,  )
  
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= pipe([image, image]					)
           self.assertEqual(
               a__ ,  [
                   [
                       {
                           '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                       }
                   ],
                   [
                       {
                           '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                       }
                   ],
               ] ,  )
  
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= pipe(a__ ,  max_new_tokens=1					)
           self.assertEqual(
               a__ ,  [{'''generated_text''': '''growth'''}] ,  )
  
  
  
  
  
  
        @require_torch
        def    A__(self					)       ->   Optional[Any]:
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= pipeline('''image-to-text''' ,  model='''hf-internal-testing/tiny-random-vit-gpt2'''					)
           SCREAMING_SNAKE_CASE__			:				Any       						= '''./tests/fixtures/tests_samples/COCO/000000039769.png'''
  
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= pipe(a__					)
           self.assertEqual(
               a__ ,  [
                   {
                       '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                   },
               ] ,  )
  
           SCREAMING_SNAKE_CASE__			:				Any       						= pipe([image, image]					)
           self.assertEqual(
               a__ ,  [
                   [
                       {
                           '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                       }
                   ],
                   [
                       {
                           '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                       }
                   ],
               ] ,  )
  
  
  
  
  
  
        @require_torch
        def    A__(self					)       ->   Any:
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= pipeline('''image-to-text''' ,  model='''hf-internal-testing/tiny-random-BlipForConditionalGeneration'''					)
           SCREAMING_SNAKE_CASE__			:				int       						= '''./tests/fixtures/tests_samples/COCO/000000039769.png'''
           SCREAMING_SNAKE_CASE__			:				Tuple       						= '''a photo of'''
  
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= pipe(a__ ,  prompt=a__					)
           self.assertTrue(outputs[0]['''generated_text'''].startswith(a__					)					)
  
  
  
  
  
  
        @slow
        @require_torch
        def    A__(self					)       ->   List[Any]:
           SCREAMING_SNAKE_CASE__			:				Tuple       						= pipeline('''image-to-text''' ,  model='''ydshieh/vit-gpt2-coco-en'''					)
           SCREAMING_SNAKE_CASE__			:				List[str]       						= '''./tests/fixtures/tests_samples/COCO/000000039769.png'''
  
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= pipe(a__					)
           self.assertEqual(a__ ,  [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}]					)
  
           SCREAMING_SNAKE_CASE__			:				Tuple       						= pipe([image, image]					)
           self.assertEqual(
               a__ ,  [
                   [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
                   [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
               ] ,  )
  
  
  
  
  
  
        @slow
        @require_torch
        def    A__(self					)       ->   Tuple:
           SCREAMING_SNAKE_CASE__			:				Dict       						= pipeline('''image-to-text''' ,  model='''Salesforce/blip-image-captioning-base'''					)
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= '''https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'''
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= Image.open(requests.get(a__ ,  stream=a__					).raw					)
  
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= pipe(a__					)
           self.assertEqual(a__ ,  [{'''generated_text''': '''a pink pokemon pokemon with a blue shirt and a blue shirt'''}]					)
  
  
  
  
  
  
        @slow
        @require_torch
        def    A__(self					)       ->   int:
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= pipeline('''image-to-text''' ,  model='''microsoft/git-base-coco'''					)
           SCREAMING_SNAKE_CASE__			:				str       						= '''https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'''
           SCREAMING_SNAKE_CASE__			:				List[str]       						= Image.open(requests.get(a__ ,  stream=a__					).raw					)
  
           SCREAMING_SNAKE_CASE__			:				str       						= pipe(a__					)
           self.assertEqual(a__ ,  [{'''generated_text''': '''a cartoon of a purple character.'''}]					)
  
  
  
  
  
  
        @slow
        @require_torch
        def    A__(self					)       ->   Dict:
           SCREAMING_SNAKE_CASE__			:				str       						= pipeline('''image-to-text''' ,  model='''Salesforce/blip-image-captioning-base'''					)
           SCREAMING_SNAKE_CASE__			:				List[Any]       						= '''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'''
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= Image.open(requests.get(a__ ,  stream=a__					).raw					)
  
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= '''a photography of'''
  
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= pipe(a__ ,  prompt=a__					)
           self.assertEqual(a__ ,  [{'''generated_text''': '''a photography of a volcano'''}]					)
  
           with self.assertRaises(a__					):
              SCREAMING_SNAKE_CASE__			:				Any       						= pipe([image, image] ,  prompt=[prompt, prompt]					)
  
  
  
  
  
  
        @slow
        @require_torch
        def    A__(self					)       ->   Dict:
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= pipeline('''image-to-text''' ,  model='''microsoft/git-base-coco'''					)
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= '''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'''
           SCREAMING_SNAKE_CASE__			:				Dict       						= Image.open(requests.get(a__ ,  stream=a__					).raw					)
  
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= '''a photo of a'''
  
           SCREAMING_SNAKE_CASE__			:				str       						= pipe(a__ ,  prompt=a__					)
           self.assertEqual(a__ ,  [{'''generated_text''': '''a photo of a tent with a tent and a tent in the background.'''}]					)
  
           with self.assertRaises(a__					):
              SCREAMING_SNAKE_CASE__			:				Dict       						= pipe([image, image] ,  prompt=[prompt, prompt]					)
  
  
  
  
  
  
        @unittest.skipIf(
            not is_torch_greater_or_equal_than_1_11 ,  reason='''`Pix2StructImageProcessor` requires `torch>=1.11.0`.'''					)
        @slow
        @require_torch
        def    A__(self					)       ->   Union[str, Any]:
           SCREAMING_SNAKE_CASE__			:				List[str]       						= pipeline('''image-to-text''' ,  model='''google/pix2struct-ai2d-base'''					)
           SCREAMING_SNAKE_CASE__			:				int       						= '''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'''
           SCREAMING_SNAKE_CASE__			:				Any       						= Image.open(requests.get(a__ ,  stream=a__					).raw					)
  
           SCREAMING_SNAKE_CASE__			:				int       						= '''What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud'''
  
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= pipe(a__ ,  prompt=a__					)
           self.assertEqual(a__ ,  [{'''generated_text''': '''ash cloud'''}]					)
  
           with self.assertRaises(a__					):
              SCREAMING_SNAKE_CASE__			:				Any       						= pipe([image, image] ,  prompt=[prompt, prompt]					)
  
  
  
  
  
  
        @slow
        @require_tf
        def    A__(self					)       ->   str:
           SCREAMING_SNAKE_CASE__			:				Optional[int]       						= pipeline('''image-to-text''' ,  model='''ydshieh/vit-gpt2-coco-en''' ,  framework='''tf'''					)
           SCREAMING_SNAKE_CASE__			:				Optional[Any]       						= '''./tests/fixtures/tests_samples/COCO/000000039769.png'''
  
           SCREAMING_SNAKE_CASE__			:				Dict       						= pipe(a__					)
           self.assertEqual(a__ ,  [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}]					)
  
           SCREAMING_SNAKE_CASE__			:				Union[str, Any]       						= pipe([image, image]					)
           self.assertEqual(
               a__ ,  [
                   [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
                   [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
               ] ,  )
  
  