


"""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


UpperCAmelCase__  							=logging.get_logger(__name__)

UpperCAmelCase__  							={
    "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    lowerCamelCase__						(		_a    ):
      a :     Tuple											=		"""marian"""
      a :     Dict											=		["""past_key_values"""]
      a :     str											=		{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}
      def __init__(		self	:	List[Any]      ,       A_	:	int=5_8_1_0_1      ,       A_	:	Tuple=None      ,       A_	:	str=1_0_2_4      ,       A_	:	List[str]=1_2      ,       A_	:	List[str]=4_0_9_6      ,       A_	:	Tuple=1_6      ,       A_	:	Optional[int]=1_2      ,       A_	:	Any=4_0_9_6      ,       A_	:	List[Any]=1_6      ,       A_	:	Optional[int]=0.0      ,       A_	:	Tuple=0.0      ,       A_	:	Optional[Any]=True      ,       A_	:	int=True      ,       A_	:	Optional[Any]="gelu"      ,       A_	:	Optional[Any]=1_0_2_4      ,       A_	:	Tuple=0.1      ,       A_	:	Tuple=0.0      ,       A_	:	Any=0.0      ,       A_	:	int=0.02      ,       A_	:	List[Any]=5_8_1_0_0      ,       A_	:	List[Any]=False      ,       A_	:	Any=5_8_1_0_0      ,       A_	:	str=0      ,       A_	:	Tuple=0      ,       A_	:	int=True      ,       **A_	:	Tuple      ,       ):






       '''simple docstring'''


       __lowercase									=	vocab_size
       __lowercase									=	decoder_vocab_size or vocab_size
       __lowercase									=	max_position_embeddings
       __lowercase									=	d_model
       __lowercase									=	encoder_ffn_dim
       __lowercase									=	encoder_layers
       __lowercase									=	encoder_attention_heads
       __lowercase									=	decoder_ffn_dim
       __lowercase									=	decoder_layers
       __lowercase									=	decoder_attention_heads
       __lowercase									=	dropout
       __lowercase									=	attention_dropout
       __lowercase									=	activation_dropout
       __lowercase									=	activation_function
       __lowercase									=	init_std
       __lowercase									=	encoder_layerdrop
       __lowercase									=	decoder_layerdrop
       __lowercase									=	use_cache
       __lowercase									=	encoder_layers
       __lowercase									=	scale_embedding  # scale factor will be sqrt(d_model) if True
       __lowercase									=	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    lowerCamelCase__						(		_a    ):
      @property
      # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
      def SCREAMING_SNAKE_CASE_	(		self	:	Optional[Any]							):






       '''simple docstring'''


       if self.task in ["default", "seq2seq-lm"]:
        __lowercase									=	OrderedDict(
            [
                ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
            ]							)

        if self.use_past:
         __lowercase									=	{0: """batch"""}
         __lowercase									=	{0: """batch""", 1: """past_decoder_sequence + sequence"""}
        else:
         __lowercase									=	{0: """batch""", 1: """decoder_sequence"""}
         __lowercase									=	{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.
        __lowercase									=	OrderedDict(
            [
                ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
            ]							)
        if self.use_past:
         __lowercase							,		__lowercase									=	self.num_layers
         for i in range(_SCREAMING_SNAKE_CASE							):
          __lowercase									=	{0: """batch""", 2: """past_sequence + sequence"""}
          __lowercase									=	{0: """batch""", 2: """past_sequence + sequence"""}
       else:
        __lowercase									=	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	:	Any							):






       '''simple docstring'''


       if self.task in ["default", "seq2seq-lm"]:
        __lowercase									=	super().outputs
       else:
        __lowercase									=	super(_SCREAMING_SNAKE_CASE      ,       self							).outputs
        if self.use_past:
         __lowercase							,		__lowercase									=	self.num_layers
         for i in range(_SCREAMING_SNAKE_CASE							):
          __lowercase									=	{0: """batch""", 2: """past_sequence + sequence"""}
          __lowercase									=	{0: """batch""", 2: """past_sequence + sequence"""}
       return common_outputs
      def SCREAMING_SNAKE_CASE_	(		self	:	Optional[int]      ,       A_	:	Any      ,       A_	:	List[str] = -1      ,       A_	:	str = -1      ,       A_	:	Dict = False      ,       A_	:	List[str] = None      ,       ):






       '''simple docstring'''


       __lowercase									=	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
       __lowercase									=	seq_length if not self.use_past else 1
       __lowercase									=	self._generate_dummy_inputs_for_encoder_and_decoder(
           _SCREAMING_SNAKE_CASE      ,       _SCREAMING_SNAKE_CASE      ,       _SCREAMING_SNAKE_CASE      ,       _SCREAMING_SNAKE_CASE      ,       _SCREAMING_SNAKE_CASE							)
       __lowercase									=	{F'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
       __lowercase									=	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
        __lowercase							,		__lowercase									=	common_inputs["""input_ids"""].shape
        __lowercase									=	common_inputs["""decoder_input_ids"""].shape[1]
        __lowercase							,		__lowercase									=	self.num_attention_heads
        __lowercase									=	(
            batch,
            num_encoder_attention_heads,
            encoder_seq_length,
            self._config.hidden_size // num_encoder_attention_heads,
        )
        __lowercase									=	decoder_seq_length + 3
        __lowercase									=	(
            batch,
            num_decoder_attention_heads,
            decoder_past_length,
            self._config.hidden_size // num_decoder_attention_heads,
        )

        __lowercase									=	torch.cat(
            [common_inputs["""decoder_attention_mask"""], torch.ones(_SCREAMING_SNAKE_CASE      ,       _SCREAMING_SNAKE_CASE							)]      ,       dim=1							)

        __lowercase									=	[]
        # If the number of encoder and decoder layers are present in the model configuration, both are considered
        __lowercase							,		__lowercase									=	self.num_layers
        __lowercase									=	min(_SCREAMING_SNAKE_CASE      ,       _SCREAMING_SNAKE_CASE							)
        __lowercase									=	max(_SCREAMING_SNAKE_CASE      ,       _SCREAMING_SNAKE_CASE							) - min_num_layers
        __lowercase									=	"""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.
        __lowercase									=	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	:	List[str]      ,       A_	:	int      ,       A_	:	List[Any] = -1      ,       A_	:	Union[str, Any] = -1      ,       A_	:	Any = False      ,       A_	:	List[str] = None      ,       ):






       '''simple docstring'''


       __lowercase									=	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
        __lowercase							,		__lowercase									=	common_inputs["""input_ids"""].shape
        # Not using the same length for past_key_values
        __lowercase									=	seqlen + 2
        __lowercase							,		__lowercase									=	self.num_layers
        __lowercase							,		__lowercase									=	self.num_attention_heads
        __lowercase									=	(
            batch,
            num_encoder_attention_heads,
            past_key_values_length,
            self._config.hidden_size // num_encoder_attention_heads,
        )

        __lowercase									=	common_inputs["""attention_mask"""].dtype
        __lowercase									=	torch.cat(
            [common_inputs["""attention_mask"""], torch.ones(_SCREAMING_SNAKE_CASE      ,       _SCREAMING_SNAKE_CASE      ,       dtype=_SCREAMING_SNAKE_CASE							)]      ,       dim=1							)
        __lowercase									=	[
            (torch.zeros(_SCREAMING_SNAKE_CASE							), torch.zeros(_SCREAMING_SNAKE_CASE							)) for _ in range(_SCREAMING_SNAKE_CASE							)
        ]
       return common_inputs
      def SCREAMING_SNAKE_CASE_	(		self	:	Union[str, Any]      ,       A_	:	Optional[Any]      ,       A_	:	Any = -1      ,       A_	:	Optional[Any] = -1      ,       A_	:	Optional[Any] = False      ,       A_	:	List[Any] = None      ,       ):






       '''simple docstring'''


       __lowercase									=	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
       __lowercase									=	tokenizer.num_special_tokens_to_add(_SCREAMING_SNAKE_CASE							)
       __lowercase									=	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
       __lowercase									=	[""" """.join([tokenizer.unk_token]							) * seq_length] * batch_size
       __lowercase									=	dict(tokenizer(_SCREAMING_SNAKE_CASE      ,       return_tensors=_SCREAMING_SNAKE_CASE							)							)
       return common_inputs
      def SCREAMING_SNAKE_CASE_	(		self	:	str      ,       A_	:	List[Any]      ,       A_	:	Union[str, Any] = -1      ,       A_	:	Optional[int] = -1      ,       A_	:	List[Any] = False      ,       A_	:	str = None      ,       ):






       '''simple docstring'''


       if self.task in ["default", "seq2seq-lm"]:
        __lowercase									=	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:
        __lowercase									=	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	:	List[Any]      ,       A_	:	Tuple      ,       A_	:	Optional[Any]      ,       A_	:	Union[str, Any]      ,       A_	:	List[str]							):






       '''simple docstring'''


       if self.task in ["default", "seq2seq-lm"]:
        __lowercase									=	super()._flatten_past_key_values_(_SCREAMING_SNAKE_CASE      ,       _SCREAMING_SNAKE_CASE      ,       _SCREAMING_SNAKE_CASE      ,       _SCREAMING_SNAKE_CASE							)
       else:
        __lowercase									=	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	:	List[str]							):






       '''simple docstring'''


       return 1e-4




