




"""simple docstring"""

import time
from dataclasses import dataclass
from multiprocessing import Pool
from unittest import TestCase
from unittest.mock import patch

import multiprocess
import numpy as np
import pytest

from datasets.utils.py_utils import (
    NestedDataStructure,
    asdict,
    iflatmap_unordered,
    map_nested,
    temp_seed,
    temporary_assignment,
    zip_dict,
)

from .utils import require_tf, require_torch






def 						_snake_case     (					_snake_case							:					str							)    ->					Dict:  # picklable for multiprocessing






      '''simple docstring'''


      return x.sum()






def 						_snake_case     (					_snake_case							:					int							)    ->					Any:  # picklable for multiprocessing






      '''simple docstring'''


      return i + 1





@dataclass
class 				lowercase_       :



 '''simple docstring'''
 UpperCAmelCase    :     int        =	42
 UpperCAmelCase    :     Tuple        =	42





class 				lowercase_       (     lowercase_							):



 '''simple docstring'''

 def 			lowerCAmelCase_							( self       :       Any		):
       _A					   =   {}
       _A					   =   []
       _A					   =   1
       _A					   =   [1, 2]
       _A					   =   {'a': 1, 'b': 2}
       _A					   =   {'a': [1, 2], 'b': [3, 4]}
       _A					   =   {'a': {'1': 1}, 'b': 2}
       _A					   =   {'a': 1, 'b': 2, 'c': 3, 'd': 4}
       _A					   =   {}
       _A					   =   []
       _A					   =   2
       _A					   =   [2, 3]
       _A					   =   {'a': 2, 'b': 3}
       _A					   =   {'a': [2, 3], 'b': [4, 5]}
       _A					   =   {'a': {'1': 2}, 'b': 3}
       _A					   =   {'a': 2, 'b': 3, 'c': 4, 'd': 5}
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase		)    ,							__UpperCamelCase		)

       _A					   =   2
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							num_proc=__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							num_proc=__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							num_proc=__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							num_proc=__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							num_proc=__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							num_proc=__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							num_proc=__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							num_proc=__UpperCamelCase		)    ,							__UpperCamelCase		)

       _A					   =   {'a': np.eye(2		), 'b': np.zeros(3		), 'c': np.ones(2		)}
       _A					   =   {'a': 2, 'b': 0, 'c': 2}
       _A					   =   {
           'a': np.eye(2		).astype(__UpperCamelCase		),
           'b': np.zeros(3		).astype(__UpperCamelCase		),
           'c': np.ones(2		).astype(__UpperCamelCase		),
       }
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							map_numpy=__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(
           {k: v.tolist() for k, v in map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							map_numpy=__UpperCamelCase		).items()}    ,							{k: v.tolist() for k, v in expected_map_nested_sna_int.items()}    ,							)
       self.assertEqual(map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							map_numpy=__UpperCamelCase    ,							num_proc=__UpperCamelCase		)    ,							__UpperCamelCase		)
       self.assertEqual(
           {k: v.tolist() for k, v in map_nested(__UpperCamelCase    ,							__UpperCamelCase    ,							map_numpy=__UpperCamelCase    ,							num_proc=__UpperCamelCase		).items()}    ,							{k: v.tolist() for k, v in expected_map_nested_sna_int.items()}    ,							)
       with self.assertRaises(__UpperCamelCase		):  # can't pickle a local lambda
             map_nested(lambda _UpperCAmelCase		: x + 1    ,							__UpperCamelCase    ,							num_proc=__UpperCamelCase		)

 def 			lowerCAmelCase_							( self       :       Dict		):
       _A					   =   {'a': 1, 'b': 2}
       _A					   =   {'a': 3, 'b': 4}
       _A					   =   {'a': 5, 'b': 6}
       _A					   =   sorted([('a', (1, 3, 5)), ('b', (2, 4, 6))]		)
       self.assertEqual(sorted(zip_dict(__UpperCamelCase    ,							__UpperCamelCase    ,							__UpperCamelCase		)		)    ,							__UpperCamelCase		)



 def 			lowerCAmelCase_							( self       :       List[Any]		):





       class 				lowercase_       :



        '''simple docstring'''
        UpperCAmelCase    :     List[Any]        =	'''bar'''



       _A					   =   Foo()
       self.assertEqual(foo.my_attr    ,							'bar'		)
       with temporary_assignment(__UpperCamelCase    ,							'my_attr'    ,							'BAR'		):
             self.assertEqual(foo.my_attr    ,							'BAR'		)
       self.assertEqual(foo.my_attr    ,							'bar'		)






