




import dataclasses
import json
import warnings
from dataclasses import dataclass, field
from time import time
from typing import List

from ..utils import logging


UpperCamelCase								=					logging.get_logger(__name__)



def 							_A       (						lowerCAmelCase_					: Any=None       ,    lowerCAmelCase_					: int=None      ):
  """simple docstring"""

  return field(default_factory=lambda: default       ,    metadata=lowerCAmelCase_      )






@dataclass
class 			__lowerCamelCase	:




    """simple docstring"""

    snake_case__ =				list_field(
        default=[]     ,    metadata={
            "help": (
                "Model checkpoints to be provided to the AutoModel classes. Leave blank to benchmark the base version"
                " of all available models"
            )
        }     ,    )

    snake_case__ =				list_field(
        default=[8]     ,    metadata={"help": "List of batch sizes for which memory and time performance will be evaluated"}   )

    snake_case__ =				list_field(
        default=[8, 3_2, 1_2_8, 5_1_2]     ,    metadata={"help": "List of sequence lengths for which memory and time performance will be evaluated"}     ,    )

    snake_case__ =				field(
        default=UpperCamelCase__     ,    metadata={"help": "Whether to benchmark inference of model. Inference can be disabled via --no-inference."}     ,    )
    snake_case__ =				field(
        default=UpperCamelCase__     ,    metadata={"help": "Whether to run on available cuda devices. Cuda can be disabled via --no-cuda."}     ,    )
    snake_case__ =				field(
        default=UpperCamelCase__     ,    metadata={"help": "Whether to run on available tpu devices. TPU can be disabled via --no-tpu."}   )
    snake_case__ =				field(default=UpperCamelCase__     ,    metadata={"help": "Use FP16 to accelerate inference."}   )
    snake_case__ =				field(default=UpperCamelCase__     ,    metadata={"help": "Benchmark training of model"}   )
    snake_case__ =				field(default=UpperCamelCase__     ,    metadata={"help": "Verbose memory tracing"}   )
    snake_case__ =				field(
        default=UpperCamelCase__     ,    metadata={"help": "Whether to perform speed measurements. Speed measurements can be disabled via --no-speed."}     ,    )
    snake_case__ =				field(
        default=UpperCamelCase__     ,    metadata={
            "help": "Whether to perform memory measurements. Memory measurements can be disabled via --no-memory"
        }     ,    )
    snake_case__ =				field(default=UpperCamelCase__     ,    metadata={"help": "Trace memory line by line"}   )
    snake_case__ =				field(default=UpperCamelCase__     ,    metadata={"help": "Save result to a CSV file"}   )
    snake_case__ =				field(default=UpperCamelCase__     ,    metadata={"help": "Save all print statements in a log file"}   )
    snake_case__ =				field(default=UpperCamelCase__     ,    metadata={"help": "Whether to print environment information"}   )
    snake_case__ =				field(
        default=UpperCamelCase__     ,    metadata={
            "help": (
                "Whether to use multiprocessing for memory and speed measurement. It is highly recommended to use"
                " multiprocessing for accurate CPU and GPU memory measurements. This option should only be disabled"
                " for debugging / testing and on TPU."
            )
        }     ,    )
    snake_case__ =				field(
        default=f"inference_time_{round(time()   )}.csv"     ,    metadata={"help": "CSV filename used if saving time results to csv."}     ,    )
    snake_case__ =				field(
        default=f"inference_memory_{round(time()   )}.csv"     ,    metadata={"help": "CSV filename used if saving memory results to csv."}     ,    )
    snake_case__ =				field(
        default=f"train_time_{round(time()   )}.csv"     ,    metadata={"help": "CSV filename used if saving time results to csv for training."}     ,    )
    snake_case__ =				field(
        default=f"train_memory_{round(time()   )}.csv"     ,    metadata={"help": "CSV filename used if saving memory results to csv for training."}     ,    )
    snake_case__ =				field(
        default=f"env_info_{round(time()   )}.csv"     ,    metadata={"help": "CSV filename used if saving environment information."}     ,    )
    snake_case__ =				field(
        default=f"log_{round(time()   )}.csv"     ,    metadata={"help": "Log filename used if print statements are saved in log."}     ,    )
    snake_case__ =				field(default=3     ,    metadata={"help": "Times an experiment will be run."}   )
    snake_case__ =				field(
        default=UpperCamelCase__     ,    metadata={
            "help": (
                "Instead of loading the model as defined in `config.architectures` if exists, just load the pretrain"
                " model weights."
            )
        }     ,    )


    def        a				(	self					:					Any       )				->	Tuple:
      warnings.warn(
          f'The class {self.__class__} is deprecated. Hugging Face Benchmarking utils'
          " are deprecated in general and it is advised to use external Benchmarking libraries "
          " to benchmark Transformer models."       ,     SCREAMING_SNAKE_CASE__       ,     )


    def        a				(	self					:					List[str]       )				->	Tuple:
      return json.dumps(dataclasses.asdict(self       )       ,     indent=2       )


    @property
    def        a				(	self					:					str       )				->	List[str]:
      if len(self.models       ) <= 0:
        raise ValueError(
            "Please make sure you provide at least one model name / model identifier, *e.g.* `--models"
            " bert-base-cased` or `args.models = ['bert-base-cased']."       )
      return self.models


    @property
    def        a				(	self					:					Optional[int]       )				->	Any:
      if not self.multi_process:
        return False
      elif self.is_tpu:
        logger.info("Multiprocessing is currently not possible on TPU."       )
        return False
      else:
        return True






