'''simple docstring'''






import random
import timeit
from functools import wraps
from typing import Callable, Optional

from ..configuration_utils import PretrainedConfig
from ..models.auto.modeling_tf_auto import TF_MODEL_MAPPING, TF_MODEL_WITH_LM_HEAD_MAPPING
from ..utils import is_pyanvml_available, is_tf_available, logging
from .benchmark_utils import (
    Benchmark,
    Memory,
    MemorySummary,
    measure_peak_memory_cpu,
    start_memory_tracing,
    stop_memory_tracing,
)


if is_tf_available():
     import tensorflow as tf
     from tensorflow.python.framework.errors_impl import ResourceExhaustedError

     from .benchmark_args_tf import TensorFlowBenchmarkArguments

if is_pyanvml_available():
     import pyanvml.pyanvml as nvml

__a										=					logging.get_logger(__name__)






def    __UpperCAmelCase			(  a_:       List[Any],					a_:       Dict							):
   def run_func(a_:       Tuple							):
      @wraps(_lowerCAmelCase							)
      def run_in_eager_mode(*a_:       Optional[Any],					**a_:       Optional[int]							):
         return func(*_lowerCAmelCase,					**_lowerCAmelCase							)

      @wraps(_lowerCAmelCase							)
      @tf.function(experimental_compile=_lowerCAmelCase							)
      def run_in_graph_mode(*a_:       str,					**a_:       str							):
         return func(*_lowerCAmelCase,					**_lowerCAmelCase							)

      if do_eager_mode is True:
         if use_xla is not False:
            raise ValueError(
                "Cannot run model in XLA, if `args.eager_mode` is set to `True`. Please set `args.eager_mode=False`."							)
         return run_in_eager_mode
      else:
         return run_in_graph_mode

   return run_func






def    __UpperCAmelCase			(  a_:       int,					a_:       Tuple,					a_:       Union[str, Any]							):
   _UpperCAmelCase							:	Optional[Any]							=   random.Random()
   _UpperCAmelCase							:	str							=   [rng.randint(0,					vocab_size - 1							) for i in range(batch_size * sequence_length							)]
   return tf.constant(_lowerCAmelCase,					shape=(batch_size, sequence_length),					dtype=tf.intaa							)