@pytest.mark.parametrize(
    'iterable_length, num_proc, expected_num_proc'				,  [
        (1, None, 1),
        (1, 1, 1),
        (2, None, 1),
        (2, 1, 1),
        (2, 2, 1),
        (2, 3, 1),
        (3, 2, 1),
        (16, 16, 16),
        (16, 17, 16),
        (17, 16, 16),
    ]				,  )
def 						_snake_case     (					_snake_case							:					List[str]				,  _snake_case							:					Optional[int]				,  _snake_case							:					Any							)    ->					List[str]:






      '''simple docstring'''


      with patch('datasets.utils.py_utils._single_map_nested'							) as mock_single_map_nested, patch(
          'datasets.parallel.parallel.Pool'							) as mock_multiprocessing_pool:
            _A					   =   {F'''{i}''': i for i in range(_snake_case							)}
            _A					   =   map_nested(lambda _snake_case							: x + 10				,  _snake_case				,  num_proc=_snake_case				,  parallel_min_length=16							)
            if expected_num_proc == 1:
                  assert mock_single_map_nested.called
                  assert not mock_multiprocessing_pool.called
            else:
                  assert not mock_single_map_nested.called
                  assert mock_multiprocessing_pool.called
                  assert mock_multiprocessing_pool.call_args[0][0] == expected_num_proc





class 				lowercase_       (     lowercase_							):



 '''simple docstring'''

 @require_tf
 def 			lowerCAmelCase_							( self       :       str		):
       import tensorflow as tf
       from tensorflow.keras import layers

       _A					   =   layers.Dense(2		)

       def gen_random_output():
             _A					   =   tf.random.uniform((1, 3)		)
             return model(__UpperCamelCase		).numpy()

       with temp_seed(42    ,							set_tensorflow=__UpperCamelCase		):
             _A					   =   gen_random_output()
       with temp_seed(42    ,							set_tensorflow=__UpperCamelCase		):
             _A					   =   gen_random_output()
       _A					   =   gen_random_output()

       np.testing.assert_equal(__UpperCamelCase    ,							__UpperCamelCase		)
       self.assertGreater(np.abs(outa - outa		).sum()    ,							0		)

 @require_torch
 def 			lowerCAmelCase_							( self       :       Optional[int]		):
       import torch

       def gen_random_output():
             _A					   =   torch.nn.Linear(3    ,							2		)
             _A					   =   torch.rand(1    ,							3		)
             return model(__UpperCamelCase		).detach().numpy()

       with temp_seed(42    ,							set_pytorch=__UpperCamelCase		):
             _A					   =   gen_random_output()
       with temp_seed(42    ,							set_pytorch=__UpperCamelCase		):
             _A					   =   gen_random_output()
       _A					   =   gen_random_output()

       np.testing.assert_equal(__UpperCamelCase    ,							__UpperCamelCase		)
       self.assertGreater(np.abs(outa - outa		).sum()    ,							0		)



 def 			lowerCAmelCase_							( self       :       Tuple		):
       def gen_random_output():
             return np.random.rand(1    ,							3		)

       with temp_seed(42		):
             _A					   =   gen_random_output()
       with temp_seed(42		):
             _A					   =   gen_random_output()
       _A					   =   gen_random_output()

       np.testing.assert_equal(__UpperCamelCase    ,							__UpperCamelCase		)
       self.assertGreater(np.abs(outa - outa		).sum()    ,							0		)






@pytest.mark.parametrize('input_data'				,  [{}]							)
def 						_snake_case     (					_snake_case							:					Optional[int]							)    ->					Any:






      '''simple docstring'''


      _A					   =   NestedDataStructure(_snake_case							).data
      assert output_data == input_data






