"""simple docstring"""






import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
       import tensorflow as tf

       from transformers import TensorFlowBenchmark, TensorFlowBenchmarkArguments





@require_tf
class 				_A		( unittest.TestCase			):

      def        A__ (		self	, __lowerCAmelCase		):







            """simple docstring"""



            for model_result in results.values():
                  for batch_size, sequence_length in zip(model_result["""bs"""]	, model_result["""ss"""]		):
                        lowercase														=			model_result["""result"""][batch_size][sequence_length]
                        self.assertIsNotNone(__lowerCAmelCase		)

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""
            lowercase														=			TensorFlowBenchmarkArguments(
                models=[MODEL_ID]	, training=__lowerCAmelCase	, inference=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, eager_mode=__lowerCAmelCase	, multi_process=__lowerCAmelCase	, )
            lowercase														=			TensorFlowBenchmark(__lowerCAmelCase		)
            lowercase														=			benchmark.run()
            self.check_results_dict_not_empty(results.time_inference_result		)
            self.check_results_dict_not_empty(results.memory_inference_result		)

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sgugger/tiny-distilbert-classification"""
            lowercase														=			TensorFlowBenchmarkArguments(
                models=[MODEL_ID]	, training=__lowerCAmelCase	, inference=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, multi_process=__lowerCAmelCase	, only_pretrain_model=__lowerCAmelCase	, )
            lowercase														=			TensorFlowBenchmark(__lowerCAmelCase		)
            lowercase														=			benchmark.run()
            self.check_results_dict_not_empty(results.time_inference_result		)
            self.check_results_dict_not_empty(results.memory_inference_result		)

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""
            lowercase														=			TensorFlowBenchmarkArguments(
                models=[MODEL_ID]	, training=__lowerCAmelCase	, inference=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, multi_process=__lowerCAmelCase	, )
            lowercase														=			TensorFlowBenchmark(__lowerCAmelCase		)
            lowercase														=			benchmark.run()
            self.check_results_dict_not_empty(results.time_inference_result		)
            self.check_results_dict_not_empty(results.memory_inference_result		)

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""
            lowercase														=			AutoConfig.from_pretrained(__lowerCAmelCase		)
            lowercase														=			TensorFlowBenchmarkArguments(
                models=[MODEL_ID]	, training=__lowerCAmelCase	, inference=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, eager_mode=__lowerCAmelCase	, multi_process=__lowerCAmelCase	, )
            lowercase														=			TensorFlowBenchmark(__lowerCAmelCase	, [config]		)
            lowercase														=			benchmark.run()
            self.check_results_dict_not_empty(results.time_inference_result		)
            self.check_results_dict_not_empty(results.memory_inference_result		)

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""
            lowercase														=			AutoConfig.from_pretrained(__lowerCAmelCase		)
            lowercase														=			TensorFlowBenchmarkArguments(
                models=[MODEL_ID]	, training=__lowerCAmelCase	, inference=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, multi_process=__lowerCAmelCase	, )
            lowercase														=			TensorFlowBenchmark(__lowerCAmelCase	, [config]		)
            lowercase														=			benchmark.run()
            self.check_results_dict_not_empty(results.time_inference_result		)
            self.check_results_dict_not_empty(results.memory_inference_result		)

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""
            lowercase														=			TensorFlowBenchmarkArguments(
                models=[MODEL_ID]	, training=__lowerCAmelCase	, inference=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, multi_process=__lowerCAmelCase	, )
            lowercase														=			TensorFlowBenchmark(__lowerCAmelCase		)
            lowercase														=			benchmark.run()
            self.check_results_dict_not_empty(results.time_train_result		)
            self.check_results_dict_not_empty(results.memory_train_result		)

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""
            lowercase														=			AutoConfig.from_pretrained(__lowerCAmelCase		)
            lowercase														=			TensorFlowBenchmarkArguments(
                models=[MODEL_ID]	, training=__lowerCAmelCase	, inference=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, multi_process=__lowerCAmelCase	, )
            lowercase														=			TensorFlowBenchmark(__lowerCAmelCase	, [config]		)
            lowercase														=			benchmark.run()
            self.check_results_dict_not_empty(results.time_train_result		)
            self.check_results_dict_not_empty(results.memory_train_result		)

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""patrickvonplaten/t5-tiny-random"""
            lowercase														=			AutoConfig.from_pretrained(__lowerCAmelCase		)
            lowercase														=			TensorFlowBenchmarkArguments(
                models=[MODEL_ID]	, training=__lowerCAmelCase	, inference=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, multi_process=__lowerCAmelCase	, )
            lowercase														=			TensorFlowBenchmark(__lowerCAmelCase	, configs=[config]		)
            lowercase														=			benchmark.run()
            self.check_results_dict_not_empty(results.time_inference_result		)
            self.check_results_dict_not_empty(results.memory_inference_result		)

      @unittest.skipIf(is_tf_available() and len(tf.config.list_physical_devices("""GPU"""		)		) == 0	, """Cannot do xla on CPU."""		)
      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""
            lowercase														=			TensorFlowBenchmarkArguments(
                models=[MODEL_ID]	, training=__lowerCAmelCase	, inference=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, use_xla=__lowerCAmelCase	, multi_process=__lowerCAmelCase	, )
            lowercase														=			TensorFlowBenchmark(__lowerCAmelCase		)
            lowercase														=			benchmark.run()
            self.check_results_dict_not_empty(results.time_inference_result		)
            self.check_results_dict_not_empty(results.memory_inference_result		)

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""
            with tempfile.TemporaryDirectory() as tmp_dir:
                  lowercase														=			TensorFlowBenchmarkArguments(
                      models=[MODEL_ID]	, inference=__lowerCAmelCase	, save_to_csv=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, inference_time_csv_file=os.path.join(__lowerCAmelCase	, """inf_time.csv"""		)	, inference_memory_csv_file=os.path.join(__lowerCAmelCase	, """inf_mem.csv"""		)	, env_info_csv_file=os.path.join(__lowerCAmelCase	, """env.csv"""		)	, multi_process=__lowerCAmelCase	, )
                  lowercase														=			TensorFlowBenchmark(__lowerCAmelCase		)
                  benchmark.run()
                  self.assertTrue(Path(os.path.join(__lowerCAmelCase	, """inf_time.csv"""		)		).exists()		)
                  self.assertTrue(Path(os.path.join(__lowerCAmelCase	, """inf_mem.csv"""		)		).exists()		)
                  self.assertTrue(Path(os.path.join(__lowerCAmelCase	, """env.csv"""		)		).exists()		)







      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""

            def _check_summary_is_not_empty(__lowerCAmelCase		):
                  self.assertTrue(hasattr(__lowerCAmelCase	, """sequential"""		)		)
                  self.assertTrue(hasattr(__lowerCAmelCase	, """cumulative"""		)		)
                  self.assertTrue(hasattr(__lowerCAmelCase	, """current"""		)		)
                  self.assertTrue(hasattr(__lowerCAmelCase	, """total"""		)		)

            with tempfile.TemporaryDirectory() as tmp_dir:
                  lowercase														=			TensorFlowBenchmarkArguments(
                      models=[MODEL_ID]	, inference=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, log_filename=os.path.join(__lowerCAmelCase	, """log.txt"""		)	, log_print=__lowerCAmelCase	, trace_memory_line_by_line=__lowerCAmelCase	, eager_mode=__lowerCAmelCase	, multi_process=__lowerCAmelCase	, )
                  lowercase														=			TensorFlowBenchmark(__lowerCAmelCase		)
                  lowercase														=			benchmark.run()
                  _check_summary_is_not_empty(result.inference_summary		)
                  self.assertTrue(Path(os.path.join(__lowerCAmelCase	, """log.txt"""		)		).exists()		)