class     A__							(       __snake_case   ):





   """simple docstring"""





   UpperCamelCase_       :						TensorFlowBenchmarkArguments
   UpperCamelCase_       :						PretrainedConfig
   UpperCamelCase_       :						str    				=     "TensorFlow"




   @property
   def 			_lowerCAmelCase		( self     :		Optional[int]			)       ->    Optional[Any]:







      """simple docstring"""




      return tf.__version__




   def 			_lowerCAmelCase		( self     :		Any						,     lowerCAmelCase__     :		Tuple						,     lowerCAmelCase__     :		List[Any]						,     lowerCAmelCase__     :		Union[str, Any]			)       ->    List[Any]:







      """simple docstring"""




      _UpperCAmelCase							:	Optional[int]							=   self.args.strategy
      if strategy is None:
         raise ValueError("A device strategy has to be initialized before using TensorFlow."			)
      _UpperCAmelCase							:	Optional[Any]							=   self._prepare_inference_func(A_						,     A_						,     A_			)
      return self._measure_speed(_inference			)




   def 			_lowerCAmelCase		( self     :		Tuple						,     lowerCAmelCase__     :		Tuple						,     lowerCAmelCase__     :		str						,     lowerCAmelCase__     :		Union[str, Any]			)       ->    str:







      """simple docstring"""




      _UpperCAmelCase							:	Any							=   self.args.strategy
      if strategy is None:
         raise ValueError("A device strategy has to be initialized before using TensorFlow."			)
      _UpperCAmelCase							:	Any							=   self._prepare_train_func(A_						,     A_						,     A_			)
      return self._measure_speed(_train			)




   def 			_lowerCAmelCase		( self     :		Dict						,     lowerCAmelCase__     :		Optional[Any]						,     lowerCAmelCase__     :		Any						,     lowerCAmelCase__     :		Tuple			)       ->    Union[str, Any]:







      """simple docstring"""




      if self.args.is_gpu:
         tf.config.experimental.set_memory_growth(self.args.gpu_list[self.args.device_idx]						,     A_			)
      _UpperCAmelCase							:	Union[str, Any]							=   self.args.strategy
      if strategy is None:
         raise ValueError("A device strategy has to be initialized before using TensorFlow."			)
      _UpperCAmelCase							:	Union[str, Any]							=   self._prepare_inference_func(A_						,     A_						,     A_			)
      return self._measure_memory(_inference			)




   def 			_lowerCAmelCase		( self     :		int						,     lowerCAmelCase__     :		Tuple						,     lowerCAmelCase__     :		Any						,     lowerCAmelCase__     :		Any			)       ->    Dict:







      """simple docstring"""




      if self.args.is_gpu:
         tf.config.experimental.set_memory_growth(self.args.gpu_list[self.args.device_idx]						,     A_			)
      _UpperCAmelCase							:	Union[str, Any]							=   self.args.strategy
      if strategy is None:
         raise ValueError("A device strategy has to be initialized before using TensorFlow."			)

      _UpperCAmelCase							:	Union[str, Any]							=   self._prepare_train_func(A_						,     A_						,     A_			)
      return self._measure_memory(_train			)




   def 			_lowerCAmelCase		( self     :		Optional[int]						,     lowerCAmelCase__     :		Union[str, Any]						,     lowerCAmelCase__     :		List[Any]						,     lowerCAmelCase__     :		str			)       ->    Optional[Any]:







      """simple docstring"""




      _UpperCAmelCase							:	Tuple							=   self.config_dict[model_name]

      if self.args.fpaa:
         raise NotImplementedError("Mixed precision is currently not supported."			)

      _UpperCAmelCase							:	Union[str, Any]							=   (
          hasattr(A_						,     "architectures"			)
          and isinstance(config.architectures						,     A_			)
          and len(config.architectures			) > 0
      )
      if not self.args.only_pretrain_model and has_model_class_in_config:
         try:
            _UpperCAmelCase							:	Optional[Any]							=   "TF" + config.architectures[0]  # prepend 'TF' for tensorflow model
            _UpperCAmelCase							:	str							=   __import__("transformers"						,     fromlist=[model_class]			)
            _UpperCAmelCase							:	Dict							=   getattr(A_						,     A_			)
            _UpperCAmelCase							:	List[str]							=   model_cls(A_			)
         except ImportError:
            raise ImportError(
                F"""{model_class} does not exist. If you just want to test the pretrained model, you might want to"""
                " set `--only_pretrain_model` or `args.only_pretrain_model=True`."			)
      else:
         _UpperCAmelCase							:	Tuple							=   TF_MODEL_MAPPING[config.__class__](A_			)

      # encoder-decoder has vocab size saved differently
      _UpperCAmelCase							:	Optional[int]							=   config.vocab_size if hasattr(A_						,     "vocab_size"			) else config.encoder.vocab_size
      _UpperCAmelCase							:	str							=   random_input_ids(A_						,     A_						,     A_			)

      @run_with_tf_optimizations(self.args.eager_mode						,     self.args.use_xla			)
      def encoder_decoder_forward():
         return model(A_						,     decoder_input_ids=A_						,     training=A_			)

      @run_with_tf_optimizations(self.args.eager_mode						,     self.args.use_xla			)
      def encoder_forward():
         return model(A_						,     training=A_			)

      _UpperCAmelCase							:	Dict							=   encoder_decoder_forward if config.is_encoder_decoder else encoder_forward

      return _inference




   def 			_lowerCAmelCase		( self     :		List[Any]						,     lowerCAmelCase__     :		List[Any]						,     lowerCAmelCase__     :		List[str]						,     lowerCAmelCase__     :		Union[str, Any]			)       ->    str:







      """simple docstring"""




      _UpperCAmelCase							:	Union[str, Any]							=   self.config_dict[model_name]

      if self.args.eager_mode is not False:
         raise ValueError("Training cannot be done in eager mode. Please make sure that `args.eager_mode = False`."			)

      if self.args.fpaa:
         raise NotImplementedError("Mixed precision is currently not supported."			)

      _UpperCAmelCase							:	List[Any]							=   (
          hasattr(A_						,     "architectures"			)
          and isinstance(config.architectures						,     A_			)
          and len(config.architectures			) > 0
      )
      if not self.args.only_pretrain_model and has_model_class_in_config:
         try:
            _UpperCAmelCase							:	Any							=   "TF" + config.architectures[0]  # prepend 'TF' for tensorflow model
            _UpperCAmelCase							:	Dict							=   __import__("transformers"						,     fromlist=[model_class]			)
            _UpperCAmelCase							:	Any							=   getattr(A_						,     A_			)
            _UpperCAmelCase							:	List[str]							=   model_cls(A_			)
         except ImportError:
            raise ImportError(
                F"""{model_class} does not exist. If you just want to test the pretrained model, you might want to"""
                " set `--only_pretrain_model` or `args.only_pretrain_model=True`."			)
      else:
         _UpperCAmelCase							:	int							=   TF_MODEL_WITH_LM_HEAD_MAPPING[config.__class__](A_			)

      # encoder-decoder has vocab size saved differently
      _UpperCAmelCase							:	Optional[Any]							=   config.vocab_size if hasattr(A_						,     "vocab_size"			) else config.encoder.vocab_size
      _UpperCAmelCase							:	Any							=   random_input_ids(A_						,     A_						,     A_			)

      @run_with_tf_optimizations(self.args.eager_mode						,     self.args.use_xla			)
      def encoder_decoder_train():
         _UpperCAmelCase							:	List[Any]							=   model(A_						,     decoder_input_ids=A_						,     labels=A_						,     training=A_			)[0]
         _UpperCAmelCase							:	Dict							=   tf.gradients(A_						,     model.trainable_variables			)
         return gradients

      @run_with_tf_optimizations(self.args.eager_mode						,     self.args.use_xla			)
      def encoder_train():
         _UpperCAmelCase							:	Union[str, Any]							=   model(A_						,     labels=A_						,     training=A_			)[0]
         _UpperCAmelCase							:	Optional[int]							=   tf.gradients(A_						,     model.trainable_variables			)
         return gradients

      _UpperCAmelCase							:	Union[str, Any]							=   encoder_decoder_train if config.is_encoder_decoder else encoder_train

      return _train




   def 			_lowerCAmelCase		( self     :		Union[str, Any]						,     lowerCAmelCase__     :		Any			)       ->    List[str]:







      """simple docstring"""




      with self.args.strategy.scope():
         try:
            if self.args.is_tpu or self.args.use_xla:
               # run additional 10 times to stabilize compilation for tpu
               logger.info("Do inference on TPU. Running model 5 times to stabilize compilation"			)
               timeit.repeat(A_						,     repeat=1						,     number=5			)

            # as written in https://docs.python.org/2/library/timeit.html#timeit.Timer.repeat, min should be taken rather than the average
            _UpperCAmelCase							:	str							=   timeit.repeat(
                A_						,     repeat=self.args.repeat						,     number=1_0						,     )

            return min(A_			) / 10.0
         except ResourceExhaustedError as e:
            self.print_fn(F"""Doesn't fit on GPU. {e}"""			)




   def 			_lowerCAmelCase		( self     :		List[Any]						,     lowerCAmelCase__     :		Union[str, Any]			)       ->    Optional[Any]:







      """simple docstring"""




      logger.info(
          "Note that TensorFlow allocates more memory than "
          "it might need to speed up computation. "
          "The memory reported here corresponds to the memory "
          "reported by `nvidia-smi`, which can vary depending "
          "on total available memory on the GPU that is used."			)
      with self.args.strategy.scope():
         try:
            if self.args.trace_memory_line_by_line:
               if not self.args.eager_mode:
                  raise ValueError(
                      "`args.eager_mode` is set to `False`. Make sure to run model in eager mode to measure memory"
                      " consumption line by line."			)
               _UpperCAmelCase							:	Dict							=   start_memory_tracing("transformers"			)

            if self.args.is_tpu:
               # tpu
               raise NotImplementedError(
                   "Memory Benchmarking is currently not implemented for TPU. Please disable memory benchmarking"
                   " with `args.memory=False`"			)
            elif self.args.is_gpu:
               # gpu
               if not is_pyanvml_available():
                  logger.warning(
                      "py3nvml not installed, we won't log GPU memory usage. "
                      "Install py3nvml (pip install py3nvml) to log information about GPU."			)
                  _UpperCAmelCase							:	Any							=   "N/A"
               else:
                  logger.info(
                      "Measuring total GPU usage on GPU device. Make sure to not have additional processes"
                      " running on the same GPU."			)
                  # init nvml
                  nvml.nvmlInit()
                  func()
                  _UpperCAmelCase							:	List[Any]							=   nvml.nvmlDeviceGetHandleByIndex(self.args.device_idx			)
                  _UpperCAmelCase							:	int							=   nvml.nvmlDeviceGetMemoryInfo(A_			)
                  _UpperCAmelCase							:	Tuple							=   meminfo.used
                  _UpperCAmelCase							:	List[str]							=   Memory(A_			)
                  # shutdown nvml
                  nvml.nvmlShutdown()
            else:
               # cpu
               if self.args.trace_memory_line_by_line:
                  logger.info(
                      "When enabling line by line tracing, the max peak memory for CPU is inaccurate in"
                      " TensorFlow."			)
                  _UpperCAmelCase							:	Optional[Any]							=   None
               else:
                  _UpperCAmelCase							:	List[str]							=   measure_peak_memory_cpu(A_			)
                  _UpperCAmelCase							:	Dict							=   Memory(A_			) if isinstance(A_						,     A_			) else memory_bytes
            if self.args.trace_memory_line_by_line:
               _UpperCAmelCase							:	int							=   stop_memory_tracing(A_			)
               if memory is None:
                  _UpperCAmelCase							:	str							=   summary.total
            else:
               _UpperCAmelCase							:	List[Any]							=   None

            return memory, summary
         except ResourceExhaustedError as e:
            self.print_fn(F"""Doesn't fit on GPU. {e}"""			)
            return "N/A", None






