
"""simple docstring"""






import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_torch_available
from transformers.testing_utils import require_torch, torch_device


if is_torch_available():
 from transformers import PyTorchBenchmark, PyTorchBenchmarkArguments





@require_torch
class 				a__					(						unittest.TestCase       ):



     def  lowerCamelCase_						(							self :str      ,  _lowerCamelCase :str   ):







      '''simple docstring'''



      for model_result in results.values():
       for batch_size, sequence_length in zip(model_result['bs']      ,  model_result['ss']   ):
        UpperCamelCase_     :					Tuple   	=model_result['result'][batch_size][sequence_length]
        self.assertIsNotNone(_lowerCamelCase   )



     def  lowerCamelCase_						(							self :List[Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					Any   	='sshleifer/tiny-gpt2'
      UpperCamelCase_     :					Optional[Any]   	=PyTorchBenchmarkArguments(
          models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  multi_process=_lowerCamelCase      ,  )
      UpperCamelCase_     :					List[Any]   	=PyTorchBenchmark(_lowerCamelCase   )
      UpperCamelCase_     :					Dict   	=benchmark.run()
      self.check_results_dict_not_empty(results.time_inference_result   )
      self.check_results_dict_not_empty(results.memory_inference_result   )



     def  lowerCamelCase_						(							self :Optional[int]   ):







      '''simple docstring'''



      UpperCamelCase_     :					Optional[int]   	='sgugger/tiny-distilbert-classification'
      UpperCamelCase_     :					Optional[Any]   	=PyTorchBenchmarkArguments(
          models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  multi_process=_lowerCamelCase      ,  only_pretrain_model=_lowerCamelCase      ,  )
      UpperCamelCase_     :					Dict   	=PyTorchBenchmark(_lowerCamelCase   )
      UpperCamelCase_     :					Dict   	=benchmark.run()
      self.check_results_dict_not_empty(results.time_inference_result   )
      self.check_results_dict_not_empty(results.memory_inference_result   )



     def  lowerCamelCase_						(							self :Union[str, Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					Dict   	='sshleifer/tiny-gpt2'
      UpperCamelCase_     :					Optional[Any]   	=PyTorchBenchmarkArguments(
          models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  torchscript=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  multi_process=_lowerCamelCase      ,  )
      UpperCamelCase_     :					List[Any]   	=PyTorchBenchmark(_lowerCamelCase   )
      UpperCamelCase_     :					List[str]   	=benchmark.run()
      self.check_results_dict_not_empty(results.time_inference_result   )
      self.check_results_dict_not_empty(results.memory_inference_result   )



     @unittest.skipIf(torch_device == 'cpu'      ,  'Cant do half precision'   )
     def  lowerCamelCase_						(							self :Optional[Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					Optional[Any]   	='sshleifer/tiny-gpt2'
      UpperCamelCase_     :					str   	=PyTorchBenchmarkArguments(
          models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  fpaa=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  multi_process=_lowerCamelCase      ,  )
      UpperCamelCase_     :					List[str]   	=PyTorchBenchmark(_lowerCamelCase   )
      UpperCamelCase_     :					Any   	=benchmark.run()
      self.check_results_dict_not_empty(results.time_inference_result   )
      self.check_results_dict_not_empty(results.memory_inference_result   )



     def  lowerCamelCase_						(							self :List[str]   ):







      '''simple docstring'''



      UpperCamelCase_     :					Dict   	='sshleifer/tiny-gpt2'
      UpperCamelCase_     :					Optional[int]   	=AutoConfig.from_pretrained(_lowerCamelCase   )
      # set architectures equal to `None`
      UpperCamelCase_     :					Optional[Any]   	=None
      UpperCamelCase_     :					List[Any]   	=PyTorchBenchmarkArguments(
          models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  multi_process=_lowerCamelCase      ,  )
      UpperCamelCase_     :					Union[str, Any]   	=PyTorchBenchmark(_lowerCamelCase      ,  configs=[config]   )
      UpperCamelCase_     :					Dict   	=benchmark.run()
      self.check_results_dict_not_empty(results.time_inference_result   )
      self.check_results_dict_not_empty(results.memory_inference_result   )



     def  lowerCamelCase_						(							self :List[Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[str]   	='sshleifer/tiny-gpt2'
      UpperCamelCase_     :					List[str]   	=PyTorchBenchmarkArguments(
          models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  multi_process=_lowerCamelCase      ,  )
      UpperCamelCase_     :					List[Any]   	=PyTorchBenchmark(_lowerCamelCase   )
      UpperCamelCase_     :					Optional[Any]   	=benchmark.run()
      self.check_results_dict_not_empty(results.time_train_result   )
      self.check_results_dict_not_empty(results.memory_train_result   )



     @unittest.skipIf(torch_device == 'cpu'      ,  'Can\'t do half precision'   )
     def  lowerCamelCase_						(							self :Tuple   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[str]   	='sshleifer/tiny-gpt2'
      UpperCamelCase_     :					str   	=PyTorchBenchmarkArguments(
          models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  fpaa=_lowerCamelCase      ,  multi_process=_lowerCamelCase      ,  )
      UpperCamelCase_     :					Dict   	=PyTorchBenchmark(_lowerCamelCase   )
      UpperCamelCase_     :					int   	=benchmark.run()
      self.check_results_dict_not_empty(results.time_train_result   )
      self.check_results_dict_not_empty(results.memory_train_result   )



     def  lowerCamelCase_						(							self :Any   ):







      '''simple docstring'''



      UpperCamelCase_     :					int   	='sshleifer/tiny-gpt2'
      UpperCamelCase_     :					List[Any]   	=AutoConfig.from_pretrained(_lowerCamelCase   )
      UpperCamelCase_     :					Union[str, Any]   	=PyTorchBenchmarkArguments(
          models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  multi_process=_lowerCamelCase      ,  )
      UpperCamelCase_     :					Optional[int]   	=PyTorchBenchmark(_lowerCamelCase      ,  configs=[config]   )
      UpperCamelCase_     :					List[str]   	=benchmark.run()
      self.check_results_dict_not_empty(results.time_inference_result   )
      self.check_results_dict_not_empty(results.memory_inference_result   )



     def  lowerCamelCase_						(							self :Dict   ):







      '''simple docstring'''



      UpperCamelCase_     :					str   	='sshleifer/tinier_bart'
      UpperCamelCase_     :					List[Any]   	=AutoConfig.from_pretrained(_lowerCamelCase   )
      UpperCamelCase_     :					Dict   	=PyTorchBenchmarkArguments(
          models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  multi_process=_lowerCamelCase      ,  )
      UpperCamelCase_     :					Union[str, Any]   	=PyTorchBenchmark(_lowerCamelCase      ,  configs=[config]   )
      UpperCamelCase_     :					Union[str, Any]   	=benchmark.run()
      self.check_results_dict_not_empty(results.time_inference_result   )
      self.check_results_dict_not_empty(results.memory_inference_result   )



     def  lowerCamelCase_						(							self :List[Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[str]   	='sshleifer/tiny-gpt2'
      UpperCamelCase_     :					Optional[int]   	=AutoConfig.from_pretrained(_lowerCamelCase   )
      UpperCamelCase_     :					Any   	=PyTorchBenchmarkArguments(
          models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  multi_process=_lowerCamelCase      ,  )
      UpperCamelCase_     :					Union[str, Any]   	=PyTorchBenchmark(_lowerCamelCase      ,  configs=[config]   )
      UpperCamelCase_     :					Union[str, Any]   	=benchmark.run()
      self.check_results_dict_not_empty(results.time_train_result   )
      self.check_results_dict_not_empty(results.memory_train_result   )



     def  lowerCamelCase_						(							self :Dict   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[Any]   	='sshleifer/tinier_bart'
      UpperCamelCase_     :					List[str]   	=AutoConfig.from_pretrained(_lowerCamelCase   )
      UpperCamelCase_     :					Optional[Any]   	=PyTorchBenchmarkArguments(
          models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  multi_process=_lowerCamelCase      ,  )
      UpperCamelCase_     :					int   	=PyTorchBenchmark(_lowerCamelCase      ,  configs=[config]   )
      UpperCamelCase_     :					Union[str, Any]   	=benchmark.run()
      self.check_results_dict_not_empty(results.time_train_result   )
      self.check_results_dict_not_empty(results.memory_train_result   )



     def  lowerCamelCase_						(							self :List[Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					Union[str, Any]   	='sshleifer/tiny-gpt2'
      with tempfile.TemporaryDirectory() as tmp_dir:
       UpperCamelCase_     :					int   	=PyTorchBenchmarkArguments(
           models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  inference=_lowerCamelCase      ,  save_to_csv=_lowerCamelCase      ,  sequence_lengths=[8]      ,  batch_sizes=[1]      ,  inference_time_csv_file=os.path.join(_lowerCamelCase      ,  'inf_time.csv'   )      ,  train_memory_csv_file=os.path.join(_lowerCamelCase      ,  'train_mem.csv'   )      ,  inference_memory_csv_file=os.path.join(_lowerCamelCase      ,  'inf_mem.csv'   )      ,  train_time_csv_file=os.path.join(_lowerCamelCase      ,  'train_time.csv'   )      ,  env_info_csv_file=os.path.join(_lowerCamelCase      ,  'env.csv'   )      ,  multi_process=_lowerCamelCase      ,  )
       UpperCamelCase_     :					Optional[int]   	=PyTorchBenchmark(_lowerCamelCase   )
       benchmark.run()
       self.assertTrue(Path(os.path.join(_lowerCamelCase      ,  'inf_time.csv'   )   ).exists()   )
       self.assertTrue(Path(os.path.join(_lowerCamelCase      ,  'train_time.csv'   )   ).exists()   )
       self.assertTrue(Path(os.path.join(_lowerCamelCase      ,  'inf_mem.csv'   )   ).exists()   )
       self.assertTrue(Path(os.path.join(_lowerCamelCase      ,  'train_mem.csv'   )   ).exists()   )
       self.assertTrue(Path(os.path.join(_lowerCamelCase      ,  'env.csv'   )   ).exists()   )




     def  lowerCamelCase_						(							self :Optional[Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					str   	='sshleifer/tiny-gpt2'

      def _check_summary_is_not_empty(_lowerCamelCase :Optional[int]   ):
       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:
       UpperCamelCase_     :					int   	=PyTorchBenchmarkArguments(
           models=[MODEL_ID]      ,  training=_lowerCamelCase      ,  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      ,  multi_process=_lowerCamelCase      ,  )
       UpperCamelCase_     :					List[str]   	=PyTorchBenchmark(_lowerCamelCase   )
       UpperCamelCase_     :					Union[str, Any]   	=benchmark.run()
       _check_summary_is_not_empty(result.inference_summary   )
       _check_summary_is_not_empty(result.train_summary   )
       self.assertTrue(Path(os.path.join(_lowerCamelCase      ,  'log.txt'   )   ).exists()   )


"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__SCREAMING_SNAKE_CASE							=     {
    'configuration_whisper': ['WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP', 'WhisperConfig', 'WhisperOnnxConfig'],
    'feature_extraction_whisper': ['WhisperFeatureExtractor'],
    'processing_whisper': ['WhisperProcessor'],
    'tokenization_whisper': ['WhisperTokenizer'],
}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __SCREAMING_SNAKE_CASE							=     ['WhisperTokenizerFast']

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __SCREAMING_SNAKE_CASE							=     [
     'WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST',
     'WhisperForConditionalGeneration',
     'WhisperModel',
     'WhisperPreTrainedModel',
     'WhisperForAudioClassification',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __SCREAMING_SNAKE_CASE							=     [
     'TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST',
     'TFWhisperForConditionalGeneration',
     'TFWhisperModel',
     'TFWhisperPreTrainedModel',
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __SCREAMING_SNAKE_CASE							=     [
     'FlaxWhisperForConditionalGeneration',
     'FlaxWhisperModel',
     'FlaxWhisperPreTrainedModel',
     'FlaxWhisperForAudioClassification',
 ]


if TYPE_CHECKING:
 from .configuration_whisper import WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP, WhisperConfig, WhisperOnnxConfig
 from .feature_extraction_whisper import WhisperFeatureExtractor
 from .processing_whisper import WhisperProcessor
 from .tokenization_whisper import WhisperTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_whisper_fast import WhisperTokenizerFast

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_whisper import (
      WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
      WhisperForAudioClassification,
      WhisperForConditionalGeneration,
      WhisperModel,
      WhisperPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_whisper import (
      TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFWhisperForConditionalGeneration,
      TFWhisperModel,
      TFWhisperPreTrainedModel,
  )

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_whisper import (
      FlaxWhisperForAudioClassification,
      FlaxWhisperForConditionalGeneration,
      FlaxWhisperModel,
      FlaxWhisperPreTrainedModel,
  )

else:
 import sys

 __SCREAMING_SNAKE_CASE							=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
