


"""simple docstring"""





import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow


if is_torch_available():
  import torch

  from transformers import XLMRobertaModel
@require_sentencepiece
@require_tokenizers
@require_torch
class    __lowerCamelCase    (  unittest.TestCase  ):

   @slow
   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       List[str]:
       UpperCamelCase__         =    XLMRobertaModel.from_pretrained('xlm-roberta-base'      )
       UpperCamelCase__         =    torch.tensor([[0, 581, 1_0269, 83, 9_9942, 136, 6_0742, 23, 70, 8_0583, 1_8276, 2]]      )
       # The dog is cute and lives in the garden house

       UpperCamelCase__         =    torch.Size((1, 12, 768)      )  # batch_size, sequence_length, embedding_vector_dim
       UpperCamelCase__         =    torch.tensor(
           [[-0.0_101, 0.1_218, -0.0_803, 0.0_801, 0.1_327, 0.0_776, -0.1_215, 0.2_383, 0.3_338, 0.3_106, 0.0_300, 0.0_252]]      )
       #  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.base')
       #  xlmr.eval()
       #  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
       with torch.no_grad():
           UpperCamelCase__         =    model(snake_case_      )['last_hidden_state'].detach()
       self.assertEqual(output.shape ,				snake_case_      )
       # compare the actual values for a slice of last dim
       self.assertTrue(torch.allclose(output[:, :, -1] ,				snake_case_ ,				atol=1E-3      )      )







   @slow
   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Any:
       UpperCamelCase__         =    XLMRobertaModel.from_pretrained('xlm-roberta-large'      )
       UpperCamelCase__         =    torch.tensor([[0, 581, 1_0269, 83, 9_9942, 136, 6_0742, 23, 70, 8_0583, 1_8276, 2]]      )
       # The dog is cute and lives in the garden house

       UpperCamelCase__         =    torch.Size((1, 12, 1024)      )  # batch_size, sequence_length, embedding_vector_dim
       UpperCamelCase__         =    torch.tensor(
           [[-0.0_699, -0.0_318, 0.0_705, -0.1_241, 0.0_999, -0.0_520, 0.1_004, -0.1_838, -0.4_704, 0.1_437, 0.0_821, 0.0_126]]      )
       #  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.large')
       #  xlmr.eval()
       #  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
       with torch.no_grad():
           UpperCamelCase__         =    model(snake_case_      )['last_hidden_state'].detach()
       self.assertEqual(output.shape ,				snake_case_      )
       # compare the actual values for a slice of last dim
       self.assertTrue(torch.allclose(output[:, :, -1] ,				snake_case_ ,				atol=1E-3      )      )












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


A__					: str=	logging.get_logger(__name__)

A__					: List[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    __lowerCamelCase    (  _a  ):
   a      :				Any 						="""segformer"""

   def __init__(					self ,				snake_case_=3 ,				snake_case_=4 ,				snake_case_=[2, 2, 2, 2] ,				snake_case_=[8, 4, 2, 1] ,				snake_case_=[32, 64, 160, 256] ,				snake_case_=[7, 3, 3, 3] ,				snake_case_=[4, 2, 2, 2] ,				snake_case_=[1, 2, 5, 8] ,				snake_case_=[4, 4, 4, 4] ,				snake_case_="gelu" ,				snake_case_=0.0 ,				snake_case_=0.0 ,				snake_case_=0.1 ,				snake_case_=0.02 ,				snake_case_=0.1 ,				snake_case_=1E-6 ,				snake_case_=256 ,				snake_case_=255 ,				**snake_case_ ,				)		->       Tuple:
       super().__init__(**snake_case_      )

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

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







class    __lowerCamelCase    (  _a  ):
   a      :				Any 						=version.parse("""1.11"""  )

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

   @property
   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       float:
       return 1E-4







   @property
   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       int:
       return 12




