




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

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


lowerCAmelCase__						=			logging.get_logger(__name__)

lowerCAmelCase__						=			{
    """facebook/m2m100_418M""": """https://huggingface.co/facebook/m2m100_418M/resolve/main/config.json""",
    # See all M2M100 models at https://huggingface.co/models?filter=m2m_100
}







class 					lowerCAmelCase__	(    _UpperCAmelCase):




     '''simple docstring'''
     __SCREAMING_SNAKE_CASE        =			'''m2m_100'''
     __SCREAMING_SNAKE_CASE        =			['''past_key_values''']
     __SCREAMING_SNAKE_CASE        =			{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}


     def __init__(						self			,						__lowerCamelCase=1_2_8_1_1_2			,						__lowerCamelCase=1_0_2_4			,						__lowerCamelCase=1_2			,						__lowerCamelCase=4_0_9_6			,						__lowerCamelCase=1_6			,						__lowerCamelCase=1_2			,						__lowerCamelCase=4_0_9_6			,						__lowerCamelCase=1_6			,						__lowerCamelCase=0.0_5			,						__lowerCamelCase=0.0_5			,						__lowerCamelCase=True			,						__lowerCamelCase=True			,						__lowerCamelCase="relu"			,						__lowerCamelCase=1_0_2_4			,						__lowerCamelCase=0.1			,						__lowerCamelCase=0.1			,						__lowerCamelCase=0.0			,						__lowerCamelCase=0.0_2			,						__lowerCamelCase=2			,						__lowerCamelCase=True			,						__lowerCamelCase=1			,						__lowerCamelCase=0			,						__lowerCamelCase=2			,						**__lowerCamelCase			,						)      ->    int:
            _A				:	List[Any]       =			vocab_size
            _A				:	List[str]       =			max_position_embeddings
            _A				:	Any       =			d_model
            _A				:	int       =			encoder_ffn_dim
            _A				:	Optional[Any]       =			encoder_layers
            _A				:	int       =			encoder_attention_heads
            _A				:	Any       =			decoder_ffn_dim
            _A				:	Tuple       =			decoder_layers
            _A				:	int       =			decoder_attention_heads
            _A				:	Union[str, Any]       =			dropout
            _A				:	Union[str, Any]       =			attention_dropout
            _A				:	Any       =			activation_dropout
            _A				:	Any       =			activation_function
            _A				:	Union[str, Any]       =			init_std
            _A				:	Optional[Any]       =			encoder_layerdrop
            _A				:	Any       =			decoder_layerdrop
            _A				:	Union[str, Any]       =			use_cache
            _A				:	Optional[Any]       =			encoder_layers
            _A				:	Any       =			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__			,						**lowerCAmelCase__			,						)







