





import json
import os
import pickle
import subprocess
from hashlib import mda
from pathlib import Path
from tempfile import gettempdir
from textwrap import dedent
from types import CodeType, FunctionType
from unittest import TestCase
from unittest.mock import patch

import pytest
from multiprocess import Pool
from packaging import version

import datasets
from datasets.fingerprint import Hasher, fingerprint_transform
from datasets.table import InMemoryTable

from .utils import (
    require_regex,
    require_spacy,
    require_spacy_model,
    require_tiktoken,
    require_torch,
    require_transformers,
)

class   __snake_case				:






    '''simple docstring'''





    def __init__(   self						:		Optional[int]			,						snake_case						:		Union[str, Any]							):

      """simple docstring"""





      __lowerCAmelCase			=				foo





    def __call__(   self						:		Dict							):

      """simple docstring"""





      return self.foo


class   __snake_case				(			datasets.Dataset   ):






    '''simple docstring'''





    @fingerprint_transform(inplace=snake_case							)
    def 	A		(   self						:		Any			,						snake_case						:		Optional[int]			,						*snake_case						:		int			,						**snake_case						:		Optional[int]							):

      """simple docstring"""





      return DatasetChild(self.data			,						fingerprint=snake_case							)





    @fingerprint_transform(inplace=snake_case							)
    def 	A		(   self						:		Any			,						snake_case						:		Union[str, Any]			,						*snake_case						:		str			,						**snake_case						:		int							):

      """simple docstring"""





      return DatasetChild(self.data			,						fingerprint=snake_case							)


class   __snake_case				:






    '''simple docstring'''





    def __init__(   self						:		Any			,						snake_case						:		List[str]							):

      """simple docstring"""





      __lowerCAmelCase			=				callable





    def __call__(   self						:		Tuple			,						*snake_case						:		Union[str, Any]			,						**snake_case						:		List[str]							):

      """simple docstring"""





      if self.callable is not None:
        return self.callable(*snake_case			,						**snake_case							)





    def __getstate__(   self						:		Optional[int]							):

      """simple docstring"""





      raise pickle.PicklingError()


