






import os
import sys
import unittest


__magic_name__:					List[str]							=     os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, "utils"))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
__magic_name__:					Union[str, Any]							=     os.path.join(git_repo_path, "src", "transformers")

__magic_name__:					List[str]							=     "\n{0} = None\n"

__magic_name__:					Tuple							=     "\nclass {0}(metaclass=DummyObject):\n    _backends = {1}\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, {1})\n"


__magic_name__:					str							=     "\ndef {0}(*args, **kwargs):\n    requires_backends({0}, {1})\n"





class 	snake_case__ (							unittest.TestCase				):
	def       __magic_name__    (    self			)							->				int:
							__magic_name__      :       Optional[int]       						= find_backend("""    _import_structure[\"models.albert\"].append(\"AlbertTokenizerFast\")"""			)
							self.assertIsNone(lowerCAmelCase__			)

							__magic_name__      :       Tuple       						= find_backend("""    if not is_tokenizers_available():"""			)
							self.assertEqual(lowerCAmelCase__      ,       """tokenizers"""			)

							__magic_name__      :       List[str]       						= find_backend("""    if not is_tensorflow_text_available():"""			)
							self.assertEqual(lowerCAmelCase__      ,       """tensorflow_text"""			)

							__magic_name__      :       int       						= find_backend("""    if not (is_sentencepiece_available() and is_tokenizers_available()):"""			)
							self.assertEqual(lowerCAmelCase__      ,       """sentencepiece_and_tokenizers"""			)

							__magic_name__      :       Any       						= find_backend(
							    """    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"""			)
							self.assertEqual(lowerCAmelCase__      ,       """sentencepiece_and_tensorflow_text"""			)

							__magic_name__      :       Dict       						= find_backend(
							    """    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):"""			)
							self.assertEqual(lowerCAmelCase__      ,       """sentencepiece_and_tokenizers_and_vision"""			)
	def       __magic_name__    (    self			)							->				int:
							__magic_name__      :       int       						= read_init()
							# We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
							self.assertIn("""torch"""      ,       lowerCAmelCase__			)
							self.assertIn("""tensorflow_text"""      ,       lowerCAmelCase__			)
							self.assertIn("""sentencepiece_and_tokenizers"""      ,       lowerCAmelCase__			)

							# Likewise, we can't assert on the exact content of a key
							self.assertIn("""BertModel"""      ,       objects["""torch"""]			)
							self.assertIn("""TFBertModel"""      ,       objects["""tf"""]			)
							self.assertIn("""FlaxBertModel"""      ,       objects["""flax"""]			)
							self.assertIn("""BertModel"""      ,       objects["""torch"""]			)
							self.assertIn("""TFBertTokenizer"""      ,       objects["""tensorflow_text"""]			)
							self.assertIn("""convert_slow_tokenizer"""      ,       objects["""sentencepiece_and_tokenizers"""]			)
	def       __magic_name__    (    self			)							->				Dict:
							__magic_name__      :       str       						= create_dummy_object("""CONSTANT"""      ,       """'torch'"""			)
							self.assertEqual(lowerCAmelCase__      ,       """\nCONSTANT = None\n"""			)

							__magic_name__      :       Optional[int]       						= create_dummy_object("""function"""      ,       """'torch'"""			)
							self.assertEqual(
							    lowerCAmelCase__      ,       """\ndef function(*args, **kwargs):\n    requires_backends(function, 'torch')\n"""			)

							__magic_name__      :       Dict       						= """
class FakeClass(metaclass=DummyObject):
    _backends = 'torch'

    def __init__(self, *args, **kwargs):
        requires_backends(self, 'torch')
"""
							__magic_name__      :       int       						= create_dummy_object("""FakeClass"""      ,       """'torch'"""			)
							self.assertEqual(lowerCAmelCase__      ,       lowerCAmelCase__			)







	def       __magic_name__    (    self			)							->				Any:
							__magic_name__      :       Any       						= """# This file is autogenerated by the command `make fix-copies`, do not edit.
from ..utils import DummyObject, requires_backends


CONSTANT = None


def function(*args, **kwargs):
    requires_backends(function, [\"torch\"])


class FakeClass(metaclass=DummyObject):
    _backends = [\"torch\"]

    def __init__(self, *args, **kwargs):
        requires_backends(self, [\"torch\"])
"""
							__magic_name__      :       str       						= create_dummy_files({"""torch""": ["""CONSTANT""", """function""", """FakeClass"""]}			)
							self.assertEqual(dummy_files["""torch"""]      ,       lowerCAmelCase__			)








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


__magic_name__:					Any							=     logging.get_logger(__name__)

__magic_name__:					Dict							=     {
    "facebook/blenderbot_small-90M": "https://huggingface.co/facebook/blenderbot_small-90M/resolve/main/config.json",
    # See all BlenderbotSmall models at https://huggingface.co/models?filter=blenderbot_small
}





