


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


_A		:				Dict									=       logging.get_logger(__name__)

_A		:				Optional[Any]									=       {
    '''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        a					(			_UpperCAmelCase   ):
     UpperCAmelCase__ :  Dict						      =	"marian"
     UpperCAmelCase__ :  List[str]						      =	["past_key_values"]
     UpperCAmelCase__ :  int						      =	{"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}





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



class        a					(			_UpperCAmelCase   ):





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

           if self.use_past:
              __lowerCamelCase:				Tuple     =	{0: """batch"""}
              __lowerCamelCase:				Any     =	{0: """batch""", 1: """past_decoder_sequence + sequence"""}
           else:
              __lowerCamelCase:				Dict     =	{0: """batch""", 1: """decoder_sequence"""}
              __lowerCamelCase:				Any     =	{0: """batch""", 1: """decoder_sequence"""}

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





     def  SCREAMING_SNAKE_CASE__       (    self					:				Optional[int]    ,	SCREAMING_SNAKE_CASE_					:				PreTrainedTokenizer    ,	SCREAMING_SNAKE_CASE_					:				int = -1    ,	SCREAMING_SNAKE_CASE_					:				int = -1    ,	SCREAMING_SNAKE_CASE_					:				bool = False    ,	SCREAMING_SNAKE_CASE_					:				Optional[TensorType] = None    ,	):
        __lowerCamelCase:				List[str]     =	self._generate_dummy_inputs_for_encoder_and_decoder(
            SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							)

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

           __lowerCamelCase:				Union[str, Any]     =	torch.cat(
               [common_inputs["""decoder_attention_mask"""], torch.ones(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							)]    ,	dim=1							)

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

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





     def  SCREAMING_SNAKE_CASE__       (    self					:				Union[str, Any]    ,	SCREAMING_SNAKE_CASE_					:				PreTrainedTokenizer    ,	SCREAMING_SNAKE_CASE_					:				int = -1    ,	SCREAMING_SNAKE_CASE_					:				int = -1    ,	SCREAMING_SNAKE_CASE_					:				bool = False    ,	SCREAMING_SNAKE_CASE_					:				Optional[TensorType] = None    ,	):
        __lowerCamelCase:				Any     =	self._generate_dummy_inputs_for_encoder_and_decoder(
            SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_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:				Optional[Any]     =	common_inputs["""input_ids"""].shape
           # Not using the same length for past_key_values
           __lowerCamelCase:				Any     =	seqlen + 2
           __lowerCamelCase   ,     __lowerCamelCase:				List[str]     =	self.num_layers
           __lowerCamelCase   ,     __lowerCamelCase:				List[Any]     =	self.num_attention_heads
           __lowerCamelCase:				Dict     =	(
               batch,
               num_encoder_attention_heads,
               past_key_values_length,
               self._config.hidden_size // num_encoder_attention_heads,
           )

           __lowerCamelCase:				Union[str, Any]     =	common_inputs["""attention_mask"""].dtype
           __lowerCamelCase:				int     =	torch.cat(
               [common_inputs["""attention_mask"""], torch.ones(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	dtype=SCREAMING_SNAKE_CASE_							)]    ,	dim=1							)
           __lowerCamelCase:				Optional[Any]     =	[
               (torch.zeros(SCREAMING_SNAKE_CASE_							), torch.zeros(SCREAMING_SNAKE_CASE_							)) for _ in range(SCREAMING_SNAKE_CASE_							)
           ]
        return common_inputs





     def  SCREAMING_SNAKE_CASE__       (    self					:				List[str]    ,	SCREAMING_SNAKE_CASE_					:				PreTrainedTokenizer    ,	SCREAMING_SNAKE_CASE_					:				int = -1    ,	SCREAMING_SNAKE_CASE_					:				int = -1    ,	SCREAMING_SNAKE_CASE_					:				bool = False    ,	SCREAMING_SNAKE_CASE_					:				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
        __lowerCamelCase:				Dict     =	compute_effective_axis_dimension(
            SCREAMING_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:				int     =	tokenizer.num_special_tokens_to_add(SCREAMING_SNAKE_CASE_							)
        __lowerCamelCase:				str     =	compute_effective_axis_dimension(
            SCREAMING_SNAKE_CASE_    ,	fixed_dimension=OnnxConfig.default_fixed_sequence    ,	num_token_to_add=SCREAMING_SNAKE_CASE_							)

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





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

        else:
           __lowerCamelCase:				Any     =	self._generate_dummy_inputs_for_causal_lm(
               SCREAMING_SNAKE_CASE_    ,	batch_size=SCREAMING_SNAKE_CASE_    ,	seq_length=SCREAMING_SNAKE_CASE_    ,	is_pair=SCREAMING_SNAKE_CASE_    ,	framework=SCREAMING_SNAKE_CASE_							)

        return common_inputs





     def  SCREAMING_SNAKE_CASE__       (    self					:				str    ,	SCREAMING_SNAKE_CASE_					:				Optional[Any]    ,	SCREAMING_SNAKE_CASE_					:				str    ,	SCREAMING_SNAKE_CASE_					:				Optional[Any]    ,	SCREAMING_SNAKE_CASE_					:				List[str]							):
        if self.task in ["default", "seq2seq-lm"]:
           __lowerCamelCase:				Any     =	super()._flatten_past_key_values_(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							)
        else:
           __lowerCamelCase:				Optional[Any]     =	super(SCREAMING_SNAKE_CASE_    ,	self							)._flatten_past_key_values_(
               SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							)







     @property
     def  SCREAMING_SNAKE_CASE__       (    self					:				Union[str, Any]							):
        return 1E-4






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_A		:				List[Any]									=       {
    '''configuration_convbert''': ['''CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ConvBertConfig''', '''ConvBertOnnxConfig'''],
    '''tokenization_convbert''': ['''ConvBertTokenizer'''],
}

try:
   if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A		:				int									=       ['''ConvBertTokenizerFast''']

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A		:				List[Any]									=       [
       '''CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''ConvBertForMaskedLM''',
       '''ConvBertForMultipleChoice''',
       '''ConvBertForQuestionAnswering''',
       '''ConvBertForSequenceClassification''',
       '''ConvBertForTokenClassification''',
       '''ConvBertLayer''',
       '''ConvBertModel''',
       '''ConvBertPreTrainedModel''',
       '''load_tf_weights_in_convbert''',
   ]


try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A		:				List[Any]									=       [
       '''TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''TFConvBertForMaskedLM''',
       '''TFConvBertForMultipleChoice''',
       '''TFConvBertForQuestionAnswering''',
       '''TFConvBertForSequenceClassification''',
       '''TFConvBertForTokenClassification''',
       '''TFConvBertLayer''',
       '''TFConvBertModel''',
       '''TFConvBertPreTrainedModel''',
   ]


if TYPE_CHECKING:
   from .configuration_convbert import CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvBertConfig, ConvBertOnnxConfig
   from .tokenization_convbert import ConvBertTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_convbert_fast import ConvBertTokenizerFast

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_convbert import (
          CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          ConvBertForMaskedLM,
          ConvBertForMultipleChoice,
          ConvBertForQuestionAnswering,
          ConvBertForSequenceClassification,
          ConvBertForTokenClassification,
          ConvBertLayer,
          ConvBertModel,
          ConvBertPreTrainedModel,
          load_tf_weights_in_convbert,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_convbert import (
          TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFConvBertForMaskedLM,
          TFConvBertForMultipleChoice,
          TFConvBertForQuestionAnswering,
          TFConvBertForSequenceClassification,
          TFConvBertForTokenClassification,
          TFConvBertLayer,
          TFConvBertModel,
          TFConvBertPreTrainedModel,
      )


else:
   import sys

   _A		:				int									=       _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