@pytest.mark.parametrize(
    'data, expected_output'				,  [
        ({}, []),
        ([], []),
        ('foo', ['foo']),
        (['foo', 'bar'], ['foo', 'bar']),
        ([['foo', 'bar']], ['foo', 'bar']),
        ([[['foo'], ['bar']]], ['foo', 'bar']),
        ([[['foo'], 'bar']], ['foo', 'bar']),
        ({'a': 1, 'b': 2}, [1, 2]),
        ({'a': [1, 2], 'b': [3, 4]}, [1, 2, 3, 4]),
        ({'a': [[1, 2]], 'b': [[3, 4]]}, [1, 2, 3, 4]),
        ({'a': [[1, 2]], 'b': [3, 4]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [[[3], [4]]]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [[3, 4]]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [3, 4]}, [1, 2, 3, 4]),
        ({'a': [[[1], [2]]], 'b': [3, [4]]}, [1, 2, 3, 4]),
        ({'a': {'1': 1}, 'b': 2}, [1, 2]),
        ({'a': {'1': [1]}, 'b': 2}, [1, 2]),
        ({'a': {'1': [1]}, 'b': [2]}, [1, 2]),
    ]				,  )
def 						_snake_case     (					_snake_case							:					int				,  _snake_case							:					int							)    ->					str:






      '''simple docstring'''


      _A					   =   NestedDataStructure(_snake_case							).flatten()
      assert output == expected_output






def 						_snake_case     (					)    ->					Optional[Any]:






      '''simple docstring'''


      _A					   =   A(x=1				,  y='foobar'							)
      _A					   =   {'x': 1, 'y': 'foobar'}
      assert asdict(_snake_case							) == expected_output

      _A					   =   {'a': {'b': A(x=10				,  y='foo'							)}, 'c': [A(x=20				,  y='bar'							)]}
      _A					   =   {'a': {'b': {'x': 10, 'y': 'foo'}}, 'c': [{'x': 20, 'y': 'bar'}]}
      assert asdict(_snake_case							) == expected_output

      with pytest.raises(_snake_case							):
            asdict([1, A(x=10				,  y='foo'							)]							)






def 						_snake_case     (					_snake_case							:					Optional[int]							)    ->					Optional[int]:






      '''simple docstring'''


      return text.split()






def 						_snake_case     (					_snake_case							:					List[Any]							)    ->					Optional[Any]:






      '''simple docstring'''


      yield (time.time(), content)
      time.sleep(2							)
      yield (time.time(), content)







def 						_snake_case     (					)    ->					Optional[Any]:






      '''simple docstring'''


      with Pool(2							) as pool:
            _A					   =   list(iflatmap_unordered(_snake_case				,  _split_text				,  kwargs_iterable=[{'text': 'hello there'}] * 10							)							)
            assert out.count('hello'							) == 10
            assert out.count('there'							) == 10
            assert len(_snake_case							) == 20

      # check multiprocess from pathos (uses dill for pickling)
      with multiprocess.Pool(2							) as pool:
            _A					   =   list(iflatmap_unordered(_snake_case				,  _split_text				,  kwargs_iterable=[{'text': 'hello there'}] * 10							)							)
            assert out.count('hello'							) == 10
            assert out.count('there'							) == 10
            assert len(_snake_case							) == 20

      # check that we get items as fast as possible
      with Pool(2							) as pool:
            _A					   =   []
            for yield_time, content in iflatmap_unordered(
                _snake_case				,  _aseconds_generator_of_aitems_with_timing				,  kwargs_iterable=[{'content': 'a'}, {'content': 'b'}]							):
                  assert yield_time < time.time() + 0.1, "we should each item directly after it was yielded"
                  out.append(_snake_case							)
            assert out.count('a'							) == 2
            assert out.count('b'							) == 2
            assert len(_snake_case							) == 4








"""simple docstring"""
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


_snake_case     :		List[Any]       						= logging.get_logger(__name__)

_snake_case     :		int       						= {
    'Helsinki-NLP/opus-mt-en-de': 'https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/config.json',
    # See all Marian models at https://huggingface.co/models?filter=marian
}