class 	snake_case__ (							_lowerCAmelCase				):
	lowercase__						:					Any											=   '''blenderbot-small'''
	lowercase__						:					Optional[int]											=   ['''past_key_values''']
	lowercase__						:					Dict											=   {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}
	def __init__(    self      ,       lowerCAmelCase__=5_02_65      ,       lowerCAmelCase__=5_12      ,       lowerCAmelCase__=8      ,       lowerCAmelCase__=20_48      ,       lowerCAmelCase__=16      ,       lowerCAmelCase__=8      ,       lowerCAmelCase__=20_48      ,       lowerCAmelCase__=16      ,       lowerCAmelCase__=0.0      ,       lowerCAmelCase__=0.0      ,       lowerCAmelCase__=True      ,       lowerCAmelCase__=True      ,       lowerCAmelCase__="gelu"      ,       lowerCAmelCase__=5_12      ,       lowerCAmelCase__=0.1      ,       lowerCAmelCase__=0.0      ,       lowerCAmelCase__=0.0      ,       lowerCAmelCase__=0.0_2      ,       lowerCAmelCase__=1      ,       lowerCAmelCase__=False      ,       lowerCAmelCase__=0      ,       lowerCAmelCase__=1      ,       lowerCAmelCase__=2      ,       lowerCAmelCase__=2      ,       **lowerCAmelCase__      ,       )							->				Tuple:
							__magic_name__      :       Tuple       						= vocab_size
							__magic_name__      :       List[str]       						= max_position_embeddings
							__magic_name__      :       Union[str, Any]       						= d_model
							__magic_name__      :       Optional[int]       						= encoder_ffn_dim
							__magic_name__      :       Union[str, Any]       						= encoder_layers
							__magic_name__      :       List[str]       						= encoder_attention_heads
							__magic_name__      :       List[Any]       						= decoder_ffn_dim
							__magic_name__      :       str       						= decoder_layers
							__magic_name__      :       List[str]       						= decoder_attention_heads
							__magic_name__      :       Union[str, Any]       						= dropout
							__magic_name__      :       Tuple       						= attention_dropout
							__magic_name__      :       List[Any]       						= activation_dropout
							__magic_name__      :       List[Any]       						= activation_function
							__magic_name__      :       Optional[int]       						= init_std
							__magic_name__      :       Dict       						= encoder_layerdrop
							__magic_name__      :       Union[str, Any]       						= decoder_layerdrop
							__magic_name__      :       Optional[int]       						= use_cache
							__magic_name__      :       List[Any]       						= encoder_layers
							__magic_name__      :       Dict       						= scale_embedding  # scale factor will be sqrt(d_model) if True

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