import warnings
from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


__lowerCamelCase       :     Union[str, Any]   =     logging.get_logger(__name__)

__lowerCamelCase       :     Any   =     {
    """facebook/bart-large""": """https://huggingface.co/facebook/bart-large/resolve/main/config.json""",
    # See all BART models at https://huggingface.co/models?filter=bart
}



class 					A__   (       __snake_case			):
      _UpperCAmelCase	:Dict						    =   'bart'
      _UpperCAmelCase	:str						    =   ['past_key_values']
      _UpperCAmelCase	:Any						    =   {'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}





      def __init__( self       ,							A_=5_0265       ,							A_=1024       ,							A_=12       ,							A_=4096       ,							A_=16       ,							A_=12       ,							A_=4096       ,							A_=16       ,							A_=0.0       ,							A_=0.0       ,							A_="gelu"       ,							A_=1024       ,							A_=0.1       ,							A_=0.0       ,							A_=0.0       ,							A_=0.02       ,							A_=0.0       ,							A_=False       ,							A_=True       ,							A_=3       ,							A_=1       ,							A_=0       ,							A_=2       ,							A_=True       ,							A_=2       ,							A_=2       ,							**A_       ,							):
       '''simple docstring'''




       UpperCamelCase	:					int       	=   vocab_size
       UpperCamelCase	:					List[Any]       	=   max_position_embeddings
       UpperCamelCase	:					Any       	=   d_model
       UpperCamelCase	:					Optional[Any]       	=   encoder_ffn_dim
       UpperCamelCase	:					List[Any]       	=   encoder_layers
       UpperCamelCase	:					int       	=   encoder_attention_heads
       UpperCamelCase	:					Optional[int]       	=   decoder_ffn_dim
       UpperCamelCase	:					List[str]       	=   decoder_layers
       UpperCamelCase	:					Optional[int]       	=   decoder_attention_heads
       UpperCamelCase	:					int       	=   dropout
       UpperCamelCase	:					int       	=   attention_dropout
       UpperCamelCase	:					Tuple       	=   activation_dropout
       UpperCamelCase	:					Tuple       	=   activation_function
       UpperCamelCase	:					int       	=   init_std
       UpperCamelCase	:					List[Any]       	=   encoder_layerdrop
       UpperCamelCase	:					List[str]       	=   decoder_layerdrop
       UpperCamelCase	:					Dict       	=   classifier_dropout
       UpperCamelCase	:					Optional[int]       	=   use_cache
       UpperCamelCase	:					List[Any]       	=   encoder_layers
       UpperCamelCase	:					int       	=   scale_embedding  # scale factor will be sqrt(d_model) if True

       super().__init__(
           num_labels=A_       ,							pad_token_id=A_       ,							bos_token_id=A_       ,							eos_token_id=A_       ,							is_encoder_decoder=A_       ,							decoder_start_token_id=A_       ,							forced_eos_token_id=A_       ,							**A_       ,							)

       # ensure backward compatibility for BART CNN models
       if self.forced_bos_token_id is None and kwargs.get("force_bos_token_to_be_generated"       ,							A_   ):
        UpperCamelCase	:					int       	=   self.bos_token_id
        warnings.warn(
            F"""Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. """
            "The config can simply be saved and uploaded again to be fixed."   )



class 					A__   (       __snake_case			):





      @property
      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       if self.task in ["default", "seq2seq-lm"]:
        UpperCamelCase	:					Optional[int]       	=   OrderedDict(
            [
                ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
            ]   )

        if self.use_past:
         UpperCamelCase	:					List[str]       	=   {0: "batch"}
         UpperCamelCase	:					Dict       	=   {0: "batch", 1: "past_decoder_sequence + sequence"}
        else:
         UpperCamelCase	:					Dict       	=   {0: "batch", 1: "decoder_sequence"}
         UpperCamelCase	:					Union[str, Any]       	=   {0: "batch", 1: "decoder_sequence"}

        if self.use_past:
         self.fill_with_past_key_values_(A_       ,							direction="inputs"   )
       elif self.task == "causal-lm":
        # TODO: figure this case out.
        UpperCamelCase	:					Any       	=   OrderedDict(
            [
                ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
            ]   )
        if self.use_past:
         UpperCamelCase	,    UpperCamelCase	:					Optional[int]       	=   self.num_layers
         for i in range(A_   ):
          UpperCamelCase	:					Optional[Any]       	=   {0: "batch", 2: "past_sequence + sequence"}
          UpperCamelCase	:					Union[str, Any]       	=   {0: "batch", 2: "past_sequence + sequence"}
       else:
        UpperCamelCase	:					Optional[Any]       	=   OrderedDict(
            [
                ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
                ("decoder_input_ids", {0: "batch", 1: "decoder_sequence"}),
                ("decoder_attention_mask", {0: "batch", 1: "decoder_sequence"}),
            ]   )

       return common_inputs





      @property
      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       if self.task in ["default", "seq2seq-lm"]:
        UpperCamelCase	:					Tuple       	=   super().outputs
       else:
        UpperCamelCase	:					Dict       	=   super(A_       ,							self   ).outputs
        if self.use_past:
         UpperCamelCase	,    UpperCamelCase	:					int       	=   self.num_layers
         for i in range(A_   ):
          UpperCamelCase	:					int       	=   {0: "batch", 2: "past_sequence + sequence"}
          UpperCamelCase	:					Tuple       	=   {0: "batch", 2: "past_sequence + sequence"}
       return common_outputs





      def        __UpperCamelCase( self       ,							A_       ,							A_ = -1       ,							A_ = -1       ,							A_ = False       ,							A_ = None       ,							):
       '''simple docstring'''




       UpperCamelCase	:					List[Any]       	=   self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           A_       ,							A_       ,							A_       ,							A_       ,							A_   )

       # Generate decoder inputs
       UpperCamelCase	:					List[Any]       	=   seq_length if not self.use_past else 1
       UpperCamelCase	:					Tuple       	=   self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           A_       ,							A_       ,							A_       ,							A_       ,							A_   )
       UpperCamelCase	:					Optional[int]       	=   {F"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
       UpperCamelCase	:					List[Any]       	=   dict(**A_       ,							**A_   )

       if self.use_past:
        if not is_torch_available():
         raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."   )
        else:
         import torch
        UpperCamelCase	,    UpperCamelCase	:					Optional[Any]       	=   common_inputs["input_ids"].shape
        UpperCamelCase	:					List[Any]       	=   common_inputs["decoder_input_ids"].shape[1]
        UpperCamelCase	,    UpperCamelCase	:					List[str]       	=   self.num_attention_heads
        UpperCamelCase	:					int       	=   (
            batch,
            num_encoder_attention_heads,
            encoder_seq_length,
            self._config.hidden_size // num_encoder_attention_heads,
        )
        UpperCamelCase	:					List[Any]       	=   decoder_seq_length + 3
        UpperCamelCase	:					str       	=   (
            batch,
            num_decoder_attention_heads,
            decoder_past_length,
            self._config.hidden_size // num_decoder_attention_heads,
        )

        UpperCamelCase	:					int       	=   torch.cat(
            [common_inputs["decoder_attention_mask"], torch.ones(A_       ,							A_   )]       ,							dim=1   )

        UpperCamelCase	:					int       	=   []
        # If the number of encoder and decoder layers are present in the model configuration, both are considered
        UpperCamelCase	,    UpperCamelCase	:					Union[str, Any]       	=   self.num_layers
        UpperCamelCase	:					Any       	=   min(A_       ,							A_   )
        UpperCamelCase	:					List[str]       	=   max(A_       ,							A_   ) - min_num_layers
        UpperCamelCase	:					Dict       	=   "encoder" if num_encoder_layers > num_decoder_layers else "decoder"

        for _ in range(A_   ):
         common_inputs["past_key_values"].append(
             (
                 torch.zeros(A_   ),
                 torch.zeros(A_   ),
                 torch.zeros(A_   ),
                 torch.zeros(A_   ),
             )   )
        # TODO: test this.
        UpperCamelCase	:					Optional[Any]       	=   encoder_shape if remaining_side_name == "encoder" else decoder_shape
        for _ in range(A_       ,							A_   ):
         common_inputs["past_key_values"].append((torch.zeros(A_   ), torch.zeros(A_   ))   )
       return common_inputs





      def        __UpperCamelCase( self       ,							A_       ,							A_ = -1       ,							A_ = -1       ,							A_ = False       ,							A_ = None       ,							):
       '''simple docstring'''




       UpperCamelCase	:					int       	=   self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           A_       ,							A_       ,							A_       ,							A_       ,							A_   )

       if self.use_past:
        if not is_torch_available():
         raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."   )
        else:
         import torch
        UpperCamelCase	,    UpperCamelCase	:					Union[str, Any]       	=   common_inputs["input_ids"].shape
        # Not using the same length for past_key_values
        UpperCamelCase	:					Optional[Any]       	=   seqlen + 2
        UpperCamelCase	,    UpperCamelCase	:					List[Any]       	=   self.num_layers
        UpperCamelCase	,    UpperCamelCase	:					Optional[int]       	=   self.num_attention_heads
        UpperCamelCase	:					str       	=   (
            batch,
            num_encoder_attention_heads,
            past_key_values_length,
            self._config.hidden_size // num_encoder_attention_heads,
        )

        UpperCamelCase	:					Optional[Any]       	=   common_inputs["attention_mask"].dtype
        UpperCamelCase	:					int       	=   torch.cat(
            [common_inputs["attention_mask"], torch.ones(A_       ,							A_       ,							dtype=A_   )]       ,							dim=1   )
        UpperCamelCase	:					Optional[Any]       	=   [
            (torch.zeros(A_   ), torch.zeros(A_   )) for _ in range(A_   )
        ]
       return common_inputs





      def        __UpperCamelCase( self       ,							A_       ,							A_ = -1       ,							A_ = -1       ,							A_ = False       ,							A_ = None       ,							):
       '''simple docstring'''




       UpperCamelCase	:					Optional[Any]       	=   compute_effective_axis_dimension(
           A_       ,							fixed_dimension=OnnxConfig.default_fixed_batch       ,							num_token_to_add=0   )

       # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
       UpperCamelCase	:					Union[str, Any]       	=   tokenizer.num_special_tokens_to_add(A_   )
       UpperCamelCase	:					int       	=   compute_effective_axis_dimension(
           A_       ,							fixed_dimension=OnnxConfig.default_fixed_sequence       ,							num_token_to_add=A_   )

       # Generate dummy inputs according to compute batch and sequence
       UpperCamelCase	:					int       	=   [" ".join([tokenizer.unk_token]   ) * seq_length] * batch_size
       UpperCamelCase	:					Dict       	=   dict(tokenizer(A_       ,							return_tensors=A_   )   )
       return common_inputs





      def        __UpperCamelCase( self       ,							A_       ,							A_ = -1       ,							A_ = -1       ,							A_ = False       ,							A_ = None       ,							):
       '''simple docstring'''




       if self.task in ["default", "seq2seq-lm"]:
        UpperCamelCase	:					Optional[int]       	=   self._generate_dummy_inputs_for_default_and_seqaseq_lm(
            A_       ,							batch_size=A_       ,							seq_length=A_       ,							is_pair=A_       ,							framework=A_   )

       elif self.task == "causal-lm":
        UpperCamelCase	:					List[str]       	=   self._generate_dummy_inputs_for_causal_lm(
            A_       ,							batch_size=A_       ,							seq_length=A_       ,							is_pair=A_       ,							framework=A_   )
       else:
        UpperCamelCase	:					List[str]       	=   self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            A_       ,							batch_size=A_       ,							seq_length=A_       ,							is_pair=A_       ,							framework=A_   )

       return common_inputs





      def        __UpperCamelCase( self       ,							A_       ,							A_       ,							A_       ,							A_   ):
       '''simple docstring'''




       if self.task in ["default", "seq2seq-lm"]:
        UpperCamelCase	:					Optional[Any]       	=   super()._flatten_past_key_values_(A_       ,							A_       ,							A_       ,							A_   )
       else:
        UpperCamelCase	:					Optional[Any]       	=   super(A_       ,							self   )._flatten_past_key_values_(
            A_       ,							A_       ,							A_       ,							A_   )
