from dataclasses import dataclass, field
from typing import Tuple

from ..utils import cached_property, is_torch_available, is_torch_tpu_available, logging, requires_backends
from .benchmark_args_utils import BenchmarkArguments


if is_torch_available():
			import torch

if is_torch_tpu_available(check_device=False):
			import torch_xla.core.xla_model as xm


__lowerCamelCase      :			Tuple							       =		logging.get_logger(__name__)







@dataclass
class __snake_case    (						A__		):
			lowerCAmelCase_														=							[
			    "no_inference",
			    "no_cuda",
			    "no_tpu",
			    "no_speed",
			    "no_memory",
			    "no_env_print",
			    "no_multi_process",
			]




			def __init__(   self      :    Dict	,     **_lowercase      :    Optional[int]				):



					"""simple docstring"""






					for deprecated_arg in self.deprecated_args:
							if deprecated_arg in kwargs:
									SCREAMING_SNAKE_CASE__      							=				deprecated_arg[3:]
									setattr(self	,     __A	,     not kwargs.pop(__A				)				)
									logger.warning(
									    f"""{deprecated_arg} is depreciated. Please use --no_{positive_arg} or"""
									    f""" {positive_arg}={kwargs[positive_arg]}"""				)

					SCREAMING_SNAKE_CASE__      							=				kwargs.pop("""torchscript"""	,     self.torchscript				)
					SCREAMING_SNAKE_CASE__      							=				kwargs.pop("""torch_xla_tpu_print_metrics"""	,     self.torch_xla_tpu_print_metrics				)
					SCREAMING_SNAKE_CASE__      							=				kwargs.pop("""fp16_opt_level"""	,     self.fpaa_opt_level				)
					super().__init__(**__A				)

			lowerCAmelCase_														=							field(default=A__       ,		metadata={"help": "Trace the models using torchscript"}		)
			lowerCAmelCase_														=							field(default=A__       ,		metadata={"help": "Print Xla/PyTorch tpu metrics"}		)
			lowerCAmelCase_														=							field(
			    default="O1"       ,		metadata={
			        "help": (
			            "For fp16: Apex AMP optimization level selected in ['O0', 'O1', 'O2', and 'O3']. "
			            "See details at https://nvidia.github.io/apex/amp.html"
			        )
			    }       ,		)




			@cached_property
			def      __a						(   self      :    Optional[Any]				):



					"""simple docstring"""






					requires_backends(self	,     ["""torch"""]				)
					logger.info("""PyTorch: setting up devices"""				)
					if not self.cuda:
							SCREAMING_SNAKE_CASE__      							=				torch.device("""cpu"""				)
							SCREAMING_SNAKE_CASE__      							=				0
					elif is_torch_tpu_available():
							SCREAMING_SNAKE_CASE__      							=				xm.xla_device()
							SCREAMING_SNAKE_CASE__      							=				0
					else:
							SCREAMING_SNAKE_CASE__      							=				torch.device("""cuda""" if torch.cuda.is_available() else """cpu"""				)
							SCREAMING_SNAKE_CASE__      							=				torch.cuda.device_count()
					return device, n_gpu




			@property
			def      __a						(   self      :    Union[str, Any]				):



					"""simple docstring"""






					return is_torch_tpu_available() and self.tpu




			@property
			def      __a						(   self      :    Optional[int]				):



					"""simple docstring"""






					requires_backends(self	,     ["""torch"""]				)
					# TODO(PVP): currently only single GPU is supported
					return torch.cuda.current_device()




			@property
			def      __a						(   self      :    Any				):



					"""simple docstring"""






					requires_backends(self	,     ["""torch"""]				)
					return self._setup_devices[0]




			@property
			def      __a						(   self      :    str				):



					"""simple docstring"""






					requires_backends(self	,     ["""torch"""]				)
					return self._setup_devices[1]




			@property
			def      __a						(   self      :    Optional[int]				):



					"""simple docstring"""






					return self.n_gpu > 0

from typing import TYPE_CHECKING

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


__lowerCamelCase      :			Optional[int]							       =		{
    '''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:
   __lowerCamelCase      :			Optional[Any]							       =		['''WhisperTokenizerFast''']

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

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

try:
   if not is_flax_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __lowerCamelCase      :			List[Any]							       =		[
       '''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

   __lowerCamelCase      :			Tuple							       =		_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
