

"""simple docstring"""






import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


__lowerCamelCase										=		logging.getLogger()
@unittest.skip('''Temporarily disable the doc tests.'''     )
@require_torch
@require_tf
@slow
class        _lowercase					(     unittest.TestCase     ):







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_ = None ,						UpperCamelCase_ = None ,						UpperCamelCase_ = None ,						UpperCamelCase_ = True ,						):
      __magic_name__     =      [file for file in os.listdir(lowerCamelCase_       ) if os.path.isfile(os.path.join(lowerCamelCase_ ,						lowerCamelCase_       )       )]

      if identifier is not None:
       __magic_name__     =      [file for file in files if identifier in file]

      if n_identifier is not None:
       if isinstance(lowerCamelCase_ ,						lowerCamelCase_       ):
        for n_ in n_identifier:
         __magic_name__     =      [file for file in files if n_ not in file]
       else:
        __magic_name__     =      [file for file in files if n_identifier not in file]

      __magic_name__     =      ignore_files or []
      ignore_files.append('''__init__.py'''       )
      __magic_name__     =      [file for file in files if file not in ignore_files]

      for file in files:
       # Open all files
       print('''Testing''' ,						lowerCamelCase_       )

       if only_modules:
        __magic_name__     =      file.split('''.'''       )[0]
        try:
         __magic_name__     =      getattr(lowerCamelCase_ ,						lowerCamelCase_       )
         __magic_name__     =      doctest.DocTestSuite(lowerCamelCase_       )
         __magic_name__     =      unittest.TextTestRunner().run(lowerCamelCase_       )
         self.assertIs(len(result.failures       ) ,						0       )
        except AttributeError:
         logger.info(f'''{module_identifier} is not a module.'''       )
       else:
        __magic_name__     =      doctest.testfile(str('''..''' / directory / file       ) ,						optionflags=doctest.ELLIPSIS       )
        self.assertIs(result.failed ,						0       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      Path('''src/transformers'''       )
      __magic_name__     =      '''modeling'''
      __magic_name__     =      [
          '''modeling_ctrl.py''',
          '''modeling_tf_ctrl.py''',
      ]
      self.analyze_directory(lowerCamelCase_ ,						identifier=lowerCamelCase_ ,						ignore_files=lowerCamelCase_       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      Path('''src/transformers'''       )
      __magic_name__     =      '''tokenization'''
      self.analyze_directory(lowerCamelCase_ ,						identifier=lowerCamelCase_       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      Path('''src/transformers'''       )
      __magic_name__     =      '''configuration'''
      self.analyze_directory(lowerCamelCase_ ,						identifier=lowerCamelCase_       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      Path('''src/transformers'''       )
      __magic_name__     =      ['''configuration''', '''modeling''', '''tokenization''']
      self.analyze_directory(lowerCamelCase_ ,						n_identifier=lowerCamelCase_       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      Path('''docs/source'''       )
      __magic_name__     =      ['''favicon.ico''']
      self.analyze_directory(lowerCamelCase_ ,						ignore_files=lowerCamelCase_ ,						only_modules=lowerCamelCase_       )




"""simple docstring"""






import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
 from transformers import AutoModelForSeqaSeqLM, AutoTokenizer
@require_torch
@require_sentencepiece
@require_tokenizers
class        _lowercase					(     unittest.TestCase     ):







     @slow
     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      AutoModelForSeqaSeqLM.from_pretrained('''google/mt5-small''' ,						return_dict=UpperCamelCase_       ).to(UpperCamelCase_       )
      __magic_name__     =      AutoTokenizer.from_pretrained('''google/mt5-small'''       )

      __magic_name__     =      tokenizer('''Hello there''' ,						return_tensors='''pt'''       ).input_ids
      __magic_name__     =      tokenizer('''Hi I am''' ,						return_tensors='''pt'''       ).input_ids

      __magic_name__     =      model(input_ids.to(UpperCamelCase_       ) ,						labels=labels.to(UpperCamelCase_       )       ).loss
      __magic_name__     =      -(labels.shape[-1] * loss.item())

      __magic_name__     =      -8_4.9_1_2_7
      self.assertTrue(abs(mtf_score - EXPECTED_SCORE       ) < 1E-4       )

