


'''simple docstring'''




import unittest

import numpy as np

from transformers.testing_utils import require_flax, require_tf, require_torch
from transformers.utils import (
    expand_dims,
    flatten_dict,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    reshape,
    squeeze,
    transpose,
)


if is_flax_available():
 import jax.numpy as jnp

if is_tf_available():
 import tensorflow as tf

if is_torch_available():
 import torch







class 					a			(				unittest.TestCase  ):
 '''simple docstring'''




 def   __UpperCamelCase   (    self      )      ->    Any:
    _a					:  Dict						=  {
        'task_specific_params': {
            'summarization': {'length_penalty': 1.0, 'max_length': 1_2_8, 'min_length': 1_2, 'num_beams': 4},
            'summarization_cnn': {'length_penalty': 2.0, 'max_length': 1_4_2, 'min_length': 5_6, 'num_beams': 4},
            'summarization_xsum': {'length_penalty': 1.0, 'max_length': 6_2, 'min_length': 1_1, 'num_beams': 6},
        }
    }
    _a					:  str						=  {
        'task_specific_params.summarization.length_penalty': 1.0,
        'task_specific_params.summarization.max_length': 1_2_8,
        'task_specific_params.summarization.min_length': 1_2,
        'task_specific_params.summarization.num_beams': 4,
        'task_specific_params.summarization_cnn.length_penalty': 2.0,
        'task_specific_params.summarization_cnn.max_length': 1_4_2,
        'task_specific_params.summarization_cnn.min_length': 5_6,
        'task_specific_params.summarization_cnn.num_beams': 4,
        'task_specific_params.summarization_xsum.length_penalty': 1.0,
        'task_specific_params.summarization_xsum.max_length': 6_2,
        'task_specific_params.summarization_xsum.min_length': 1_1,
        'task_specific_params.summarization_xsum.num_beams': 6,
    }

    self.assertEqual(flatten_dict(lowerCamelCase_      )		,      lowerCamelCase_      )




 def   __UpperCamelCase   (    self      )      ->    Optional[Any]:
    _a					:  Any						=  np.random.randn(3		,      4      )
    self.assertTrue(np.allclose(transpose(lowerCamelCase_      )		,      x.transpose()      )      )

    _a					:  Dict						=  np.random.randn(3		,      4		,      5      )
    self.assertTrue(np.allclose(transpose(lowerCamelCase_		,      axes=(1, 2, 0)      )		,      x.transpose((1, 2, 0)      )      )      )




 @require_torch
 def   __UpperCamelCase   (    self      )      ->    Any:
    _a					:  Optional[int]						=  np.random.randn(3		,      4      )
    _a					:  List[Any]						=  torch.tensor(lowerCamelCase_      )
    self.assertTrue(np.allclose(transpose(lowerCamelCase_      )		,      transpose(lowerCamelCase_      ).numpy()      )      )

    _a					:  List[str]						=  np.random.randn(3		,      4		,      5      )
    _a					:  List[Any]						=  torch.tensor(lowerCamelCase_      )
    self.assertTrue(np.allclose(transpose(lowerCamelCase_		,      axes=(1, 2, 0)      )		,      transpose(lowerCamelCase_		,      axes=(1, 2, 0)      ).numpy()      )      )




 @require_tf
 def   __UpperCamelCase   (    self      )      ->    Dict:
    _a					:  Dict						=  np.random.randn(3		,      4      )
    _a					:  Optional[int]						=  tf.constant(lowerCamelCase_      )
    self.assertTrue(np.allclose(transpose(lowerCamelCase_      )		,      transpose(lowerCamelCase_      ).numpy()      )      )

    _a					:  Optional[int]						=  np.random.randn(3		,      4		,      5      )
    _a					:  Optional[int]						=  tf.constant(lowerCamelCase_      )
    self.assertTrue(np.allclose(transpose(lowerCamelCase_		,      axes=(1, 2, 0)      )		,      transpose(lowerCamelCase_		,      axes=(1, 2, 0)      ).numpy()      )      )




 @require_flax
 def   __UpperCamelCase   (    self      )      ->    int:
    _a					:  Tuple						=  np.random.randn(3		,      4      )
    _a					:  str						=  jnp.array(lowerCamelCase_      )
    self.assertTrue(np.allclose(transpose(lowerCamelCase_      )		,      np.asarray(transpose(lowerCamelCase_      )      )      )      )

    _a					:  Optional[int]						=  np.random.randn(3		,      4		,      5      )
    _a					:  Optional[int]						=  jnp.array(lowerCamelCase_      )
    self.assertTrue(np.allclose(transpose(lowerCamelCase_		,      axes=(1, 2, 0)      )		,      np.asarray(transpose(lowerCamelCase_		,      axes=(1, 2, 0)      )      )      )      )




 def   __UpperCamelCase   (    self      )      ->    int:
    _a					:  Dict						=  np.random.randn(3		,      4      )
    self.assertTrue(np.allclose(reshape(lowerCamelCase_		,      (4, 3)      )		,      np.reshape(lowerCamelCase_		,      (4, 3)      )      )      )

    _a					:  Any						=  np.random.randn(3		,      4		,      5      )
    self.assertTrue(np.allclose(reshape(lowerCamelCase_		,      (1_2, 5)      )		,      np.reshape(lowerCamelCase_		,      (1_2, 5)      )      )      )




 @require_torch
 def   __UpperCamelCase   (    self      )      ->    Any:
    _a					:  Optional[int]						=  np.random.randn(3		,      4      )
    _a					:  Tuple						=  torch.tensor(lowerCamelCase_      )
    self.assertTrue(np.allclose(reshape(lowerCamelCase_		,      (4, 3)      )		,      reshape(lowerCamelCase_		,      (4, 3)      ).numpy()      )      )

    _a					:  Tuple						=  np.random.randn(3		,      4		,      5      )
    _a					:  List[str]						=  torch.tensor(lowerCamelCase_      )
    self.assertTrue(np.allclose(reshape(lowerCamelCase_		,      (1_2, 5)      )		,      reshape(lowerCamelCase_		,      (1_2, 5)      ).numpy()      )      )




 @require_tf
 def   __UpperCamelCase   (    self      )      ->    Optional[int]:
    _a					:  List[Any]						=  np.random.randn(3		,      4      )
    _a					:  Optional[int]						=  tf.constant(lowerCamelCase_      )
    self.assertTrue(np.allclose(reshape(lowerCamelCase_		,      (4, 3)      )		,      reshape(lowerCamelCase_		,      (4, 3)      ).numpy()      )      )

    _a					:  Optional[int]						=  np.random.randn(3		,      4		,      5      )
    _a					:  str						=  tf.constant(lowerCamelCase_      )
    self.assertTrue(np.allclose(reshape(lowerCamelCase_		,      (1_2, 5)      )		,      reshape(lowerCamelCase_		,      (1_2, 5)      ).numpy()      )      )




 @require_flax
 def   __UpperCamelCase   (    self      )      ->    Optional[int]:
    _a					:  Union[str, Any]						=  np.random.randn(3		,      4      )
    _a					:  List[str]						=  jnp.array(lowerCamelCase_      )
    self.assertTrue(np.allclose(reshape(lowerCamelCase_		,      (4, 3)      )		,      np.asarray(reshape(lowerCamelCase_		,      (4, 3)      )      )      )      )

    _a					:  int						=  np.random.randn(3		,      4		,      5      )
    _a					:  List[Any]						=  jnp.array(lowerCamelCase_      )
    self.assertTrue(np.allclose(reshape(lowerCamelCase_		,      (1_2, 5)      )		,      np.asarray(reshape(lowerCamelCase_		,      (1_2, 5)      )      )      )      )




 def   __UpperCamelCase   (    self      )      ->    str:
    _a					:  Tuple						=  np.random.randn(1		,      3		,      4      )
    self.assertTrue(np.allclose(squeeze(lowerCamelCase_      )		,      np.squeeze(lowerCamelCase_      )      )      )

    _a					:  List[str]						=  np.random.randn(1		,      4		,      1		,      5      )
    self.assertTrue(np.allclose(squeeze(lowerCamelCase_		,      axis=2      )		,      np.squeeze(lowerCamelCase_		,      axis=2      )      )      )




 @require_torch
 def   __UpperCamelCase   (    self      )      ->    Any:
    _a					:  Dict						=  np.random.randn(1		,      3		,      4      )
    _a					:  str						=  torch.tensor(lowerCamelCase_      )
    self.assertTrue(np.allclose(squeeze(lowerCamelCase_      )		,      squeeze(lowerCamelCase_      ).numpy()      )      )

    _a					:  Optional[int]						=  np.random.randn(1		,      4		,      1		,      5      )
    _a					:  Optional[Any]						=  torch.tensor(lowerCamelCase_      )
    self.assertTrue(np.allclose(squeeze(lowerCamelCase_		,      axis=2      )		,      squeeze(lowerCamelCase_		,      axis=2      ).numpy()      )      )




 @require_tf
 def   __UpperCamelCase   (    self      )      ->    Union[str, Any]:
    _a					:  Tuple						=  np.random.randn(1		,      3		,      4      )
    _a					:  Tuple						=  tf.constant(lowerCamelCase_      )
    self.assertTrue(np.allclose(squeeze(lowerCamelCase_      )		,      squeeze(lowerCamelCase_      ).numpy()      )      )

    _a					:  List[Any]						=  np.random.randn(1		,      4		,      1		,      5      )
    _a					:  Any						=  tf.constant(lowerCamelCase_      )
    self.assertTrue(np.allclose(squeeze(lowerCamelCase_		,      axis=2      )		,      squeeze(lowerCamelCase_		,      axis=2      ).numpy()      )      )




 @require_flax
 def   __UpperCamelCase   (    self      )      ->    int:
    _a					:  str						=  np.random.randn(1		,      3		,      4      )
    _a					:  Optional[Any]						=  jnp.array(lowerCamelCase_      )
    self.assertTrue(np.allclose(squeeze(lowerCamelCase_      )		,      np.asarray(squeeze(lowerCamelCase_      )      )      )      )

    _a					:  int						=  np.random.randn(1		,      4		,      1		,      5      )
    _a					:  Union[str, Any]						=  jnp.array(lowerCamelCase_      )
    self.assertTrue(np.allclose(squeeze(lowerCamelCase_		,      axis=2      )		,      np.asarray(squeeze(lowerCamelCase_		,      axis=2      )      )      )      )




 def   __UpperCamelCase   (    self      )      ->    Optional[int]:
    _a					:  int						=  np.random.randn(3		,      4      )
    self.assertTrue(np.allclose(expand_dims(lowerCamelCase_		,      axis=1      )		,      np.expand_dims(lowerCamelCase_		,      axis=1      )      )      )




 @require_torch
 def   __UpperCamelCase   (    self      )      ->    List[str]:
    _a					:  str						=  np.random.randn(3		,      4      )
    _a					:  int						=  torch.tensor(lowerCamelCase_      )
    self.assertTrue(np.allclose(expand_dims(lowerCamelCase_		,      axis=1      )		,      expand_dims(lowerCamelCase_		,      axis=1      ).numpy()      )      )




 @require_tf
 def   __UpperCamelCase   (    self      )      ->    List[str]:
    _a					:  Optional[int]						=  np.random.randn(3		,      4      )
    _a					:  Union[str, Any]						=  tf.constant(lowerCamelCase_      )
    self.assertTrue(np.allclose(expand_dims(lowerCamelCase_		,      axis=1      )		,      expand_dims(lowerCamelCase_		,      axis=1      ).numpy()      )      )




 @require_flax
 def   __UpperCamelCase   (    self      )      ->    List[str]:
    _a					:  List[str]						=  np.random.randn(3		,      4      )
    _a					:  Optional[Any]						=  jnp.array(lowerCamelCase_      )
    self.assertTrue(np.allclose(expand_dims(lowerCamelCase_		,      axis=1      )		,      np.asarray(expand_dims(lowerCamelCase_		,      axis=1      )      )      )      )