class 	snake_case__ (							_lowerCAmelCase				):
	@property
	def       __magic_name__    (    self			)							->				Mapping[str, Mapping[int, str]]:
							if self.task in ["default", "seq2seq-lm"]:
													__magic_name__      :       Optional[int]       						= OrderedDict(
													    [
													        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
													        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
													    ]			)

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

													if self.use_past:
																			self.fill_with_past_key_values_(lowerCAmelCase__      ,       direction="""inputs"""			)
							elif self.task == "causal-lm":
													# TODO: figure this case out.
													__magic_name__      :       Union[str, Any]       						= OrderedDict(
													    [
													        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
													        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
													    ]			)
													if self.use_past:
																			__magic_name__						,__magic_name__      :       Dict       						= self.num_layers
																			for i in range(lowerCAmelCase__			):
																									__magic_name__      :       Dict       						= {0: """batch""", 2: """past_sequence + sequence"""}
																									__magic_name__      :       int       						= {0: """batch""", 2: """past_sequence + sequence"""}
							else:
													__magic_name__      :       Union[str, 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       __magic_name__    (    self			)							->				Mapping[str, Mapping[int, str]]:
							if self.task in ["default", "seq2seq-lm"]:
													__magic_name__      :       Any       						= super().outputs
							else:
													__magic_name__      :       int       						= super(lowerCAmelCase__      ,       self			).outputs
													if self.use_past:
																			__magic_name__						,__magic_name__      :       str       						= self.num_layers
																			for i in range(lowerCAmelCase__			):
																									__magic_name__      :       Tuple       						= {0: """batch""", 2: """past_sequence + sequence"""}
																									__magic_name__      :       Dict       						= {0: """batch""", 2: """past_sequence + sequence"""}
							return common_outputs
	def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__ = -1      ,       lowerCAmelCase__ = -1      ,       lowerCAmelCase__ = False      ,       lowerCAmelCase__ = None      ,       )							->				Mapping[str, Any]:
							__magic_name__      :       Tuple       						= self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)

							# Generate decoder inputs
							__magic_name__      :       Optional[int]       						= seq_length if not self.use_past else 1
							__magic_name__      :       Optional[Any]       						= self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)
							__magic_name__      :       Optional[Any]       						= {F'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
							__magic_name__      :       Dict       						= dict(**lowerCAmelCase__      ,       **lowerCAmelCase__			)

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

													__magic_name__      :       List[str]       						= torch.cat(
													    [common_inputs["""decoder_attention_mask"""], torch.ones(lowerCAmelCase__      ,       lowerCAmelCase__			)]      ,       dim=1			)

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

													for _ in range(lowerCAmelCase__			):
																			common_inputs["past_key_values"].append(
																			    (
																			        torch.zeros(lowerCAmelCase__			),
																			        torch.zeros(lowerCAmelCase__			),
																			        torch.zeros(lowerCAmelCase__			),
																			        torch.zeros(lowerCAmelCase__			),
																			    )			)
													# TODO: test this.
													__magic_name__      :       Union[str, Any]       						= encoder_shape if remaining_side_name == """encoder""" else decoder_shape
													for _ in range(lowerCAmelCase__      ,       lowerCAmelCase__			):
																			common_inputs["past_key_values"].append((torch.zeros(lowerCAmelCase__			), torch.zeros(lowerCAmelCase__			))			)
							return common_inputs
	def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__ = -1      ,       lowerCAmelCase__ = -1      ,       lowerCAmelCase__ = False      ,       lowerCAmelCase__ = None      ,       )							->				Mapping[str, Any]:
							__magic_name__      :       int       						= self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)

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

													__magic_name__      :       Optional[int]       						= common_inputs["""attention_mask"""].dtype
													__magic_name__      :       Optional[Any]       						= torch.cat(
													    [common_inputs["""attention_mask"""], torch.ones(lowerCAmelCase__      ,       lowerCAmelCase__      ,       dtype=lowerCAmelCase__			)]      ,       dim=1			)
													__magic_name__      :       Tuple       						= [
													    (torch.zeros(lowerCAmelCase__			), torch.zeros(lowerCAmelCase__			)) for _ in range(lowerCAmelCase__			)
													]
							return common_inputs
	def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__ = -1      ,       lowerCAmelCase__ = -1      ,       lowerCAmelCase__ = False      ,       lowerCAmelCase__ = None      ,       )							->				Mapping[str, Any]:
							# 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
							__magic_name__      :       Tuple       						= compute_effective_axis_dimension(
							    lowerCAmelCase__      ,       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
							__magic_name__      :       str       						= tokenizer.num_special_tokens_to_add(lowerCAmelCase__			)
							__magic_name__      :       List[str]       						= compute_effective_axis_dimension(
							    lowerCAmelCase__      ,       fixed_dimension=OnnxConfig.default_fixed_sequence      ,       num_token_to_add=lowerCAmelCase__			)

							# Generate dummy inputs according to compute batch and sequence
							__magic_name__      :       List[Any]       						= [""" """.join([tokenizer.unk_token]			) * seq_length] * batch_size
							__magic_name__      :       List[str]       						= dict(tokenizer(lowerCAmelCase__      ,       return_tensors=lowerCAmelCase__			)			)
							return common_inputs
	def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__ = -1      ,       lowerCAmelCase__ = -1      ,       lowerCAmelCase__ = False      ,       lowerCAmelCase__ = None      ,       )							->				Mapping[str, Any]:
							if self.task in ["default", "seq2seq-lm"]:
													__magic_name__      :       Tuple       						= self._generate_dummy_inputs_for_default_and_seqaseq_lm(
													    lowerCAmelCase__      ,       batch_size=lowerCAmelCase__      ,       seq_length=lowerCAmelCase__      ,       is_pair=lowerCAmelCase__      ,       framework=lowerCAmelCase__			)

							elif self.task == "causal-lm":
													__magic_name__      :       str       						= self._generate_dummy_inputs_for_causal_lm(
													    lowerCAmelCase__      ,       batch_size=lowerCAmelCase__      ,       seq_length=lowerCAmelCase__      ,       is_pair=lowerCAmelCase__      ,       framework=lowerCAmelCase__			)
							else:
													__magic_name__      :       Dict       						= self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
													    lowerCAmelCase__      ,       batch_size=lowerCAmelCase__      ,       seq_length=lowerCAmelCase__      ,       is_pair=lowerCAmelCase__      ,       framework=lowerCAmelCase__			)

							return common_inputs







	def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)							->				Dict:
							if self.task in ["default", "seq2seq-lm"]:
													__magic_name__      :       List[Any]       						= super()._flatten_past_key_values_(lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)
							else:
													__magic_name__      :       Tuple       						= super(lowerCAmelCase__      ,       self			)._flatten_past_key_values_(
													    lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)