class   __snake_case				(			_a   ):






    '''simple docstring'''





    @require_transformers
    @pytest.mark.integration
    def 	A		(   self						:		Union[str, Any]							):

      """simple docstring"""





      from transformers import AutoTokenizer

      def encode(snake_case						:		Tuple							):
        return tokenizer(snake_case							)

      # TODO: add hash consistency tests across sessions
      __lowerCAmelCase			=				AutoTokenizer.from_pretrained('''bert-base-uncased'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(lambda snake_case							: tokenizer(snake_case							)							)							).hexdigest()
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				AutoTokenizer.from_pretrained('''bert-base-cased'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(lambda snake_case							: tokenizer(snake_case							)							)							).hexdigest()
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				AutoTokenizer.from_pretrained('''bert-base-uncased'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(lambda snake_case							: tokenizer(snake_case							)							)							).hexdigest()
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)





    @require_transformers
    @pytest.mark.integration
    def 	A		(   self						:		Any							):

      """simple docstring"""





      from transformers import AutoTokenizer

      __lowerCAmelCase			=				AutoTokenizer.from_pretrained('''gpt2'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      tokenizer('''Hello world !'''							)  # call once to change the tokenizer's cache
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)





    @require_regex
    def 	A		(   self						:		Tuple							):

      """simple docstring"""





      import regex

      __lowerCAmelCase			=				regex.Regex('''foo'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				regex.Regex('''bar'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				regex.Regex('''foo'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)


class   __snake_case				(			_a   ):






    '''simple docstring'''





    def 	A		(   self						:		Any							):

      """simple docstring"""





      def func():
        return foo

      __lowerCAmelCase			=				[0]
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				[1]
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				[0]
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)





    def 	A		(   self						:		Optional[Any]							):

      """simple docstring"""





      def func():
        pass

      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()

      def func():
        pass

      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)





    def 	A		(   self						:		int							):

      """simple docstring"""





      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(Foo([0]							)							)							).hexdigest()
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(Foo([1]							)							)							).hexdigest()
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(Foo([0]							)							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)





    def 	A		(   self						:		List[str]							):

      """simple docstring"""





      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(Foo([0]							).__call__							)							).hexdigest()
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(Foo([1]							).__call__							)							).hexdigest()
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(Foo([0]							).__call__							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)





    def 	A		(   self						:		Tuple							):

      """simple docstring"""





      __lowerCAmelCase			=				(
          '''co_argcount''',
          '''co_kwonlyargcount''',
          '''co_nlocals''',
          '''co_stacksize''',
          '''co_flags''',
          '''co_code''',
          '''co_consts''',
          '''co_names''',
          '''co_varnames''',
          '''co_filename''',
          '''co_name''',
          '''co_firstlineno''',
          '''co_lnotab''',
          '''co_freevars''',
          '''co_cellvars''',
      )

      def _create_code_pyaa(*snake_case						:		Optional[Any]							):
        if hasattr(args[-3]			,						'''encode'''							):
          __lowerCAmelCase			=				list(snake_case							)
          __lowerCAmelCase			=				args[-3].encode()  # co_lnotab
          __lowerCAmelCase			=				args[-10].encode()  # co_code
        if hasattr(snake_case			,						'''co_posonlyargcount'''							):
          if len(snake_case							) == 16:
            return CodeType(*snake_case							)
          elif len(snake_case							) == 15:
            return CodeType(args[0]			,						0			,						*args[1:]							)
          return CodeType(args[0]			,						0			,						0			,						*args[1:]							)
        elif hasattr(snake_case			,						'''co_kwonlyargcount'''							):
          if len(snake_case							) == 16:
            return CodeType(args[0]			,						*args[2:]							)
          elif len(snake_case							) == 15:
            return CodeType(*snake_case							)
          return CodeType(args[0]			,						0			,						*args[1:]							)
        if len(snake_case							) == 16:
          return CodeType(args[0]			,						*args[3:]							)
        elif len(snake_case							) == 15:
          return CodeType(args[0]			,						*args[2:]							)
        return CodeType(*snake_case							)

      def create_ipython_func(snake_case						:		int			,						snake_case						:		Tuple							):
        def func():
          return returned_obj

        __lowerCAmelCase			=				func.__code__
        # Use _create_code from dill in order to make it work for different python versions
        if datasets.config.PY_VERSION < version.parse('''3.8'''							):
          __lowerCAmelCase			=				_create_code_pyaa(
              *[getattr(snake_case			,						snake_case							) if k != '''co_filename''' else co_filename for k in code_args_pyaa]							)
        else:
          __lowerCAmelCase			=				code.replace(co_filename=snake_case							)
        return FunctionType(snake_case			,						func.__globals__			,						func.__name__			,						func.__defaults__			,						func.__closure__							)

      __lowerCAmelCase	,						__lowerCAmelCase			=				'''<ipython-input-2-e0383a102aae>''', [0]
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(create_ipython_func(snake_case			,						snake_case							)							)							).hexdigest()
      __lowerCAmelCase	,						__lowerCAmelCase			=				'''<ipython-input-2-e0383a102aae>''', [1]
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(create_ipython_func(snake_case			,						snake_case							)							)							).hexdigest()
      __lowerCAmelCase	,						__lowerCAmelCase			=				'''<ipython-input-5-713f6613acf3>''', [0]
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(create_ipython_func(snake_case			,						snake_case							)							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)

      __lowerCAmelCase	,						__lowerCAmelCase			=				os.path.join(gettempdir()			,						'''ipykernel_12345'''			,						'''321456789.py'''							), [0]
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(create_ipython_func(snake_case			,						snake_case							)							)							).hexdigest()
      __lowerCAmelCase	,						__lowerCAmelCase			=				os.path.join(gettempdir()			,						'''ipykernel_12345'''			,						'''321456789.py'''							), [1]
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(create_ipython_func(snake_case			,						snake_case							)							)							).hexdigest()
      __lowerCAmelCase	,						__lowerCAmelCase			=				os.path.join(gettempdir()			,						'''ipykernel_12345'''			,						'''654123987.py'''							), [0]
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(create_ipython_func(snake_case			,						snake_case							)							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)





    def 	A		(   self						:		int							):

      """simple docstring"""





      __lowerCAmelCase	,						__lowerCAmelCase			=				[0], [1]

      def func():
        return foo, bar

      __lowerCAmelCase			=				'''__main__'''

      def globalvars_mocka_side_effect(snake_case						:		Any			,						*snake_case						:		Union[str, Any]			,						**snake_case						:		Dict							):
        return {"foo": foo, "bar": bar}

      def globalvars_mocka_side_effect(snake_case						:		str			,						*snake_case						:		str			,						**snake_case						:		Union[str, Any]							):
        return {"bar": bar, "foo": foo}

      with patch('''dill.detect.globalvars'''			,						side_effect=snake_case							) as globalvars_mocka:
        __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
        self.assertGreater(globalvars_mocka.call_count			,						0							)
      with patch('''dill.detect.globalvars'''			,						side_effect=snake_case							) as globalvars_mocka:
        __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
        self.assertGreater(globalvars_mocka.call_count			,						0							)
      self.assertEqual(snake_case			,						snake_case							)