"""simple docstring"""

import warnings
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCAmelCase__  							=logging.get_logger(__name__)

UpperCAmelCase__  							={
    "nvidia/segformer-b0-finetuned-ade-512-512": (
        "https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json"
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}





class    lowerCamelCase__						(		_a    ):
      a :     Optional[int]											=		"""segformer"""
      def __init__(		self	:	str      ,       A_	:	Optional[int]=3      ,       A_	:	Any=4      ,       A_	:	Optional[int]=[2, 2, 2, 2]      ,       A_	:	str=[8, 4, 2, 1]      ,       A_	:	Any=[3_2, 6_4, 1_6_0, 2_5_6]      ,       A_	:	Union[str, Any]=[7, 3, 3, 3]      ,       A_	:	Any=[4, 2, 2, 2]      ,       A_	:	int=[1, 2, 5, 8]      ,       A_	:	Union[str, Any]=[4, 4, 4, 4]      ,       A_	:	Optional[Any]="gelu"      ,       A_	:	List[str]=0.0      ,       A_	:	Any=0.0      ,       A_	:	Optional[Any]=0.1      ,       A_	:	List[str]=0.02      ,       A_	:	Tuple=0.1      ,       A_	:	Optional[Any]=1e-6      ,       A_	:	Optional[int]=2_5_6      ,       A_	:	Optional[Any]=2_5_5      ,       **A_	:	Union[str, Any]      ,       ):






       '''simple docstring'''


       super().__init__(**A_							)

       if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
        warnings.warn(
            """Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be"""
            """ removed, as the behaviour will default to that of reshape_last_stage = True."""      ,       A_      ,       )

       __lowercase									=	num_channels
       __lowercase									=	num_encoder_blocks
       __lowercase									=	depths
       __lowercase									=	sr_ratios
       __lowercase									=	hidden_sizes
       __lowercase									=	patch_sizes
       __lowercase									=	strides
       __lowercase									=	mlp_ratios
       __lowercase									=	num_attention_heads
       __lowercase									=	hidden_act
       __lowercase									=	hidden_dropout_prob
       __lowercase									=	attention_probs_dropout_prob
       __lowercase									=	classifier_dropout_prob
       __lowercase									=	initializer_range
       __lowercase									=	drop_path_rate
       __lowercase									=	layer_norm_eps
       __lowercase									=	decoder_hidden_size
       __lowercase									=	kwargs.get("""reshape_last_stage"""      ,       A_							)
       __lowercase									=	semantic_loss_ignore_index






class    lowerCamelCase__						(		_a    ):
      a :     List[str]											=		version.parse("""1.11"""    )
      @property
      def SCREAMING_SNAKE_CASE_	(		self	:	Any							):






       '''simple docstring'''


       return OrderedDict(
           [
               ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
           ]							)
      @property
      def SCREAMING_SNAKE_CASE_	(		self	:	int							):






       '''simple docstring'''


       return 1e-4






      @property
      def SCREAMING_SNAKE_CASE_	(		self	:	int							):






       '''simple docstring'''


       return 1_2