class 					_UpperCAmelCase   (	lowercase_ ):
					UpperCamelCase      =							'''marian'''
					UpperCamelCase      =							['''past_key_values''']
					UpperCamelCase      =							{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}


					def __init__(					self			:int     ,       __UpperCamelCase			:Any=5_81_01     ,       __UpperCamelCase			:int=None     ,       __UpperCamelCase			:Union[str, Any]=10_24     ,       __UpperCamelCase			:Union[str, Any]=12     ,       __UpperCamelCase			:str=40_96     ,       __UpperCamelCase			:int=16     ,       __UpperCamelCase			:int=12     ,       __UpperCamelCase			:Optional[Any]=40_96     ,       __UpperCamelCase			:Optional[Any]=16     ,       __UpperCamelCase			:Dict=0.0     ,       __UpperCamelCase			:Dict=0.0     ,       __UpperCamelCase			:str=True     ,       __UpperCamelCase			:Optional[int]=True     ,       __UpperCamelCase			:Any="gelu"     ,       __UpperCamelCase			:Any=10_24     ,       __UpperCamelCase			:List[Any]=0.1     ,       __UpperCamelCase			:Optional[Any]=0.0     ,       __UpperCamelCase			:Union[str, Any]=0.0     ,       __UpperCamelCase			:Tuple=0.02     ,       __UpperCamelCase			:List[str]=5_81_00     ,       __UpperCamelCase			:str=False     ,       __UpperCamelCase			:Optional[int]=5_81_00     ,       __UpperCamelCase			:List[Any]=0     ,       __UpperCamelCase			:List[str]=0     ,       __UpperCamelCase			:Dict=True     ,       **__UpperCamelCase			:Tuple     ,       ):
												A		=  vocab_size
												A		=  decoder_vocab_size or vocab_size
												A		=  max_position_embeddings
												A		=  d_model
												A		=  encoder_ffn_dim
												A		=  encoder_layers
												A		=  encoder_attention_heads
												A		=  decoder_ffn_dim
												A		=  decoder_layers
												A		=  decoder_attention_heads
												A		=  dropout
												A		=  attention_dropout
												A		=  activation_dropout
												A		=  activation_function
												A		=  init_std
												A		=  encoder_layerdrop
												A		=  decoder_layerdrop
												A		=  use_cache
												A		=  encoder_layers
												A		=  scale_embedding  # scale factor will be sqrt(d_model) if True
												A		=  share_encoder_decoder_embeddings
												super().__init__(
												    pad_token_id=__UpperCamelCase     ,       eos_token_id=__UpperCamelCase     ,       is_encoder_decoder=__UpperCamelCase     ,       decoder_start_token_id=__UpperCamelCase     ,       forced_eos_token_id=__UpperCamelCase     ,       **__UpperCamelCase     ,       )