class 					lowerCAmelCase__	(    _UpperCAmelCase):




     '''simple docstring'''


     @property
     def 			_lowerCamelCase			(						self)      ->    Mapping[str, Mapping[int, str]]:
            _A				:	List[Any]       =			OrderedDict(
                [
                    ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                    ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
                ])

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

            if self.use_past:
                   self.fill_with_past_key_values_(lowerCAmelCase__			,						direction="inputs")
            return common_inputs


     def 			_lowerCamelCase			(						self			,						__lowerCamelCase			,						__lowerCamelCase = -1			,						__lowerCamelCase = -1			,						__lowerCamelCase = False			,						__lowerCamelCase = None			,						)      ->    Mapping[str, Any]:
            _A				:	int       =			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
            _A				:	Optional[int]       =			tokenizer.num_special_tokens_to_add(lowerCAmelCase__)
            _A				:	int       =			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
            _A				:	str       =			[" ".join([tokenizer.unk_token]) * seq_length] * batch_size
            _A				:	Optional[Any]       =			dict(tokenizer(lowerCAmelCase__			,						return_tensors=lowerCAmelCase__))
            return common_inputs


     def 			_lowerCamelCase			(						self			,						__lowerCamelCase			,						__lowerCamelCase = -1			,						__lowerCamelCase = -1			,						__lowerCamelCase = False			,						__lowerCamelCase = None			,						)      ->    Mapping[str, Any]:
            _A				:	Optional[int]       =			self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__)

            # Generate decoder inputs
            _A				:	Union[str, Any]       =			seq_length if not self.use_past else 1
            _A				:	List[str]       =			self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__)
            _A				:	Dict       =			{F"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
            _A				:	int       =			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
                   _A   ,      _A				:	Tuple       =			common_inputs["input_ids"].shape
                   _A				:	Dict       =			common_inputs["decoder_input_ids"].shape[1]
                   _A   ,      _A				:	Optional[Any]       =			self.num_attention_heads
                   _A				:	Optional[Any]       =			(
                       batch,
                       num_encoder_attention_heads,
                       encoder_seq_length,
                       self._config.hidden_size // num_encoder_attention_heads,
                   )
                   _A				:	Any       =			decoder_seq_length + 3
                   _A				:	Tuple       =			(
                       batch,
                       num_decoder_attention_heads,
                       decoder_past_length,
                       self._config.hidden_size // num_decoder_attention_heads,
                   )

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

                   _A				:	int       =			[]
                   # If the number of encoder and decoder layers are present in the model configuration, both are considered
                   _A   ,      _A				:	Optional[Any]       =			self.num_layers
                   _A				:	Any       =			min(lowerCAmelCase__			,						lowerCAmelCase__)
                   _A				:	int       =			max(lowerCAmelCase__			,						lowerCAmelCase__) - min_num_layers
                   _A				:	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.
                   _A				:	List[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


     __SCREAMING_SNAKE_CASE        =			_generate_dummy_inputs_for_default_and_seqaseq_lm




from typing import List

import datasets
from datasets.tasks import ImageClassification

from ..folder_based_builder import folder_based_builder


lowerCAmelCase__						=			datasets.utils.logging.get_logger(__name__)







class 					lowerCAmelCase__	(    folder_based_builder.FolderBasedBuilderConfig):




     '''simple docstring'''
     __SCREAMING_SNAKE_CASE        =			None
     __SCREAMING_SNAKE_CASE        =			None







class 					lowerCAmelCase__	(    folder_based_builder.FolderBasedBuilder):




     '''simple docstring'''
     __SCREAMING_SNAKE_CASE        =			datasets.Image()
     __SCREAMING_SNAKE_CASE        =			"image"
     __SCREAMING_SNAKE_CASE        =			ImageFolderConfig
     __SCREAMING_SNAKE_CASE        =			42  # definition at the bottom of the script
     __SCREAMING_SNAKE_CASE        =			ImageClassification(image_column="image"					,   label_column="label")




lowerCAmelCase__						=			[
    '.blp',
    '.bmp',
    '.dib',
    '.bufr',
    '.cur',
    '.pcx',
    '.dcx',
    '.dds',
    '.ps',
    '.eps',
    '.fit',
    '.fits',
    '.fli',
    '.flc',
    '.ftc',
    '.ftu',
    '.gbr',
    '.gif',
    '.grib',
    '.h5',
    '.hdf',
    '.png',
    '.apng',
    '.jp2',
    '.j2k',
    '.jpc',
    '.jpf',
    '.jpx',
    '.j2c',
    '.icns',
    '.ico',
    '.im',
    '.iim',
    '.tif',
    '.tiff',
    '.jfif',
    '.jpe',
    '.jpg',
    '.jpeg',
    '.mpg',
    '.mpeg',
    '.msp',
    '.pcd',
    '.pxr',
    '.pbm',
    '.pgm',
    '.ppm',
    '.pnm',
    '.psd',
    '.bw',
    '.rgb',
    '.rgba',
    '.sgi',
    '.ras',
    '.tga',
    '.icb',
    '.vda',
    '.vst',
    '.webp',
    '.wmf',
    '.emf',
    '.xbm',
    '.xpm',
]
lowerCAmelCase__						=			IMAGE_EXTENSIONS
