



'''simple docstring'''





from collections import OrderedDict
from typing import Mapping

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


_lowerCAmelCase      						=	logging.get_logger(__name__)

_lowerCAmelCase      						=	{
    '''facebook/xlm-roberta-xl''': '''https://huggingface.co/facebook/xlm-roberta-xl/resolve/main/config.json''',
    '''facebook/xlm-roberta-xxl''': '''https://huggingface.co/facebook/xlm-roberta-xxl/resolve/main/config.json''',
    # See all XLM-RoBERTa-XL models at https://huggingface.co/models?filter=xlm-roberta-xl
}






class        lowerCAmelCase_(				SCREAMING_SNAKE_CASE_     ):
  '''simple docstring'''




  __lowercase							:      int				=      '''xlm-roberta-xl'''




  def __init__(    self  ,__UpperCAmelCase=25_0880  ,__UpperCAmelCase=2560  ,__UpperCAmelCase=36  ,__UpperCAmelCase=32  ,__UpperCAmelCase=1_0240  ,__UpperCAmelCase="gelu"  ,__UpperCAmelCase=0.1  ,__UpperCAmelCase=0.1  ,__UpperCAmelCase=514  ,__UpperCAmelCase=1  ,__UpperCAmelCase=0.0_2  ,__UpperCAmelCase=1E-05  ,__UpperCAmelCase=1  ,__UpperCAmelCase=0  ,__UpperCAmelCase=2  ,__UpperCAmelCase="absolute"  ,__UpperCAmelCase=True  ,__UpperCAmelCase=None  ,**__UpperCAmelCase  ,)    ->		str:
      super().__init__(pad_token_id=__UpperCAmelCase  ,bos_token_id=__UpperCAmelCase  ,eos_token_id=__UpperCAmelCase  ,**__UpperCAmelCase      )
      lowerCAmelCase__ :  List[Any]							      =					vocab_size
      lowerCAmelCase__ :  int							      =					hidden_size
      lowerCAmelCase__ :  int							      =					num_hidden_layers
      lowerCAmelCase__ :  str							      =					num_attention_heads
      lowerCAmelCase__ :  int							      =					hidden_act
      lowerCAmelCase__ :  Dict							      =					intermediate_size
      lowerCAmelCase__ :  List[Any]							      =					hidden_dropout_prob
      lowerCAmelCase__ :  str							      =					attention_probs_dropout_prob
      lowerCAmelCase__ :  Optional[int]							      =					max_position_embeddings
      lowerCAmelCase__ :  List[str]							      =					type_vocab_size
      lowerCAmelCase__ :  List[Any]							      =					initializer_range
      lowerCAmelCase__ :  Tuple							      =					layer_norm_eps
      lowerCAmelCase__ :  int							      =					position_embedding_type
      lowerCAmelCase__ :  Optional[Any]							      =					use_cache
      lowerCAmelCase__ :  Optional[Any]							      =					classifier_dropout







class        lowerCAmelCase_(				SCREAMING_SNAKE_CASE_     ):
  '''simple docstring'''




  @property
  def 							UpperCAmelCase_	(    self      )    ->		Mapping[str, Mapping[int, str]]:
      if self.task == "multiple-choice":
          lowerCAmelCase__ :  Dict							      =					{0: """batch""", 1: """choice""", 2: """sequence"""}
      else:
          lowerCAmelCase__ :  Any							      =					{0: """batch""", 1: """sequence"""}
      return OrderedDict(
          [
              ("""input_ids""", dynamic_axis),
              ("""attention_mask""", dynamic_axis),
          ]      )







'''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     ):
  '''simple docstring'''




  @slow
  def 							UpperCAmelCase_	(    self      )    ->		Union[str, Any]:
      lowerCAmelCase__ :  Tuple							      =					XLMRobertaModel.from_pretrained("""xlm-roberta-base"""      )
      lowerCAmelCase__ :  Optional[int]							      =					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

      lowerCAmelCase__ :  str							      =					torch.Size((1, 12, 768)      )  # batch_size, sequence_length, embedding_vector_dim
      lowerCAmelCase__ :  Dict							      =					torch.tensor(
          [[-0.0_1_0_1, 0.1_2_1_8, -0.0_8_0_3, 0.0_8_0_1, 0.1_3_2_7, 0.0_7_7_6, -0.1_2_1_5, 0.2_3_8_3, 0.3_3_3_8, 0.3_1_0_6, 0.0_3_0_0, 0.0_2_5_2]]      )
      #  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():
          lowerCAmelCase__ :  Optional[int]							      =					model(__UpperCAmelCase      )["""last_hidden_state"""].detach()
      self.assertEqual(output.shape  ,__UpperCAmelCase      )
      # compare the actual values for a slice of last dim
      self.assertTrue(torch.allclose(output[:, :, -1]  ,__UpperCAmelCase  ,atol=1E-3      )      )






  @slow
  def 							UpperCAmelCase_	(    self      )    ->		int:
      lowerCAmelCase__ :  Union[str, Any]							      =					XLMRobertaModel.from_pretrained("""xlm-roberta-large"""      )
      lowerCAmelCase__ :  Optional[Any]							      =					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

      lowerCAmelCase__ :  Dict							      =					torch.Size((1, 12, 1024)      )  # batch_size, sequence_length, embedding_vector_dim
      lowerCAmelCase__ :  Union[str, Any]							      =					torch.tensor(
          [[-0.0_6_9_9, -0.0_3_1_8, 0.0_7_0_5, -0.1_2_4_1, 0.0_9_9_9, -0.0_5_2_0, 0.1_0_0_4, -0.1_8_3_8, -0.4_7_0_4, 0.1_4_3_7, 0.0_8_2_1, 0.0_1_2_6]]      )
      #  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():
          lowerCAmelCase__ :  Union[str, Any]							      =					model(__UpperCAmelCase      )["""last_hidden_state"""].detach()
      self.assertEqual(output.shape  ,__UpperCAmelCase      )
      # compare the actual values for a slice of last dim
      self.assertTrue(torch.allclose(output[:, :, -1]  ,__UpperCAmelCase  ,atol=1E-3      )      )