'''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_      :		int          =		logging.get_logger(__name__)

UpperCAmelCase_      :		Optional[Any]          =		{
    "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 					a			(				snake_case__  ):
 '''simple docstring'''




 __lowerCAmelCase						: List[Any]							  =		"""segformer"""




 def __init__(    self		,      lowerCamelCase_=3		,      lowerCamelCase_=4		,      lowerCamelCase_=[2, 2, 2, 2]		,      lowerCamelCase_=[8, 4, 2, 1]		,      lowerCamelCase_=[3_2, 6_4, 1_6_0, 2_5_6]		,      lowerCamelCase_=[7, 3, 3, 3]		,      lowerCamelCase_=[4, 2, 2, 2]		,      lowerCamelCase_=[1, 2, 5, 8]		,      lowerCamelCase_=[4, 4, 4, 4]		,      lowerCamelCase_="gelu"		,      lowerCamelCase_=0.0		,      lowerCamelCase_=0.0		,      lowerCamelCase_=0.1		,      lowerCamelCase_=0.02		,      lowerCamelCase_=0.1		,      lowerCamelCase_=1e-6		,      lowerCamelCase_=2_5_6		,      lowerCamelCase_=2_5_5		,      **lowerCamelCase_		,      )      ->    Union[str, Any]:
    super().__init__(**lowerCamelCase_      )

    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.'		,      lowerCamelCase_		,      )

    _a					:  Union[str, Any]						=  num_channels
    _a					:  Any						=  num_encoder_blocks
    _a					:  Union[str, Any]						=  depths
    _a					:  int						=  sr_ratios
    _a					:  List[str]						=  hidden_sizes
    _a					:  Tuple						=  patch_sizes
    _a					:  Any						=  strides
    _a					:  List[Any]						=  mlp_ratios
    _a					:  str						=  num_attention_heads
    _a					:  str						=  hidden_act
    _a					:  List[Any]						=  hidden_dropout_prob
    _a					:  int						=  attention_probs_dropout_prob
    _a					:  Any						=  classifier_dropout_prob
    _a					:  Optional[Any]						=  initializer_range
    _a					:  int						=  drop_path_rate
    _a					:  int						=  layer_norm_eps
    _a					:  Optional[Any]						=  decoder_hidden_size
    _a					:  int						=  kwargs.get('reshape_last_stage'		,      lowerCamelCase_      )
    _a					:  str						=  semantic_loss_ignore_index







class 					a			(				snake_case__  ):
 '''simple docstring'''




 __lowerCAmelCase						: Any							  =		version.parse("""1.11"""  )




 @property
 def   __UpperCamelCase   (    self      )      ->    Mapping[str, Mapping[int, str]]:
    return OrderedDict(
        [
            ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
        ]      )




 @property
 def   __UpperCamelCase   (    self      )      ->    float:
    return 1e-4




 @property
 def   __UpperCamelCase   (    self      )      ->    int:
    return 1_2


