import unittest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TextaTextGenerationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch
from transformers.utils import is_torch_available

from .test_pipelines_common import ANY


if is_torch_available():
     import torch



@is_pipeline_test
class  UpperCamelCase				( unittest.TestCase ):

     '''simple docstring'''

     A_										=  MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
     A_										=  TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING



     def 		UpperCamelCase_						(					self				,				A_				,				A_				,				A_						) ->				int:






           """simple docstring"""
           _lowerCamelCase			    =				TextaTextGenerationPipeline(model=A_				,				tokenizer=A_						)
           return generator, ["Something to write", "Something else"]



     def 		UpperCamelCase_						(					self				,				A_				,				A_						) ->				List[str]:






           """simple docstring"""
           _lowerCamelCase			    =				generator('''Something there'''						)
           self.assertEqual(A_				,				[{'''generated_text''': ANY(A_						)}]						)
           # These are encoder decoder, they don't just append to incoming string
           self.assertFalse(outputs[0]['''generated_text'''].startswith('''Something there'''						)						)

           _lowerCamelCase			    =				generator(['''This is great !''', '''Something else''']				,				num_return_sequences=2				,				do_sample=A_						)
           self.assertEqual(
               A_				,				[
                   [{'''generated_text''': ANY(A_						)}, {'''generated_text''': ANY(A_						)}],
                   [{'''generated_text''': ANY(A_						)}, {'''generated_text''': ANY(A_						)}],
               ]				,				)

           _lowerCamelCase			    =				generator(
               ['''This is great !''', '''Something else''']				,				num_return_sequences=2				,				batch_size=2				,				do_sample=A_						)
           self.assertEqual(
               A_				,				[
                   [{'''generated_text''': ANY(A_						)}, {'''generated_text''': ANY(A_						)}],
                   [{'''generated_text''': ANY(A_						)}, {'''generated_text''': ANY(A_						)}],
               ]				,				)

           with self.assertRaises(A_						):
                 generator(4						)



     @require_torch
     def 		UpperCamelCase_						(					self						) ->				int:






           """simple docstring"""
           _lowerCamelCase			    =				pipeline('''text2text-generation'''				,				model='''patrickvonplaten/t5-tiny-random'''				,				framework='''pt'''						)
           # do_sample=False necessary for reproducibility
           _lowerCamelCase			    =				generator('''Something there'''				,				do_sample=A_						)
           self.assertEqual(A_				,				[{'''generated_text''': ''''''}]						)

           _lowerCamelCase			    =				3
           _lowerCamelCase			    =				generator(
               '''Something there'''				,				num_return_sequences=A_				,				num_beams=A_				,				)
           _lowerCamelCase			    =				[
               {'''generated_text''': '''Beide Beide Beide Beide Beide Beide Beide Beide Beide'''},
               {'''generated_text''': '''Beide Beide Beide Beide Beide Beide Beide Beide'''},
               {'''generated_text''': ''''''},
           ]
           self.assertEqual(A_				,				A_						)

           _lowerCamelCase			    =				generator('''This is a test'''				,				do_sample=A_				,				num_return_sequences=2				,				return_tensors=A_						)
           self.assertEqual(
               A_				,				[
                   {'''generated_token_ids''': ANY(torch.Tensor						)},
                   {'''generated_token_ids''': ANY(torch.Tensor						)},
               ]				,				)
           _lowerCamelCase			    =				generator.model.config.eos_token_id
           _lowerCamelCase			    =				'''<pad>'''
           _lowerCamelCase			    =				generator(
               ['''This is a test''', '''This is a second test''']				,				do_sample=A_				,				num_return_sequences=2				,				batch_size=2				,				return_tensors=A_				,				)
           self.assertEqual(
               A_				,				[
                   [
                       {'''generated_token_ids''': ANY(torch.Tensor						)},
                       {'''generated_token_ids''': ANY(torch.Tensor						)},
                   ],
                   [
                       {'''generated_token_ids''': ANY(torch.Tensor						)},
                       {'''generated_token_ids''': ANY(torch.Tensor						)},
                   ],
               ]				,				)





     @require_tf
     def 		UpperCamelCase_						(					self						) ->				Union[str, Any]:






           """simple docstring"""
           _lowerCamelCase			    =				pipeline('''text2text-generation'''				,				model='''patrickvonplaten/t5-tiny-random'''				,				framework='''tf'''						)
           # do_sample=False necessary for reproducibility
           _lowerCamelCase			    =				generator('''Something there'''				,				do_sample=A_						)
           self.assertEqual(A_				,				[{'''generated_text''': ''''''}]						)
import os
import tempfile
import unittest

from transformers.models.marian.convert_marian_tatoeba_to_pytorch import DEFAULT_REPO, TatoebaConverter
from transformers.testing_utils import slow
from transformers.utils import cached_property



@unittest.skipUnless(os.path.exists(__lowercase )   ,  'Tatoeba directory does not exist.' )
class  UpperCamelCase				( unittest.TestCase ):

     '''simple docstring'''

     @cached_property
     def 		UpperCamelCase_						(					self						) ->				int:






           """simple docstring"""
           _lowerCamelCase			    =				tempfile.mkdtemp()
           return TatoebaConverter(save_dir=A_						)



     @slow
     def 		UpperCamelCase_						(					self						) ->				Any:






           """simple docstring"""
           self.resolver.convert_models(['''heb-eng''']						)





     @slow
     def 		UpperCamelCase_						(					self						) ->				Tuple:






           """simple docstring"""
           _lowerCamelCase    ,					_lowerCamelCase			    =				self.resolver.write_model_card('''opus-mt-he-en'''				,				dry_run=A_						)
           assert mmeta["long_pair"] == "heb-eng"