





from __future__ import annotations

import unittest

from transformers import AutoTokenizer, GPTJConfig, is_tf_available
from transformers.testing_utils import require_tf, slow, tooslow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin
from ...utils.test_modeling_tf_core import TFCoreModelTesterMixin


if is_tf_available():
					import tensorflow as tf

					from transformers.models.gptj.modeling_tf_gptj import (
					    TFGPTJForCausalLM,
					    TFGPTJForQuestionAnswering,
					    TFGPTJForSequenceClassification,
					    TFGPTJModel,
					    shape_list,
					)
class 	UpperCamelCase_						:




					def __init__(						self ,  lowerCAmelCase_     )						->							Optional[Any]:
										_snake_case													= parent
										_snake_case													= 13
										_snake_case													= 7
										_snake_case													= True
										_snake_case													= True
										_snake_case													= True
										_snake_case													= True
										_snake_case													= True
										_snake_case													= 99
										_snake_case													= 32
										_snake_case													= 4
										_snake_case													= 2
										_snake_case													= 4
										_snake_case													= 37
										_snake_case													= 'gelu'
										_snake_case													= 0.1
										_snake_case													= 0.1
										_snake_case													= 512
										_snake_case													= 16
										_snake_case													= 2
										_snake_case													= 0.02
										_snake_case													= 3
										_snake_case													= 4
										_snake_case													= None
										_snake_case													= self.vocab_size - 1
										_snake_case													= self.vocab_size - 1
										_snake_case													= self.vocab_size - 1




					def 		lowerCAmelCase	(						self     )						->							int:
										_snake_case													= ids_tensor([self.batch_size, self.seq_length] ,  self.vocab_size     )

										_snake_case													= None
										if self.use_input_mask:
															_snake_case													= random_attention_mask([self.batch_size, self.seq_length]     )

										_snake_case													= None
										if self.use_token_type_ids:
															_snake_case													= ids_tensor([self.batch_size, self.seq_length] ,  self.type_vocab_size     )

										_snake_case													= None
										if self.use_mc_token_ids:
															_snake_case													= ids_tensor([self.batch_size, self.num_choices] ,  self.seq_length     )

										_snake_case													= None
										_snake_case													= None
										_snake_case													= None
										if self.use_labels:
															_snake_case													= ids_tensor([self.batch_size] ,  self.type_sequence_label_size     )
															_snake_case													= ids_tensor([self.batch_size, self.seq_length] ,  self.num_labels     )
															_snake_case													= ids_tensor([self.batch_size] ,  self.num_choices     )

										_snake_case													= GPTJConfig(
										    vocab_size=self.vocab_size ,  n_embd=self.hidden_size ,  n_layer=self.num_hidden_layers ,  n_head=self.num_attention_heads ,  intermediate_size=self.intermediate_size ,  hidden_act=self.hidden_act ,  hidden_dropout_prob=self.hidden_dropout_prob ,  attention_probs_dropout_prob=self.attention_probs_dropout_prob ,  n_positions=self.max_position_embeddings ,  type_vocab_size=self.type_vocab_size ,  initializer_range=self.initializer_range ,  bos_token_id=self.bos_token_id ,  eos_token_id=self.eos_token_id ,  pad_token_id=self.pad_token_id ,  rotary_dim=self.rotary_dim ,  return_dict=_lowerCamelCase ,  )

										_snake_case													= ids_tensor([self.num_hidden_layers, self.num_attention_heads] ,  2     )

										return (
										    config,
										    input_ids,
										    input_mask,
										    head_mask,
										    token_type_ids,
										    mc_token_ids,
										    sequence_labels,
										    token_labels,
										    choice_labels,
										)




					def 		lowerCAmelCase	(						self ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  *lowerCAmelCase_     )						->							Dict:
										_snake_case													= TFGPTJModel(config=_lowerCamelCase     )
										_snake_case													= {
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}
										_snake_case													= model(_lowerCamelCase     )

										_snake_case													= [input_ids, None, input_mask]  # None is the input for 'past'
										_snake_case													= model(_lowerCamelCase     )

										_snake_case													= model(_lowerCamelCase     )

										self.parent.assertEqual(result.last_hidden_state.shape ,  (self.batch_size, self.seq_length, self.hidden_size)     )




					def 		lowerCAmelCase	(						self ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  *lowerCAmelCase_     )						->							Any:
										_snake_case													= TFGPTJModel(config=_lowerCamelCase     )

										# first forward pass
										_snake_case													= model(_lowerCamelCase ,  token_type_ids=_lowerCamelCase ,  use_cache=_lowerCamelCase     )
										_snake_case													= model(_lowerCamelCase ,  token_type_ids=_lowerCamelCase     )
										_snake_case													= model(_lowerCamelCase ,  token_type_ids=_lowerCamelCase ,  use_cache=_lowerCamelCase     )

										self.parent.assertTrue(len(_lowerCamelCase     ) == len(_lowerCamelCase     )     )
										self.parent.assertTrue(len(_lowerCamelCase     ) == len(_lowerCamelCase     ) + 1     )

										_snake_case							,   _snake_case													= outputs.to_tuple()

										# create hypothetical next token and extent to next_input_ids
										_snake_case													= ids_tensor((self.batch_size, 1) ,  config.vocab_size     )
										_snake_case													= ids_tensor([self.batch_size, 1] ,  self.type_vocab_size     )

										# append to next input_ids and token_type_ids
										_snake_case													= tf.concat([input_ids, next_tokens] ,  axis=-1     )
										_snake_case													= tf.concat([token_type_ids, next_token_types] ,  axis=-1     )

										_snake_case													= model(_lowerCamelCase ,  token_type_ids=_lowerCamelCase     )['last_hidden_state']
										_snake_case													= model(_lowerCamelCase ,  token_type_ids=_lowerCamelCase ,  past_key_values=_lowerCamelCase     )[
										    'last_hidden_state'
										]

										# select random slice
										_snake_case													= int(ids_tensor((1,) ,  shape_list(_lowerCamelCase     )[-1]     )     )
										_snake_case													= output_from_no_past[:, -1, random_slice_idx]
										_snake_case													= output_from_past[:, 0, random_slice_idx]

										# test that outputs are equal for slice
										tf.debugging.assert_near(_lowerCamelCase ,  _lowerCamelCase ,  rtol=1E-6     )




					def 		lowerCAmelCase	(						self ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  *lowerCAmelCase_     )						->							Tuple:
										_snake_case													= TFGPTJModel(config=_lowerCamelCase     )

										# create attention mask
										_snake_case													= self.seq_length // 2
										_snake_case													= tf.ones((self.batch_size, half_seq_length) ,  dtype=tf.intaa     )
										_snake_case													= tf.zeros((self.batch_size, self.seq_length - half_seq_length) ,  dtype=tf.intaa     )
										_snake_case													= tf.concat([attn_mask_begin, attn_mask_end] ,  axis=1     )

										# first forward pass
										_snake_case							,   _snake_case													= model(_lowerCamelCase ,  attention_mask=_lowerCamelCase     ).to_tuple()

										# create hypothetical next token and extent to next_input_ids
										_snake_case													= ids_tensor((self.batch_size, 1) ,  config.vocab_size     )

										# change a random masked slice from input_ids
										_snake_case													= ids_tensor((1,) ,  _lowerCamelCase     ).numpy() + 1
										_snake_case													= ids_tensor((self.batch_size, self.seq_length) ,  config.vocab_size     )
										_snake_case													= tf.range(self.seq_length     ) == (self.seq_length - random_seq_idx_to_change)
										_snake_case													= tf.transpose(
										    tf.broadcast_to(tf.expand_dims(_lowerCamelCase ,  -1     ) ,  (self.seq_length, self.batch_size)     )     )
										_snake_case													= tf.where(_lowerCamelCase ,  _lowerCamelCase ,  _lowerCamelCase     )

										# append to next input_ids and attn_mask
										_snake_case													= tf.concat([input_ids, next_tokens] ,  axis=-1     )
										_snake_case													= tf.concat([attn_mask, tf.ones((shape_list(_lowerCamelCase     )[0], 1) ,  dtype=tf.intaa     )] ,  axis=1     )

										# get two different outputs
										_snake_case													= model(_lowerCamelCase ,  attention_mask=_lowerCamelCase     )['last_hidden_state']
										_snake_case													= model(_lowerCamelCase ,  past_key_values=_lowerCamelCase ,  attention_mask=_lowerCamelCase     )[
										    'last_hidden_state'
										]

										# select random slice
										_snake_case													= int(ids_tensor((1,) ,  shape_list(_lowerCamelCase     )[-1]     )     )
										_snake_case													= output_from_no_past[:, -1, random_slice_idx]
										_snake_case													= output_from_past[:, 0, random_slice_idx]

										# test that outputs are equal for slice
										tf.debugging.assert_near(_lowerCamelCase ,  _lowerCamelCase ,  rtol=1E-12     )




					def 		lowerCAmelCase	(						self ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  *lowerCAmelCase_     )						->							List[str]:
										_snake_case													= TFGPTJModel(config=_lowerCamelCase     )

										_snake_case													= input_ids[:1, :]
										_snake_case													= input_mask[:1, :]
										_snake_case													= token_type_ids[:1, :]
										_snake_case													= 1

										# first forward pass
										_snake_case													= model(_lowerCamelCase ,  attention_mask=_lowerCamelCase ,  token_type_ids=_lowerCamelCase ,  use_cache=_lowerCamelCase     )

										_snake_case							,   _snake_case													= outputs.to_tuple()

										# create hypothetical next token and extent to next_input_ids
										_snake_case													= ids_tensor((self.batch_size, 3) ,  config.vocab_size     )
										_snake_case													= ids_tensor((self.batch_size, 3) ,  2     )
										_snake_case													= ids_tensor((self.batch_size, 3) ,  self.type_vocab_size     )

										# append to next input_ids and token_type_ids
										_snake_case													= tf.concat([input_ids, next_tokens] ,  axis=-1     )
										_snake_case													= tf.concat([input_mask, next_attn_mask] ,  axis=-1     )
										_snake_case													= tf.concat([token_type_ids, next_token_types] ,  axis=-1     )

										_snake_case													= model(
										    _lowerCamelCase ,  token_type_ids=_lowerCamelCase ,  attention_mask=_lowerCamelCase     )['last_hidden_state']
										_snake_case													= model(
										    _lowerCamelCase ,  token_type_ids=_lowerCamelCase ,  attention_mask=_lowerCamelCase ,  past_key_values=_lowerCamelCase ,  )['last_hidden_state']
										self.parent.assertTrue(output_from_past.shape[1] == next_tokens.shape[1]     )

										# select random slice
										_snake_case													= int(ids_tensor((1,) ,  shape_list(_lowerCamelCase     )[-1]     )     )
										_snake_case													= output_from_no_past[:, -3:, random_slice_idx]
										_snake_case													= output_from_past[:, :, random_slice_idx]

										# test that outputs are equal for slice
										tf.debugging.assert_near(_lowerCamelCase ,  _lowerCamelCase ,  rtol=1E-3     )




					def 		lowerCAmelCase	(						self ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  *lowerCAmelCase_     )						->							Optional[int]:
										_snake_case													= TFGPTJForCausalLM(config=_lowerCamelCase     )
										_snake_case													= {
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}
										_snake_case													= model(_lowerCamelCase     )
										self.parent.assertEqual(result.logits.shape ,  (self.batch_size, self.seq_length, self.vocab_size)     )






					def 		lowerCAmelCase	(						self     )						->							Optional[int]:
										_snake_case													= self.prepare_config_and_inputs()

										(
										    (
										    _snake_case      
										)							,   (
										    _snake_case      
										)							,   (
										    _snake_case      
										)							,   (
										    _snake_case      
										)							,   (
										    _snake_case      
										)							,   (
										    _snake_case      
										)							,   (
										    _snake_case      
										)							,   (
										    _snake_case      
										)							,   (
										    _snake_case      
										)							,         
										)													= config_and_inputs

										_snake_case													= {
										    'input_ids': input_ids,
										    'token_type_ids': token_type_ids,
										    'attention_mask': input_mask,
										}
										return config, inputs_dict





