





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   A      (unittest.TestCase   ):
   '''simple docstring'''




   @slow
   def        a_	(      self       :   Any       )     ->     Any:







     """simple docstring"""






     A__  				=       XLMRobertaModel.from_pretrained("""xlm-roberta-base"""       )
     A__  				=       torch.tensor([[0, 5_81, 1_02_69, 83, 9_99_42, 1_36, 6_07_42, 23, 70, 8_05_83, 1_82_76, 2]]       )
     # The dog is cute and lives in the garden house

     A__  				=       torch.Size((1, 12, 7_68)       )  # batch_size, sequence_length, embedding_vector_dim
     A__  				=       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():
       A__  				=       model(A__       )["""last_hidden_state"""].detach()
     self.assertEqual(output.shape							,     A__       )
     # compare the actual values for a slice of last dim
     self.assertTrue(torch.allclose(output[:, :, -1]							,     A__							,     atol=1e-3       )       )







   @slow
   def        a_	(      self       :   List[str]       )     ->     str:







     """simple docstring"""






     A__  				=       XLMRobertaModel.from_pretrained("""xlm-roberta-large"""       )
     A__  				=       torch.tensor([[0, 5_81, 1_02_69, 83, 9_99_42, 1_36, 6_07_42, 23, 70, 8_05_83, 1_82_76, 2]]       )
     # The dog is cute and lives in the garden house

     A__  				=       torch.Size((1, 12, 10_24)       )  # batch_size, sequence_length, embedding_vector_dim
     A__  				=       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():
       A__  				=       model(A__       )["""last_hidden_state"""].detach()
     self.assertEqual(output.shape							,     A__       )
     # compare the actual values for a slice of last dim
     self.assertTrue(torch.allclose(output[:, :, -1]							,     A__							,     atol=1e-3       )       )










from ...configuration_utils import PretrainedConfig
from ...utils import logging


A   : Dict			=				logging.get_logger(__name__)

A   : Dict			=				{
    '''google/pegasus-large''': '''https://huggingface.co/google/pegasus-large/resolve/main/config.json''',
    # See all PEGASUS models at https://huggingface.co/models?filter=pegasus
}


class   A      (SCREAMING_SNAKE_CASE   ):
			'''simple docstring'''




			__lowerCamelCase     :	Tuple          =   '''pegasus'''
			__lowerCamelCase     :	Any          =   ['''past_key_values''']
			__lowerCamelCase     :	List[str]          =   {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}






			def __init__(      self       :   List[Any]							,     __lowerCAmelCase       :   str=5_02_65							,     __lowerCAmelCase       :   Dict=10_24							,     __lowerCAmelCase       :   Union[str, Any]=12							,     __lowerCAmelCase       :   Any=40_96							,     __lowerCAmelCase       :   Optional[Any]=16							,     __lowerCAmelCase       :   Dict=12							,     __lowerCAmelCase       :   Optional[int]=40_96							,     __lowerCAmelCase       :   Dict=16							,     __lowerCAmelCase       :   Optional[int]=0.0							,     __lowerCAmelCase       :   Optional[Any]=0.0							,     __lowerCAmelCase       :   Union[str, Any]=True							,     __lowerCAmelCase       :   List[str]=True							,     __lowerCAmelCase       :   str="gelu"							,     __lowerCAmelCase       :   Union[str, Any]=10_24							,     __lowerCAmelCase       :   Union[str, Any]=0.1							,     __lowerCAmelCase       :   Dict=0.0							,     __lowerCAmelCase       :   Union[str, Any]=0.0							,     __lowerCAmelCase       :   Union[str, Any]=0.0_2							,     __lowerCAmelCase       :   List[Any]=0							,     __lowerCAmelCase       :   str=False							,     __lowerCAmelCase       :   int=0							,     __lowerCAmelCase       :   Optional[Any]=1							,     __lowerCAmelCase       :   Optional[int]=1							,     **__lowerCAmelCase       :   Dict							,     )     ->     Dict:







					"""simple docstring"""






					A__  				=       vocab_size
					A__  				=       max_position_embeddings
					A__  				=       d_model
					A__  				=       encoder_ffn_dim
					A__  				=       encoder_layers
					A__  				=       encoder_attention_heads
					A__  				=       decoder_ffn_dim
					A__  				=       decoder_layers
					A__  				=       decoder_attention_heads
					A__  				=       dropout
					A__  				=       attention_dropout
					A__  				=       activation_dropout
					A__  				=       activation_function
					A__  				=       init_std
					A__  				=       encoder_layerdrop
					A__  				=       decoder_layerdrop
					A__  				=       use_cache
					A__  				=       encoder_layers
					A__  				=       scale_embedding  # scale factor will be sqrt(d_model) if True
					super().__init__(
					    pad_token_id=__lowerCAmelCase							,     eos_token_id=__lowerCAmelCase							,     is_encoder_decoder=__lowerCAmelCase							,     decoder_start_token_id=__lowerCAmelCase							,     forced_eos_token_id=__lowerCAmelCase							,     **__lowerCAmelCase							,     )






			@property
			def        a_	(      self       :   Dict       )     ->     int:







					"""simple docstring"""






					return self.encoder_attention_heads







			@property
			def        a_	(      self       :   Optional[Any]       )     ->     int:







					"""simple docstring"""






					return self.d_model