class 					_UpperCAmelCase   (	lowercase_ ):


					@property
					# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
					def 	lowerCamelCase       (					self			:List[str]		):
												if self.task in ["default", "seq2seq-lm"]:
																			A		=  OrderedDict(
																			    [
																			        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
																			        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
																			    ]		)

																			if self.use_past:
																										A		=  {0: "batch"}
																										A		=  {0: "batch", 1: "past_decoder_sequence + sequence"}
																			else:
																										A		=  {0: "batch", 1: "decoder_sequence"}
																										A		=  {0: "batch", 1: "decoder_sequence"}

																			if self.use_past:
																										self.fill_with_past_key_values_(__UpperCamelCase     ,       direction="inputs"		)
												elif self.task == "causal-lm":
																			# TODO: figure this case out.
																			A		=  OrderedDict(
																			    [
																			        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
																			        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
																			    ]		)
																			if self.use_past:
																										A,	A		=  self.num_layers
																										for i in range(__UpperCamelCase		):
																																	A		=  {0: "batch", 2: "past_sequence + sequence"}
																																	A		=  {0: "batch", 2: "past_sequence + sequence"}
												else:
																			A		=  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
					# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
					def 	lowerCamelCase       (					self			:List[str]		):
												if self.task in ["default", "seq2seq-lm"]:
																			A		=  super().outputs
												else:
																			A		=  super(__UpperCamelCase     ,       self		).outputs
																			if self.use_past:
																										A,	A		=  self.num_layers
																										for i in range(__UpperCamelCase		):
																																	A		=  {0: "batch", 2: "past_sequence + sequence"}
																																	A		=  {0: "batch", 2: "past_sequence + sequence"}
												return common_outputs


					def 	lowerCamelCase       (					self			:Optional[int]     ,       __UpperCamelCase			:PreTrainedTokenizer     ,       __UpperCamelCase			:int = -1     ,       __UpperCamelCase			:int = -1     ,       __UpperCamelCase			:bool = False     ,       __UpperCamelCase			:Optional[TensorType] = None     ,       ):
												A		=  self._generate_dummy_inputs_for_encoder_and_decoder(
												    __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase		)

												# Generate decoder inputs
												A		=  seq_length if not self.use_past else 1
												A		=  self._generate_dummy_inputs_for_encoder_and_decoder(
												    __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase		)
												A		=  {f"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
												A		=  dict(**__UpperCamelCase     ,       **__UpperCamelCase		)

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

																			A		=  torch.cat(
																			    [common_inputs["decoder_attention_mask"], torch.ones(__UpperCamelCase     ,       __UpperCamelCase		)]     ,       dim=1		)

																			A		=  []
																			# If the number of encoder and decoder layers are present in the model configuration, both are considered
																			A,	A		=  self.num_layers
																			A		=  min(__UpperCamelCase     ,       __UpperCamelCase		)
																			A		=  max(__UpperCamelCase     ,       __UpperCamelCase		) - min_num_layers
																			A		=  "encoder" if num_encoder_layers > num_decoder_layers else "decoder"

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


					def 	lowerCamelCase       (					self			:Optional[int]     ,       __UpperCamelCase			:PreTrainedTokenizer     ,       __UpperCamelCase			:int = -1     ,       __UpperCamelCase			:int = -1     ,       __UpperCamelCase			:bool = False     ,       __UpperCamelCase			:Optional[TensorType] = None     ,       ):
												A		=  self._generate_dummy_inputs_for_encoder_and_decoder(
												    __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase		)

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

																			A		=  common_inputs["attention_mask"].dtype
																			A		=  torch.cat(
																			    [common_inputs["attention_mask"], torch.ones(__UpperCamelCase     ,       __UpperCamelCase     ,       dtype=__UpperCamelCase		)]     ,       dim=1		)
																			A		=  [
																			    (torch.zeros(__UpperCamelCase		), torch.zeros(__UpperCamelCase		)) for _ in range(__UpperCamelCase		)
																			]
												return common_inputs


					def 	lowerCamelCase       (					self			:Tuple     ,       __UpperCamelCase			:PreTrainedTokenizer     ,       __UpperCamelCase			:int = -1     ,       __UpperCamelCase			:int = -1     ,       __UpperCamelCase			:bool = False     ,       __UpperCamelCase			:Optional[TensorType] = None     ,       ):
												# Copied from OnnxConfig.generate_dummy_inputs
												# Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
												# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
												A		=  compute_effective_axis_dimension(
												    __UpperCamelCase     ,       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
												A		=  tokenizer.num_special_tokens_to_add(__UpperCamelCase		)
												A		=  compute_effective_axis_dimension(
												    __UpperCamelCase     ,       fixed_dimension=OnnxConfig.default_fixed_sequence     ,       num_token_to_add=__UpperCamelCase		)

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


					def 	lowerCamelCase       (					self			:List[Any]     ,       __UpperCamelCase			:PreTrainedTokenizer     ,       __UpperCamelCase			:int = -1     ,       __UpperCamelCase			:int = -1     ,       __UpperCamelCase			:bool = False     ,       __UpperCamelCase			:Optional[TensorType] = None     ,       ):
												if self.task in ["default", "seq2seq-lm"]:
																			A		=  self._generate_dummy_inputs_for_default_and_seqaseq_lm(
																			    __UpperCamelCase     ,       batch_size=__UpperCamelCase     ,       seq_length=__UpperCamelCase     ,       is_pair=__UpperCamelCase     ,       framework=__UpperCamelCase		)

												else:
																			A		=  self._generate_dummy_inputs_for_causal_lm(
																			    __UpperCamelCase     ,       batch_size=__UpperCamelCase     ,       seq_length=__UpperCamelCase     ,       is_pair=__UpperCamelCase     ,       framework=__UpperCamelCase		)

												return common_inputs


					def 	lowerCamelCase       (					self			:List[Any]     ,       __UpperCamelCase			:Tuple     ,       __UpperCamelCase			:List[str]     ,       __UpperCamelCase			:str     ,       __UpperCamelCase			:str		):
												if self.task in ["default", "seq2seq-lm"]:
																			A		=  super()._flatten_past_key_values_(__UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase		)
												else:
																			A		=  super(__UpperCamelCase     ,       self		)._flatten_past_key_values_(
																			    __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase     ,       __UpperCamelCase		)


					@property
					def 	lowerCamelCase       (					self			:List[str]		):
												return 1e-4


