


"""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												=							logging.get_logger(__name__)

__snake_case												=							{
    '''facebook/mbart-large-cc25''': '''https://huggingface.co/facebook/mbart-large-cc25/resolve/main/config.json''',
    # See all MBART models at https://huggingface.co/models?filter=mbart
}


class      __lowerCamelCase	(       _lowercase					):

     '''simple docstring'''
     A_							:						List[str]     =		'mbart'
     A_							:						str     =		['past_key_values']
     A_							:						Any     =		{'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}


     def __init__(   self     ,					__UpperCAmelCase=50265     ,					__UpperCAmelCase=1024     ,					__UpperCAmelCase=12     ,					__UpperCAmelCase=4096     ,					__UpperCAmelCase=16     ,					__UpperCAmelCase=12     ,					__UpperCAmelCase=4096     ,					__UpperCAmelCase=16     ,					__UpperCAmelCase=0.0     ,					__UpperCAmelCase=0.0     ,					__UpperCAmelCase=True     ,					__UpperCAmelCase=True     ,					__UpperCAmelCase="gelu"     ,					__UpperCAmelCase=1024     ,					__UpperCAmelCase=0.1     ,					__UpperCAmelCase=0.0     ,					__UpperCAmelCase=0.0     ,					__UpperCAmelCase=0.02     ,					__UpperCAmelCase=0.0     ,					__UpperCAmelCase=False     ,					__UpperCAmelCase=1     ,					__UpperCAmelCase=0     ,					__UpperCAmelCase=2     ,					__UpperCAmelCase=2     ,					**__UpperCAmelCase     ,					)							->				Optional[Any]:
          _a     						=					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     						=					classifier_dropout
          _a     						=					use_cache
          _a     						=					encoder_layers
          _a     						=					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     ,					forced_eos_token_id=__lowerCAmelCase     ,					**__lowerCAmelCase     ,					)







class      __lowerCamelCase	(       _lowercase					):

     '''simple docstring'''


     @property
     def 				_UpperCAmelCase   (   self				)							->				Mapping[str, Mapping[int, 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_(__lowerCAmelCase     ,					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(__lowerCAmelCase				):
                         _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
     def 				_UpperCAmelCase   (   self				)							->				Mapping[str, Mapping[int, str]]:
          if self.task in ["default", "seq2seq-lm"]:
               _a     						=					super().outputs
          else:
               _a     						=					super(__lowerCAmelCase     ,					self				).outputs
               if self.use_past:
                    _a						,   _a     						=					self.num_layers
                    for i in range(__lowerCAmelCase				):
                         _a     						=					{0: '''batch''', 2: '''past_sequence + sequence'''}
                         _a     						=					{0: '''batch''', 2: '''past_sequence + sequence'''}
          return common_outputs


     def 				_UpperCAmelCase   (   self     ,					__UpperCAmelCase     ,					__UpperCAmelCase = -1     ,					__UpperCAmelCase = -1     ,					__UpperCAmelCase = False     ,					__UpperCAmelCase = None     ,					)							->				Mapping[str, Any]:
          _a     						=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
              __lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase				)

          # Generate decoder inputs
          _a     						=					seq_length if not self.use_past else 1
          _a     						=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
              __lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase				)
          _a     						=					{F'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
          _a     						=					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     						=					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(__lowerCAmelCase     ,					__lowerCAmelCase				)]     ,					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(__lowerCAmelCase     ,					__lowerCAmelCase				)
               _a     						=					max(__lowerCAmelCase     ,					__lowerCAmelCase				) - min_num_layers
               _a     						=					'''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     						=					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 				_UpperCAmelCase   (   self     ,					__UpperCAmelCase     ,					__UpperCAmelCase = -1     ,					__UpperCAmelCase = -1     ,					__UpperCAmelCase = False     ,					__UpperCAmelCase = None     ,					)							->				Mapping[str, Any]:
          _a     						=					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
               _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(__lowerCAmelCase     ,					__lowerCAmelCase     ,					dtype=__lowerCAmelCase				)]     ,					dim=1				)
               _a     						=					[
                   (torch.zeros(__lowerCAmelCase				), torch.zeros(__lowerCAmelCase				)) for _ in range(__lowerCAmelCase				)
               ]
          return common_inputs


     def 				_UpperCAmelCase   (   self     ,					__UpperCAmelCase     ,					__UpperCAmelCase = -1     ,					__UpperCAmelCase = -1     ,					__UpperCAmelCase = False     ,					__UpperCAmelCase = 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
          _a     						=					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     						=					tokenizer.num_special_tokens_to_add(__lowerCAmelCase				)
          _a     						=					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     						=					[''' '''.join([tokenizer.unk_token]				) * seq_length] * batch_size
          _a     						=					dict(tokenizer(__lowerCAmelCase     ,					return_tensors=__lowerCAmelCase				)				)
          return common_inputs


     def 				_UpperCAmelCase   (   self     ,					__UpperCAmelCase     ,					__UpperCAmelCase = -1     ,					__UpperCAmelCase = -1     ,					__UpperCAmelCase = False     ,					__UpperCAmelCase = None     ,					)							->				Mapping[str, Any]:
          if self.task in ["default", "seq2seq-lm"]:
               _a     						=					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":
               _a     						=					self._generate_dummy_inputs_for_causal_lm(
                   __lowerCAmelCase     ,					batch_size=__lowerCAmelCase     ,					seq_length=__lowerCAmelCase     ,					is_pair=__lowerCAmelCase     ,					framework=__lowerCAmelCase				)
          else:
               _a     						=					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 				_UpperCAmelCase   (   self     ,					__UpperCAmelCase     ,					__UpperCAmelCase     ,					__UpperCAmelCase     ,					__UpperCAmelCase				)							->				Dict:
          if self.task in ["default", "seq2seq-lm"]:
               _a     						=					super()._flatten_past_key_values_(__lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase				)
          else:
               _a     						=					super(__lowerCAmelCase     ,					self				)._flatten_past_key_values_(
                   __lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase				)






from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCAmelCase 	=      logging.get_logger(__name__)

__lowerCAmelCase 	=      {
    "MCG-NJU/videomae-base": "https://huggingface.co/MCG-NJU/videomae-base/resolve/main/config.json",
}




class 	_UpperCAmelCase						( _lowercase       ):
					__A        = "videomae"




					def __init__(    self     ,   __lowerCAmelCase=224     ,   __lowerCAmelCase=16     ,   __lowerCAmelCase=3     ,   __lowerCAmelCase=16     ,   __lowerCAmelCase=2     ,   __lowerCAmelCase=768     ,   __lowerCAmelCase=12     ,   __lowerCAmelCase=12     ,   __lowerCAmelCase=3_072     ,   __lowerCAmelCase="gelu"     ,   __lowerCAmelCase=0.0     ,   __lowerCAmelCase=0.0     ,   __lowerCAmelCase=0.0_2     ,   __lowerCAmelCase=1E-1_2     ,   __lowerCAmelCase=True     ,   __lowerCAmelCase=True     ,   __lowerCAmelCase=6     ,   __lowerCAmelCase=384     ,   __lowerCAmelCase=4     ,   __lowerCAmelCase=1_536     ,   __lowerCAmelCase=True     ,   **__lowerCAmelCase     ,   )    ->	Any:
							super().__init__(**__lowerCAmelCase							)

							UpperCamelCase__								=						image_size
							UpperCamelCase__								=						patch_size
							UpperCamelCase__								=						num_channels
							UpperCamelCase__								=						num_frames
							UpperCamelCase__								=						tubelet_size

							UpperCamelCase__								=						hidden_size
							UpperCamelCase__								=						num_hidden_layers
							UpperCamelCase__								=						num_attention_heads
							UpperCamelCase__								=						intermediate_size
							UpperCamelCase__								=						hidden_act
							UpperCamelCase__								=						hidden_dropout_prob
							UpperCamelCase__								=						attention_probs_dropout_prob
							UpperCamelCase__								=						initializer_range
							UpperCamelCase__								=						layer_norm_eps
							UpperCamelCase__								=						qkv_bias
							UpperCamelCase__								=						use_mean_pooling

							UpperCamelCase__								=						decoder_num_attention_heads
							UpperCamelCase__								=						decoder_hidden_size
							UpperCamelCase__								=						decoder_num_hidden_layers
							UpperCamelCase__								=						decoder_intermediate_size
							UpperCamelCase__								=						norm_pix_loss