@require_tf
class 	UpperCamelCase_						(     __lowerCAmelCase							,     __lowerCAmelCase							,     __lowerCAmelCase							,     unittest.TestCase    ):
					lowerCAmelCase_							=		(
					    (TFGPTJForCausalLM, TFGPTJForSequenceClassification, TFGPTJForQuestionAnswering, TFGPTJModel)
					    if is_tf_available()
					    else ()
					)

					lowerCAmelCase_							=		(TFGPTJForCausalLM,) if is_tf_available() else ()
					lowerCAmelCase_							=		(
					    {
					        '''feature-extraction''': TFGPTJModel,
					        '''question-answering''': TFGPTJForQuestionAnswering,
					        '''text-classification''': TFGPTJForSequenceClassification,
					        '''text-generation''': TFGPTJForCausalLM,
					        '''zero-shot''': TFGPTJForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					lowerCAmelCase_							=		False
					lowerCAmelCase_							=		False
					lowerCAmelCase_							=		False
					lowerCAmelCase_							=		False




					def 		lowerCAmelCase	(						self ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_ ,  lowerCAmelCase_     )						->							str:
										if (
										    pipeline_test_casse_name == "QAPipelineTests"
										    and tokenizer_name is not None
										    and not tokenizer_name.endswith('Fast'     )
										):
															# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
															# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
															# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
															return True

										return False




					def 		lowerCAmelCase	(						self     )						->							str:
										_snake_case													= TFGPTJModelTester(self     )
										_snake_case													= ConfigTester(self ,  config_class=_lowerCamelCase ,  n_embd=37     )




					def 		lowerCAmelCase	(						self     )						->							Tuple:
										self.config_tester.run_common_tests()




					def 		lowerCAmelCase	(						self     )						->							Optional[int]:
										_snake_case													= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_gptj_model(*_lowerCamelCase     )




					def 		lowerCAmelCase	(						self     )						->							Any:
										_snake_case													= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_gptj_model_past(*_lowerCamelCase     )




					def 		lowerCAmelCase	(						self     )						->							Optional[Any]:
										_snake_case													= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_gptj_model_attention_mask_past(*_lowerCamelCase     )




					def 		lowerCAmelCase	(						self     )						->							Dict:
										_snake_case													= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_gptj_model_past_large_inputs(*_lowerCamelCase     )




					def 		lowerCAmelCase	(						self     )						->							Optional[int]:
										_snake_case													= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_gptj_lm_head_model(*_lowerCamelCase     )




					@slow
					@unittest.skipIf(
					    not is_tf_available() or len(tf.config.list_physical_devices('GPU'     )     ) > 0 ,  'skip testing on GPU for now to avoid GPU OOM.' ,  )
					def 		lowerCAmelCase	(						self     )						->							Optional[int]:
										_snake_case													= TFGPTJModel.from_pretrained('EleutherAI/gpt-j-6B' ,  from_pt=_lowerCamelCase     )
										self.assertIsNotNone(_lowerCamelCase     )






					@unittest.skip(reason='Currently, model embeddings are going to undergo a major refactor.'     )
					def 		lowerCAmelCase	(						self     )						->							int:
										super().test_resize_token_embeddings()





@require_tf
@tooslow
# Marked as @tooslow due to GPU OOM -- but still useful to run locally. Requires ~39GB of RAM.
class 	UpperCamelCase_						(     unittest.TestCase    ):




					def 		lowerCAmelCase	(						self     )						->							Optional[int]:
										_snake_case													= TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B' ,  from_pt=_lowerCamelCase     )
										_snake_case													= tf.convert_to_tensor([[464, 3290]] ,  dtype=tf.intaa     )  # The dog
										# fmt: off
										# The dog is a man's best friend. It is a loyal companion, and it is a friend
										_snake_case													= [464, 3290, 318, 257, 582, 338, 1266, 1545, 13, 632, 318, 257, 9112, 1_5185, 11, 290, 340, 318, 257, 1545]
										# fmt: on
										_snake_case													= model.generate(_lowerCamelCase ,  do_sample=_lowerCamelCase     )
										self.assertListEqual(output_ids[0].numpy().tolist() ,  _lowerCamelCase     )




					def 		lowerCAmelCase	(						self     )						->							Optional[int]:
										_snake_case													= AutoTokenizer.from_pretrained('EleutherAI/gpt-j-6B' ,  revision='float16'     )
										_snake_case													= TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B' ,  revision='float16' ,  from_pt=_lowerCamelCase     )

										_snake_case													= tokenizer('Today is a nice day and' ,  return_tensors='tf'     )
										# forces the generation to happen on CPU, to avoid GPU-related quirks
										with tf.device(':/CPU:0'     ):
															_snake_case													= model.generate(**_lowerCamelCase ,  do_sample=_lowerCamelCase ,  seed=[42, 0]     )
										_snake_case													= tokenizer.decode(output_ids[0] ,  skip_special_tokens=_lowerCamelCase     )

										_snake_case													= 'Today is a nice day and I’m going to go for a walk. I’'
										self.assertEqual(_lowerCamelCase ,  _lowerCamelCase     )




					def 		lowerCAmelCase	(						self     )						->							Tuple:
										_snake_case													= TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B' ,  revision='float16' ,  from_pt=_lowerCamelCase     )
										_snake_case													= AutoTokenizer.from_pretrained('EleutherAI/gpt-j-6B' ,  revision='float16'     )

										_snake_case													= 'left'

										# Define PAD Token = EOS Token = 50256
										_snake_case													= tokenizer.eos_token
										_snake_case													= model.config.eos_token_id

										# use different length sentences to test batching
										_snake_case													= [
										    'Hello, my dog is a little',
										    'Today, I',
										]
										_snake_case													= [
										    'Hello, my dog is a little over a year old and has been diagnosed with hip dysplasia',
										    'Today, I’m going to be talking about a topic that’',
										]
										return model, tokenizer, sentences, expected_output_sentences




					def 		lowerCAmelCase	(						self     )						->							Dict:
										# Confirms that we get the expected results with left-padded beam search
										_snake_case							,   _snake_case							,   _snake_case							,   _snake_case													= self._get_beam_search_test_objects()

										_snake_case													= tokenizer(_lowerCamelCase ,  return_tensors='tf' ,  padding=_lowerCamelCase     )
										_snake_case													= model.generate(**_lowerCamelCase ,  do_sample=_lowerCamelCase ,  num_beams=2     )
										_snake_case													= tokenizer.batch_decode(_lowerCamelCase ,  skip_special_tokens=_lowerCamelCase     )
										self.assertListEqual(_lowerCamelCase ,  _lowerCamelCase     )




					def 		lowerCAmelCase	(						self     )						->							Union[str, Any]:
										# Confirms that left-padding is working properly
										_snake_case							,   _snake_case							,   _snake_case							,   _snake_case													= self._get_beam_search_test_objects()

										_snake_case													= tokenizer(_lowerCamelCase ,  return_tensors='tf' ,  padding=_lowerCamelCase     )
										_snake_case													= tokenizer(sentences[0] ,  return_tensors='tf'     )
										_snake_case													= model.generate(**_lowerCamelCase ,  do_sample=_lowerCamelCase ,  num_beams=2     )
										_snake_case													= (
										    shape_list(inputs_non_padded['input_ids']     )[-1]
										    - tf.reduce_sum(tf.cast(inputs['attention_mask'][-1] ,  tf.intaa     )     ).numpy()
										)
										_snake_case													= tokenizer(sentences[1] ,  return_tensors='tf'     )
										_snake_case													= model.generate(
										    **_lowerCamelCase ,  do_sample=_lowerCamelCase ,  num_beams=2 ,  max_length=model.config.max_length - num_paddings     )
										_snake_case													= tokenizer.decode(output_non_padded[0] ,  skip_special_tokens=_lowerCamelCase     )
										_snake_case													= tokenizer.decode(output_padded[0] ,  skip_special_tokens=_lowerCamelCase     )
										self.assertListEqual(_lowerCamelCase ,  [non_padded_sentence, padded_sentence]     )






					def 		lowerCAmelCase	(						self     )						->							Dict:
										# Confirms that XLA is working properly
										_snake_case							,   _snake_case							,   _snake_case							,   _snake_case													= self._get_beam_search_test_objects()

										_snake_case													= tokenizer(_lowerCamelCase ,  return_tensors='tf' ,  padding=_lowerCamelCase     )
										_snake_case													= tf.function(model.generate ,  jit_compile=_lowerCamelCase     )
										_snake_case													= xla_generate(**_lowerCamelCase ,  do_sample=_lowerCamelCase ,  num_beams=2     )
										_snake_case													= tokenizer.batch_decode(_lowerCamelCase ,  skip_special_tokens=_lowerCamelCase     )
										self.assertListEqual(_lowerCamelCase ,  _lowerCamelCase     )




"""simple docstring"""


import unittest

import pytest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    MBartaaTokenizerFast,
    MBartConfig,
    MBartForConditionalGeneration,
    TranslationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch, slow

from .test_pipelines_common import ANY






@is_pipeline_test
class    __UpperCAmelCase						(	unittest.TestCase	):
				A__      :   Optional[Any]  							=       MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
				A__      :   int  							=       TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

				def 		_a	(      self	, _lowerCamelCase	, _lowerCamelCase	, _lowerCamelCase      ):
										if isinstance(model.config	, _lowerCamelCase      ):
																lowerCamelCase__					,      lowerCamelCase__					=list(tokenizer.lang_code_to_id.keys()      )[:2]
																lowerCamelCase__					=TranslationPipeline(model=_lowerCamelCase	, tokenizer=_lowerCamelCase	, src_lang=_lowerCamelCase	, tgt_lang=_lowerCamelCase      )
										else:
																lowerCamelCase__					=TranslationPipeline(model=_lowerCamelCase	, tokenizer=_lowerCamelCase      )
										return translator, ["Some string", "Some other text"]

				def 		_a	(      self	, _lowerCamelCase	, _lowerCamelCase      ):
										lowerCamelCase__					=translator("Some string"      )
										self.assertEqual(_lowerCamelCase	, [{"translation_text": ANY(_lowerCamelCase      )}]      )

										lowerCamelCase__					=translator(["Some string"]      )
										self.assertEqual(_lowerCamelCase	, [{"translation_text": ANY(_lowerCamelCase      )}]      )

										lowerCamelCase__					=translator(["Some string", "other string"]      )
										self.assertEqual(_lowerCamelCase	, [{"translation_text": ANY(_lowerCamelCase      )}, {"translation_text": ANY(_lowerCamelCase      )}]      )

				@require_torch
				def 		_a	(      self      ):
										lowerCamelCase__					=pipeline("translation_en_to_ro"	, model="patrickvonplaten/t5-tiny-random"	, framework="pt"      )
										lowerCamelCase__					=translator("This is a test string"	, max_length=20      )
										self.assertEqual(
										    _lowerCamelCase	, [
										        {
										            "translation_text": (
										                "Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide"
										                " Beide Beide"
										            )
										        }
										    ]	, )

				@require_tf
				def 		_a	(      self      ):
										lowerCamelCase__					=pipeline("translation_en_to_ro"	, model="patrickvonplaten/t5-tiny-random"	, framework="tf"      )
										lowerCamelCase__					=translator("This is a test string"	, max_length=20      )
										self.assertEqual(
										    _lowerCamelCase	, [
										        {
										            "translation_text": (
										                "Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide"
										                " Beide Beide"
										            )
										        }
										    ]	, )

				@require_torch
				def 		_a	(      self      ):
										lowerCamelCase__					=pipeline("translation_en_to_de"	, model="patrickvonplaten/t5-tiny-random"	, framework="pt"      )
										lowerCamelCase__					=translator("This is a test string"	, max_length=20      )
										self.assertEqual(
										    _lowerCamelCase	, [
										        {
										            "translation_text": (
										                "monoton monoton monoton monoton monoton monoton monoton monoton monoton monoton urine urine"
										                " urine urine urine urine urine urine urine"
										            )
										        }
										    ]	, )






				@require_tf
				def 		_a	(      self      ):
										lowerCamelCase__					=pipeline("translation_en_to_de"	, model="patrickvonplaten/t5-tiny-random"	, framework="tf"      )
										lowerCamelCase__					=translator("This is a test string"	, max_length=20      )
										self.assertEqual(
										    _lowerCamelCase	, [
										        {
										            "translation_text": (
										                "monoton monoton monoton monoton monoton monoton monoton monoton monoton monoton urine urine"
										                " urine urine urine urine urine urine urine"
										            )
										        }
										    ]	, )






class    __UpperCAmelCase						(	unittest.TestCase	):

				@require_torch
				@slow
				def 		_a	(      self      ):
										# We don't provide a default for this pair
										with self.assertRaises(_lowerCamelCase      ):
																pipeline(task="translation_cn_to_ar"      )

										# but we do for this one
										lowerCamelCase__					=pipeline(task="translation_en_to_de"      )
										self.assertEqual(translator._preprocess_params["src_lang"]	, "en"      )
										self.assertEqual(translator._preprocess_params["tgt_lang"]	, "de"      )

				@require_torch
				@slow
				def 		_a	(      self      ):
										lowerCamelCase__					=MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-many-to-many-mmt"      )
										lowerCamelCase__					=MBartaaTokenizerFast.from_pretrained("facebook/mbart-large-50-many-to-many-mmt"      )

										lowerCamelCase__					=pipeline(task="translation"	, model=_lowerCamelCase	, tokenizer=_lowerCamelCase      )
										# Missing src_lang, tgt_lang
										with self.assertRaises(_lowerCamelCase      ):
																translator("This is a test"      )

										lowerCamelCase__					=translator("This is a test"	, src_lang="en_XX"	, tgt_lang="ar_AR"      )
										self.assertEqual(_lowerCamelCase	, [{"translation_text": "هذا إختبار"}]      )

										lowerCamelCase__					=translator("This is a test"	, src_lang="en_XX"	, tgt_lang="hi_IN"      )
										self.assertEqual(_lowerCamelCase	, [{"translation_text": "यह एक परीक्षण है"}]      )

										# src_lang, tgt_lang can be defined at pipeline call time
										lowerCamelCase__					=pipeline(task="translation"	, model=_lowerCamelCase	, tokenizer=_lowerCamelCase	, src_lang="en_XX"	, tgt_lang="ar_AR"      )
										lowerCamelCase__					=translator("This is a test"      )
										self.assertEqual(_lowerCamelCase	, [{"translation_text": "هذا إختبار"}]      )

				@require_torch
				def 		_a	(      self      ):
										lowerCamelCase__					="patrickvonplaten/t5-tiny-random"
										lowerCamelCase__					=pipeline(task="translation_cn_to_ar"	, model=_lowerCamelCase      )
										self.assertEqual(translator._preprocess_params["src_lang"]	, "cn"      )
										self.assertEqual(translator._preprocess_params["tgt_lang"]	, "ar"      )

				@require_torch
				def 		_a	(      self      ):
										lowerCamelCase__					="patrickvonplaten/t5-tiny-random"
										with pytest.warns(_lowerCamelCase	, match=r".*translation_en_to_de.*"      ):
																lowerCamelCase__					=pipeline(task="translation"	, model=_lowerCamelCase      )
										self.assertEqual(translator.task	, "translation_en_to_de"      )
										self.assertEqual(translator._preprocess_params["src_lang"]	, "en"      )
										self.assertEqual(translator._preprocess_params["tgt_lang"]	, "de"      )






				@require_torch
				def 		_a	(      self      ):
										with self.assertRaises(_lowerCamelCase      ):
																pipeline(task="translation"      )