"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


__lowerCAmelCase					: Dict        ={
    """configuration_xlm""": ["""XLM_PRETRAINED_CONFIG_ARCHIVE_MAP""", """XLMConfig""", """XLMOnnxConfig"""],
    """tokenization_xlm""": ["""XLMTokenizer"""],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowerCAmelCase					: int        =[
           """XLM_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """XLMForMultipleChoice""",
           """XLMForQuestionAnswering""",
           """XLMForQuestionAnsweringSimple""",
           """XLMForSequenceClassification""",
           """XLMForTokenClassification""",
           """XLMModel""",
           """XLMPreTrainedModel""",
           """XLMWithLMHeadModel""",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowerCAmelCase					: Union[str, Any]        =[
           """TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """TFXLMForMultipleChoice""",
           """TFXLMForQuestionAnsweringSimple""",
           """TFXLMForSequenceClassification""",
           """TFXLMForTokenClassification""",
           """TFXLMMainLayer""",
           """TFXLMModel""",
           """TFXLMPreTrainedModel""",
           """TFXLMWithLMHeadModel""",
       ]


if TYPE_CHECKING:
       from .configuration_xlm import XLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XLMConfig, XLMOnnxConfig
       from .tokenization_xlm import XLMTokenizer

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_xlm import (
                  XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
                  XLMForMultipleChoice,
                  XLMForQuestionAnswering,
                  XLMForQuestionAnsweringSimple,
                  XLMForSequenceClassification,
                  XLMForTokenClassification,
                  XLMModel,
                  XLMPreTrainedModel,
                  XLMWithLMHeadModel,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_xlm import (
                  TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFXLMForMultipleChoice,
                  TFXLMForQuestionAnsweringSimple,
                  TFXLMForSequenceClassification,
                  TFXLMForTokenClassification,
                  TFXLMMainLayer,
                  TFXLMModel,
                  TFXLMPreTrainedModel,
                  TFXLMWithLMHeadModel,
              )

else:
       import sys

       __lowerCAmelCase					: Optional[int]        =_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