class   __snake_case				(			_a   ):






    '''simple docstring'''





    def 	A		(   self						:		List[str]							):

      """simple docstring"""





      __lowerCAmelCase			=				Hasher.hash('''hello'''							)
      __lowerCAmelCase			=				Hasher.hash('''hello'''							)
      __lowerCAmelCase			=				Hasher.hash('''there'''							)
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)





    def 	A		(   self						:		List[str]							):

      """simple docstring"""





      __lowerCAmelCase			=				Hasher.hash(Foo('''hello'''							)							)
      __lowerCAmelCase			=				Hasher.hash(Foo('''hello'''							)							)
      __lowerCAmelCase			=				Hasher.hash(Foo('''there'''							)							)
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)





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

      """simple docstring"""





      __lowerCAmelCase			=				Hasher()
      for x in ["hello", Foo('''hello'''							)]:
        hasher.update(snake_case							)
      __lowerCAmelCase			=				hasher.hexdigest()
      __lowerCAmelCase			=				Hasher()
      for x in ["hello", Foo('''hello'''							)]:
        hasher.update(snake_case							)
      __lowerCAmelCase			=				hasher.hexdigest()
      __lowerCAmelCase			=				Hasher()
      for x in ["there", Foo('''there'''							)]:
        hasher.update(snake_case							)
      __lowerCAmelCase			=				hasher.hexdigest()
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)





    def 	A		(   self						:		int							):

      """simple docstring"""





      with self.assertRaises(pickle.PicklingError							):
        Hasher.hash(UnpicklableCallable(Foo('''hello'''							)							)							)





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

      """simple docstring"""





      __lowerCAmelCase			=				'''abc'''
      __lowerCAmelCase			=				[string, string]  # two strings have the same ids
      __lowerCAmelCase			=				[string, string]
      __lowerCAmelCase			=				json.loads(f'''["{string}", "{string}"]'''							)  # two strings have different ids
      self.assertIs(obja[0]			,						snake_case							)
      self.assertIs(obja[0]			,						obja[1]							)
      self.assertIs(obja[0]			,						snake_case							)
      self.assertIs(obja[0]			,						obja[1]							)
      self.assertIsNot(obja[0]			,						snake_case							)
      self.assertIsNot(obja[0]			,						obja[1]							)
      __lowerCAmelCase			=				Hasher.hash(snake_case							)
      __lowerCAmelCase			=				Hasher.hash(snake_case							)
      __lowerCAmelCase			=				Hasher.hash(snake_case							)
      self.assertEqual(snake_case			,						snake_case							)
      self.assertEqual(snake_case			,						snake_case							)





    @require_tiktoken
    def 	A		(   self						:		Union[str, Any]							):

      """simple docstring"""





      import tiktoken

      __lowerCAmelCase			=				tiktoken.get_encoding('''gpt2'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				tiktoken.get_encoding('''r50k_base'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				tiktoken.get_encoding('''gpt2'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)





    @require_torch
    def 	A		(   self						:		Union[str, Any]							):

      """simple docstring"""





      import torch

      __lowerCAmelCase			=				torch.tensor([1.0]							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				torch.tensor([2.0]							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				torch.tensor([1.0]							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)





    @require_spacy
    @require_spacy_model('''en_core_web_sm'''							)
    @require_spacy_model('''fr_core_news_sm'''							)
    @pytest.mark.integration
    def 	A		(   self						:		List[Any]							):

      """simple docstring"""





      import spacy

      __lowerCAmelCase			=				spacy.load('''en_core_web_sm'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				spacy.load('''fr_core_news_sm'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      __lowerCAmelCase			=				spacy.load('''en_core_web_sm'''							)
      __lowerCAmelCase			=				mda(datasets.utils.py_utils.dumps(snake_case							)							).hexdigest()
      self.assertEqual(snake_case			,						snake_case							)
      self.assertNotEqual(snake_case			,						snake_case							)


@pytest.mark.integration
def 					__SCREAMING_SNAKE_CASE  (							__lowercase:		Path):



  '''simple docstring'''






  __lowerCAmelCase			=				tmp_path / '''dir1'''
  __lowerCAmelCase			=				tmp_path / '''dir2'''
  dira.mkdir()
  dira.mkdir()
  __lowerCAmelCase			=				'''script.py'''
  __lowerCAmelCase			=				dedent(
      '''
    from datasets.fingerprint import Hasher
    def foo():
        pass
    print(Hasher.hash(foo))
    ''')
  __lowerCAmelCase			=				dira / script_filename
  __lowerCAmelCase			=				dira / script_filename
  with script_patha.open('''w''') as f:
    f.write(__lowercase)
  with script_patha.open('''w''') as f:
    f.write(__lowercase)
  __lowerCAmelCase			=				subprocess.check_output(['''python''', str(__lowercase)])
  __lowerCAmelCase			=				subprocess.check_output(['''python''', str(__lowercase)])
  assert fingerprinta == fingerprinta


def 					__SCREAMING_SNAKE_CASE  (							):



  '''simple docstring'''






  __lowerCAmelCase			=				{'''a''': [0, 1, 2]}
  __lowerCAmelCase			=				DatasetChild(InMemoryTable.from_pydict(__lowercase))
  __lowerCAmelCase			=				dataset.funca()._fingerprint
  assert expected_fingerprint == dataset.funca()._fingerprint
  assert expected_fingerprint != dataset.funca()._fingerprint

  with Pool(2) as p:
    assert expected_fingerprint == p.apply_async(dataset.funca).get()._fingerprint
    assert expected_fingerprint != p.apply_async(dataset.funca).get()._fingerprint


def 					__SCREAMING_SNAKE_CASE  (							):



  '''simple docstring'''






  __lowerCAmelCase			=				{'''a''': [0, 1, 2]}

  class   __snake_case				(			datasets.Dataset   ):






      '''simple docstring'''





      @fingerprint_transform(inplace=snake_case							)
      def 	A		(   self						:		Any			,						snake_case						:		Dict							):

        """simple docstring"""





        return DummyDatasetChild(self.data			,						fingerprint=snake_case							)


  __lowerCAmelCase			=				DummyDatasetChild(InMemoryTable.from_pydict(__lowercase)).func()

  class   __snake_case				(			datasets.Dataset   ):






      '''simple docstring'''





      @fingerprint_transform(inplace=snake_case			,						version='''1.0.0'''							)
      def 	A		(   self						:		Any			,						snake_case						:		Dict							):

        """simple docstring"""





        return DummyDatasetChild(self.data			,						fingerprint=snake_case							)


  __lowerCAmelCase			=				DummyDatasetChild(InMemoryTable.from_pydict(__lowercase)).func()

  class   __snake_case				(			datasets.Dataset   ):






      '''simple docstring'''





      @fingerprint_transform(inplace=snake_case			,						version='''2.0.0'''							)
      def 	A		(   self						:		Union[str, Any]			,						snake_case						:		Tuple							):

        """simple docstring"""





        return DummyDatasetChild(self.data			,						fingerprint=snake_case							)


  __lowerCAmelCase			=				DummyDatasetChild(InMemoryTable.from_pydict(__lowercase)).func()

  assert len({fingeprint_no_version, fingeprint_a, fingeprint_a}) == 3




def 					__SCREAMING_SNAKE_CASE  (							):



  '''simple docstring'''






  __lowerCAmelCase			=				Hasher()
  hasher.update(lambda __lowercase: x)







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

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


__lowercase													=			logging.get_logger(__name__)

__lowercase													=			{
    """facebook/blenderbot-3B""": """https://huggingface.co/facebook/blenderbot-3B/resolve/main/config.json""",
    # See all Blenderbot models at https://huggingface.co/models?filter=blenderbot
}

class   __snake_case				(			_a   ):






    '''simple docstring'''
    _lowerCAmelCase     =	"""blenderbot"""
    _lowerCAmelCase     =	["""past_key_values"""]
    _lowerCAmelCase     =	{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}





    def __init__(   self						:		Any			,						snake_case						:		Union[str, Any]=8_008			,						snake_case						:		List[str]=128			,						snake_case						:		Tuple=2			,						snake_case						:		int=10_240			,						snake_case						:		Optional[int]=32			,						snake_case						:		Dict=24			,						snake_case						:		List[Any]=10_240			,						snake_case						:		Optional[int]=32			,						snake_case						:		List[str]=0.0			,						snake_case						:		Optional[int]=0.0			,						snake_case						:		Optional[Any]=True			,						snake_case						:		int=True			,						snake_case						:		List[str]="gelu"			,						snake_case						:		Any=2_560			,						snake_case						:		Optional[Any]=0.1			,						snake_case						:		Union[str, Any]=0.0			,						snake_case						:		List[Any]=0.0			,						snake_case						:		Dict=0.02			,						snake_case						:		int=1			,						snake_case						:		Dict=False			,						snake_case						:		List[str]=0			,						snake_case						:		Optional[Any]=1			,						snake_case						:		List[Any]=2			,						snake_case						:		List[str]=3			,						snake_case						:		List[str]=2			,						**snake_case						:		int			,						):

      """simple docstring"""





      __lowerCAmelCase			=				vocab_size
      __lowerCAmelCase			=				max_position_embeddings
      __lowerCAmelCase			=				d_model
      __lowerCAmelCase			=				encoder_ffn_dim
      __lowerCAmelCase			=				encoder_layers
      __lowerCAmelCase			=				encoder_attention_heads
      __lowerCAmelCase			=				decoder_ffn_dim
      __lowerCAmelCase			=				decoder_layers
      __lowerCAmelCase			=				decoder_attention_heads
      __lowerCAmelCase			=				dropout
      __lowerCAmelCase			=				attention_dropout
      __lowerCAmelCase			=				activation_dropout
      __lowerCAmelCase			=				activation_function
      __lowerCAmelCase			=				init_std
      __lowerCAmelCase			=				encoder_layerdrop
      __lowerCAmelCase			=				decoder_layerdrop
      __lowerCAmelCase			=				use_cache
      __lowerCAmelCase			=				encoder_layers
      __lowerCAmelCase			=				scale_embedding  # scale factor will be sqrt(d_model) if True

      super().__init__(
          pad_token_id=snake_case			,						bos_token_id=snake_case			,						eos_token_id=snake_case			,						is_encoder_decoder=snake_case			,						decoder_start_token_id=snake_case			,						encoder_no_repeat_ngram_size=snake_case			,						forced_eos_token_id=snake_case			,						**snake_case			,						)


class   __snake_case				(			_a   ):






    '''simple docstring'''





    @property
    def 	A		(   self						:		int							):

      """simple docstring"""





      if self.task in ["default", "seq2seq-lm"]:
        __lowerCAmelCase			=				OrderedDict(
            [
                ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
            ]							)
        if self.use_past:
          __lowerCAmelCase			=				{0: '''batch'''}
          __lowerCAmelCase			=				{0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
        else:
          __lowerCAmelCase			=				{0: '''batch''', 1: '''decoder_sequence'''}
          __lowerCAmelCase			=				{0: '''batch''', 1: '''decoder_sequence'''}
        if self.use_past:
          self.fill_with_past_key_values_(snake_case			,						direction='''inputs'''							)
      elif self.task == "causal-lm":
        __lowerCAmelCase			=				OrderedDict(
            [
                ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
            ]							)
        if self.use_past:
          __lowerCAmelCase	,						__lowerCAmelCase			=				self.num_layers
          for i in range(snake_case							):
            __lowerCAmelCase			=				{0: '''batch''', 2: '''past_sequence + sequence'''}
            __lowerCAmelCase			=				{0: '''batch''', 2: '''past_sequence + sequence'''}
      else:
        __lowerCAmelCase			=				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 	A		(   self						:		Optional[Any]							):

      """simple docstring"""





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





    def 	A		(   self						:		int			,						snake_case						:		PreTrainedTokenizer			,						snake_case						:		int = -1			,						snake_case						:		int = -1			,						snake_case						:		bool = False			,						snake_case						:		Optional[TensorType] = None			,						):

      """simple docstring"""





      __lowerCAmelCase			=				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          snake_case			,						snake_case			,						snake_case			,						snake_case			,						snake_case							)
      # Generate decoder inputs
      __lowerCAmelCase			=				seq_length if not self.use_past else 1
      __lowerCAmelCase			=				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          snake_case			,						snake_case			,						snake_case			,						snake_case			,						snake_case							)
      __lowerCAmelCase			=				{f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
      __lowerCAmelCase			=				dict(**snake_case			,						**snake_case							)

      if self.use_past:
        if not is_torch_available():
          raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''							)
        else:
          import torch
        __lowerCAmelCase	,						__lowerCAmelCase			=				common_inputs['''input_ids'''].shape
        __lowerCAmelCase			=				common_inputs['''decoder_input_ids'''].shape[1]
        __lowerCAmelCase	,						__lowerCAmelCase			=				self.num_attention_heads
        __lowerCAmelCase			=				(
            batch,
            num_encoder_attention_heads,
            encoder_seq_length,
            self._config.hidden_size // num_encoder_attention_heads,
        )
        __lowerCAmelCase			=				decoder_seq_length
        __lowerCAmelCase			=				(
            batch,
            num_decoder_attention_heads,
            decoder_past_length,
            self._config.hidden_size // num_decoder_attention_heads,
        )
        __lowerCAmelCase			=				torch.cat(
            [common_inputs['''decoder_attention_mask'''], torch.ones(snake_case			,						snake_case							)]			,						dim=1							)
        __lowerCAmelCase			=				[]
        __lowerCAmelCase	,						__lowerCAmelCase			=				self.num_layers

        for _ in range(snake_case							):
          common_inputs["past_key_values"].append(
              (
                  torch.zeros(snake_case							),
                  torch.zeros(snake_case							),
                  torch.zeros(snake_case							),
                  torch.zeros(snake_case							),
              )							)
      return common_inputs





    def 	A		(   self						:		str			,						snake_case						:		PreTrainedTokenizer			,						snake_case						:		int = -1			,						snake_case						:		int = -1			,						snake_case						:		bool = False			,						snake_case						:		Optional[TensorType] = None			,						):

      """simple docstring"""





      __lowerCAmelCase			=				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          snake_case			,						snake_case			,						snake_case			,						snake_case			,						snake_case							)

      if self.use_past:
        if not is_torch_available():
          raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''							)
        else:
          import torch
        __lowerCAmelCase	,						__lowerCAmelCase			=				common_inputs['''input_ids'''].shape
        __lowerCAmelCase			=				seqlen
        __lowerCAmelCase	,						__lowerCAmelCase			=				self.num_layers
        __lowerCAmelCase	,						__lowerCAmelCase			=				self.num_attention_heads
        __lowerCAmelCase			=				(
            batch,
            num_encoder_attention_heads,
            past_key_values_length,
            self._config.hidden_size // num_encoder_attention_heads,
        )
        __lowerCAmelCase			=				common_inputs['''attention_mask'''].dtype
        __lowerCAmelCase			=				torch.cat(
            [common_inputs['''attention_mask'''], torch.ones(snake_case			,						snake_case			,						dtype=snake_case							)]			,						dim=1							)
        __lowerCAmelCase			=				[
            (torch.zeros(snake_case							), torch.zeros(snake_case							)) for _ in range(snake_case							)
        ]
      return common_inputs





    def 	A		(   self						:		Optional[int]			,						snake_case						:		PreTrainedTokenizer			,						snake_case						:		int = -1			,						snake_case						:		int = -1			,						snake_case						:		bool = False			,						snake_case						:		Optional[TensorType] = None			,						):

      """simple docstring"""





      __lowerCAmelCase			=				compute_effective_axis_dimension(
          snake_case			,						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
      __lowerCAmelCase			=				tokenizer.num_special_tokens_to_add(snake_case							)
      __lowerCAmelCase			=				compute_effective_axis_dimension(
          snake_case			,						fixed_dimension=OnnxConfig.default_fixed_sequence			,						num_token_to_add=snake_case							)

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





    def 	A		(   self						:		str			,						snake_case						:		PreTrainedTokenizer			,						snake_case						:		int = -1			,						snake_case						:		int = -1			,						snake_case						:		bool = False			,						snake_case						:		Optional[TensorType] = None			,						):

      """simple docstring"""





      if self.task in ["default", "seq2seq-lm"]:
        __lowerCAmelCase			=				self._generate_dummy_inputs_for_default_and_seqaseq_lm(
            snake_case			,						batch_size=snake_case			,						seq_length=snake_case			,						is_pair=snake_case			,						framework=snake_case							)

      elif self.task == "causal-lm":
        __lowerCAmelCase			=				self._generate_dummy_inputs_for_causal_lm(
            snake_case			,						batch_size=snake_case			,						seq_length=snake_case			,						is_pair=snake_case			,						framework=snake_case							)
      else:
        __lowerCAmelCase			=				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            snake_case			,						batch_size=snake_case			,						seq_length=snake_case			,						is_pair=snake_case			,						framework=snake_case							)

      return common_inputs





    def 	A		(   self						:		Optional[Any]			,						snake_case						:		int			,						snake_case						:		str			,						snake_case						:		str			,						snake_case						:		List[str]							):

      """simple docstring"""





      if self.task in ["default", "seq2seq-lm"]:
        __lowerCAmelCase			=				super()._flatten_past_key_values_(snake_case			,						snake_case			,						snake_case			,						snake_case							)
      else:
        __lowerCAmelCase			=				super(snake_case			,						self							)._flatten_past_key_values_(
            snake_case			,						snake_case			,						snake_case			,						snake_case							)





    def 	A		(   self						:		List[Any]			,						snake_case						:		Mapping[str, Mapping[int, str]]			,						snake_case						:		str							):

      """simple docstring"""





      if direction not in ["inputs", "outputs"]:
        raise ValueError(f'''direction must either be "inputs" or "outputs", but {direction} was given'''							)

      __lowerCAmelCase			=				'''past_key_values''' if direction == '''inputs''' else '''present'''
      __lowerCAmelCase	,						__lowerCAmelCase			=				self.num_layers

      __lowerCAmelCase			=				'''past_encoder_sequence'''
      __lowerCAmelCase			=				'''past_decoder_sequence''' if direction == '''inputs''' else '''past_decoder_sequence + sequence'''

      for i in range(snake_case							):
        __lowerCAmelCase			=				{0: '''batch''', 2: decoder_sequence}
        __lowerCAmelCase			=				{0: '''batch''', 2: decoder_sequence}
        __lowerCAmelCase			=				{0: '''batch''', 2: encoder_sequence}
        __lowerCAmelCase			=				{0: '''batch''', 2: encoder_sequence}