import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin





class 			__lowerCamelCase	(   UpperCamelCase__   ):




    """simple docstring"""

    snake_case__ =				"Speech2TextFeatureExtractor"
    snake_case__ =				"Speech2TextTokenizer"


    def __init__(	self					:					int       ,     SCREAMING_SNAKE_CASE__					:					Dict       ,     SCREAMING_SNAKE_CASE__					:					Tuple       )				->	Optional[Any]:
         super().__init__(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			self.feature_extractor
         lowerCAmelCase__          =			False


    def __call__(	self					:					str       ,     *SCREAMING_SNAKE_CASE__					:					int       ,     **SCREAMING_SNAKE_CASE__					:					int       )				->	Optional[Any]:
         # For backward compatibility
         if self._in_target_context_manager:
              return self.current_processor(*SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )

         if "raw_speech" in kwargs:
              warnings.warn("Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."       )
              lowerCAmelCase__          =			kwargs.pop("raw_speech"       )
         else:
              lowerCAmelCase__          =			kwargs.pop("audio"       ,     SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			kwargs.pop("sampling_rate"       ,     SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			kwargs.pop("text"       ,     SCREAMING_SNAKE_CASE__       )
         if len(SCREAMING_SNAKE_CASE__       ) > 0:
              lowerCAmelCase__          =			args[0]
              lowerCAmelCase__          =			args[1:]

         if audio is None and text is None:
              raise ValueError("You need to specify either an `audio` or `text` input to process."       )

         if audio is not None:
              lowerCAmelCase__          =			self.feature_extractor(SCREAMING_SNAKE_CASE__       ,     *SCREAMING_SNAKE_CASE__       ,     sampling_rate=SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )
         if text is not None:
              lowerCAmelCase__          =			self.tokenizer(SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )

         if text is None:
              return inputs
         elif audio is None:
              return encodings
         else:
              lowerCAmelCase__          =			encodings["input_ids"]
              return inputs


    def        a				(	self					:					str       ,     *SCREAMING_SNAKE_CASE__					:					Dict       ,     **SCREAMING_SNAKE_CASE__					:					int       )				->	Union[str, Any]:
         return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					Dict       ,     *SCREAMING_SNAKE_CASE__					:					Optional[int]       ,     **SCREAMING_SNAKE_CASE__					:					Optional[int]       )				->	Optional[Any]:
         return self.tokenizer.decode(*SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )


    @contextmanager
    def        a				(	self					:					Union[str, Any]       )				->	Any:
         warnings.warn(
             "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your "
             "labels by using the argument `text` of the regular `__call__` method (either in the same call as "
             "your audio inputs, or in a separate call."       )
         lowerCAmelCase__          =			True
         lowerCAmelCase__          =			self.tokenizer
         yield
         lowerCAmelCase__          =			self.feature_extractor
         lowerCAmelCase__          =			False
