





'''simple docstring'''







import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    RemBertConfig,
					    RemBertForCausalLM,
					    RemBertForMaskedLM,
					    RemBertForMultipleChoice,
					    RemBertForQuestionAnswering,
					    RemBertForSequenceClassification,
					    RemBertForTokenClassification,
					    RemBertModel,
					)
					from transformers.models.rembert.modeling_rembert import REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST


class        __a   :

							def __init__(				self				:  Tuple							,  __magic_name__				:  List[str]							,  __magic_name__				:  Optional[int]=13							,  __magic_name__				:  Tuple=7							,  __magic_name__				:  Union[str, Any]=True							,  __magic_name__				:  Dict=True							,  __magic_name__				:  Union[str, Any]=True							,  __magic_name__				:  Union[str, Any]=True							,  __magic_name__				:  Union[str, Any]=99							,  __magic_name__				:  int=32							,  __magic_name__				:  Optional[int]=18							,  __magic_name__				:  List[str]=43							,  __magic_name__				:  Tuple=5							,  __magic_name__				:  Any=4							,  __magic_name__				:  Tuple=37							,  __magic_name__				:  Optional[Any]="gelu"							,  __magic_name__				:  Any=0.1							,  __magic_name__				:  Optional[Any]=0.1							,  __magic_name__				:  Any=5_12							,  __magic_name__				:  str=16							,  __magic_name__				:  Union[str, Any]=2							,  __magic_name__				:  Optional[Any]=0.0_2							,  __magic_name__				:  List[Any]=3							,  __magic_name__				:  Optional[int]=4							,  __magic_name__				:  List[Any]=None							,  )       ->							Any:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[int]      =	parent
													UpperCAmelCase_      :   List[Any]      =	batch_size
													UpperCAmelCase_      :   List[str]      =	seq_length
													UpperCAmelCase_      :   Dict      =	is_training
													UpperCAmelCase_      :   Union[str, Any]      =	use_input_mask
													UpperCAmelCase_      :   Union[str, Any]      =	use_token_type_ids
													UpperCAmelCase_      :   Dict      =	use_labels
													UpperCAmelCase_      :   Any      =	vocab_size
													UpperCAmelCase_      :   Any      =	hidden_size
													UpperCAmelCase_      :   List[str]      =	input_embedding_size
													UpperCAmelCase_      :   Union[str, Any]      =	output_embedding_size
													UpperCAmelCase_      :   Optional[Any]      =	num_hidden_layers
													UpperCAmelCase_      :   int      =	num_attention_heads
													UpperCAmelCase_      :   str      =	intermediate_size
													UpperCAmelCase_      :   Optional[Any]      =	hidden_act
													UpperCAmelCase_      :   Optional[Any]      =	hidden_dropout_prob
													UpperCAmelCase_      :   Optional[Any]      =	attention_probs_dropout_prob
													UpperCAmelCase_      :   Optional[int]      =	max_position_embeddings
													UpperCAmelCase_      :   Tuple      =	type_vocab_size
													UpperCAmelCase_      :   Tuple      =	type_sequence_label_size
													UpperCAmelCase_      :   Tuple      =	initializer_range
													UpperCAmelCase_      :   Union[str, Any]      =	num_labels
													UpperCAmelCase_      :   int      =	num_choices
													UpperCAmelCase_      :   Union[str, Any]      =	scope

							def      UpperCAmelCase__						(				self				:  List[Any] )       ->							str:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	ids_tensor([self.batch_size, self.seq_length]							,  self.vocab_size )

													UpperCAmelCase_      :   Union[str, Any]      =	None
													if self.use_input_mask:
																			UpperCAmelCase_      :   Tuple      =	random_attention_mask([self.batch_size, self.seq_length] )

													UpperCAmelCase_      :   Dict      =	None
													if self.use_token_type_ids:
																			UpperCAmelCase_      :   Optional[Any]      =	ids_tensor([self.batch_size, self.seq_length]							,  self.type_vocab_size )

													UpperCAmelCase_      :   str      =	None
													UpperCAmelCase_      :   Any      =	None
													UpperCAmelCase_      :   Dict      =	None
													if self.use_labels:
																			UpperCAmelCase_      :   List[str]      =	ids_tensor([self.batch_size]							,  self.type_sequence_label_size )
																			UpperCAmelCase_      :   Union[str, Any]      =	ids_tensor([self.batch_size, self.seq_length]							,  self.num_labels )
																			UpperCAmelCase_      :   Any      =	ids_tensor([self.batch_size]							,  self.num_choices )

													UpperCAmelCase_      :   Any      =	RemBertConfig(
													    vocab_size=self.vocab_size							,  hidden_size=self.hidden_size							,  input_embedding_size=self.input_embedding_size							,  output_embedding_size=self.output_embedding_size							,  num_hidden_layers=self.num_hidden_layers							,  num_attention_heads=self.num_attention_heads							,  intermediate_size=self.intermediate_size							,  hidden_act=self.hidden_act							,  hidden_dropout_prob=self.hidden_dropout_prob							,  attention_probs_dropout_prob=self.attention_probs_dropout_prob							,  max_position_embeddings=self.max_position_embeddings							,  type_vocab_size=self.type_vocab_size							,  is_decoder=lowerCAmelCase__							,  initializer_range=self.initializer_range							,  )

													return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

							def      UpperCAmelCase__						(				self				:  Optional[int] )       ->							List[Any]:







													"""simple docstring"""
													(
													    UpperCAmelCase_      
													)      :   Tuple      =	self.prepare_config_and_inputs()

													UpperCAmelCase_      :   List[str]      =	True
													UpperCAmelCase_      :   Tuple      =	floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
													UpperCAmelCase_      :   Optional[Any]      =	ids_tensor([self.batch_size, self.seq_length]							,  vocab_size=2 )

													return (
													    config,
													    input_ids,
													    token_type_ids,
													    input_mask,
													    sequence_labels,
													    token_labels,
													    choice_labels,
													    encoder_hidden_states,
													    encoder_attention_mask,
													)

							def      UpperCAmelCase__						(				self				:  List[Any]							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  Any							,  __magic_name__				:  Optional[Any]							,  __magic_name__				:  List[Any]							,  __magic_name__				:  Dict							,  __magic_name__				:  List[str]							,  __magic_name__				:  Union[str, Any] )       ->							int:







													"""simple docstring"""
													UpperCAmelCase_      :   List[str]      =	RemBertModel(config=lowerCAmelCase__ )
													model.to(lowerCAmelCase__ )
													model.eval()
													UpperCAmelCase_      :   Optional[int]      =	model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__ )
													UpperCAmelCase_      :   List[Any]      =	model(lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__ )
													UpperCAmelCase_      :   List[Any]      =	model(lowerCAmelCase__ )
													self.parent.assertEqual(result.last_hidden_state.shape							,  (self.batch_size, self.seq_length, self.hidden_size) )

							def      UpperCAmelCase__						(				self				:  Optional[Any]							,  __magic_name__				:  List[str]							,  __magic_name__				:  Optional[Any]							,  __magic_name__				:  Dict							,  __magic_name__				:  int							,  __magic_name__				:  str							,  __magic_name__				:  Dict							,  __magic_name__				:  Tuple							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  Optional[Any]							,  )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[int]      =	True
													UpperCAmelCase_      :   Any      =	RemBertModel(lowerCAmelCase__ )
													model.to(lowerCAmelCase__ )
													model.eval()
													UpperCAmelCase_      :   Optional[Any]      =	model(
													    lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__							,  encoder_hidden_states=lowerCAmelCase__							,  encoder_attention_mask=lowerCAmelCase__							,  )
													UpperCAmelCase_      :   Any      =	model(
													    lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__							,  encoder_hidden_states=lowerCAmelCase__							,  )
													UpperCAmelCase_      :   Optional[int]      =	model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__ )
													self.parent.assertEqual(result.last_hidden_state.shape							,  (self.batch_size, self.seq_length, self.hidden_size) )

							def      UpperCAmelCase__						(				self				:  int							,  __magic_name__				:  List[str]							,  __magic_name__				:  Tuple							,  __magic_name__				:  Any							,  __magic_name__				:  List[Any]							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  Tuple							,  __magic_name__				:  Any							,  __magic_name__				:  str							,  __magic_name__				:  Optional[Any]							,  )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   Dict      =	RemBertForCausalLM(config=lowerCAmelCase__ )
													model.to(lowerCAmelCase__ )
													model.eval()
													UpperCAmelCase_      :   Union[str, Any]      =	model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__							,  labels=lowerCAmelCase__ )
													self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.vocab_size) )

							def      UpperCAmelCase__						(				self				:  str							,  __magic_name__				:  List[Any]							,  __magic_name__				:  Optional[Any]							,  __magic_name__				:  Optional[int]							,  __magic_name__				:  Optional[Any]							,  __magic_name__				:  Tuple							,  __magic_name__				:  Any							,  __magic_name__				:  int )       ->							Dict:







													"""simple docstring"""
													UpperCAmelCase_      :   str      =	RemBertForMaskedLM(config=lowerCAmelCase__ )
													model.to(lowerCAmelCase__ )
													model.eval()
													UpperCAmelCase_      :   str      =	model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__							,  labels=lowerCAmelCase__ )
													self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.vocab_size) )

							def      UpperCAmelCase__						(				self				:  str							,  __magic_name__				:  Tuple							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  Optional[int]							,  __magic_name__				:  List[str]							,  __magic_name__				:  int							,  __magic_name__				:  Optional[int]							,  __magic_name__				:  Optional[int]							,  __magic_name__				:  Any							,  __magic_name__				:  List[str]							,  )       ->							Dict:







													"""simple docstring"""
													UpperCAmelCase_      :   int      =	True
													UpperCAmelCase_      :   Tuple      =	True
													UpperCAmelCase_      :   Union[str, Any]      =	RemBertForCausalLM(config=lowerCAmelCase__ )
													model.to(lowerCAmelCase__ )
													model.eval()

													# first forward pass
													UpperCAmelCase_      :   Optional[int]      =	model(
													    lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  encoder_hidden_states=lowerCAmelCase__							,  encoder_attention_mask=lowerCAmelCase__							,  use_cache=lowerCAmelCase__							,  )
													UpperCAmelCase_      :   Tuple      =	outputs.past_key_values

													# create hypothetical multiple next token and extent to next_input_ids
													UpperCAmelCase_      :   Dict      =	ids_tensor((self.batch_size, 3)							,  config.vocab_size )
													UpperCAmelCase_      :   List[Any]      =	ids_tensor((self.batch_size, 3)							,  vocab_size=2 )

													# append to next input_ids and
													UpperCAmelCase_      :   str      =	torch.cat([input_ids, next_tokens]							,  dim=-1 )
													UpperCAmelCase_      :   Optional[Any]      =	torch.cat([input_mask, next_mask]							,  dim=-1 )

													UpperCAmelCase_      :   int      =	model(
													    lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  encoder_hidden_states=lowerCAmelCase__							,  encoder_attention_mask=lowerCAmelCase__							,  output_hidden_states=lowerCAmelCase__							,  )["""hidden_states"""][0]
													UpperCAmelCase_      :   Optional[Any]      =	model(
													    lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  encoder_hidden_states=lowerCAmelCase__							,  encoder_attention_mask=lowerCAmelCase__							,  past_key_values=lowerCAmelCase__							,  output_hidden_states=lowerCAmelCase__							,  )["""hidden_states"""][0]

													# select random slice
													UpperCAmelCase_      :   List[str]      =	ids_tensor((1,)							,  output_from_past.shape[-1] ).item()
													UpperCAmelCase_      :   int      =	output_from_no_past[:, -3:, random_slice_idx].detach()
													UpperCAmelCase_      :   Dict      =	output_from_past[:, :, random_slice_idx].detach()

													self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1] )

													# test that outputs are equal for slice
													self.parent.assertTrue(torch.allclose(lowerCAmelCase__							,  lowerCAmelCase__							,  atol=1E-3 ) )

							def      UpperCAmelCase__						(				self				:  Optional[Any]							,  __magic_name__				:  Tuple							,  __magic_name__				:  Optional[int]							,  __magic_name__				:  Dict							,  __magic_name__				:  List[str]							,  __magic_name__				:  Tuple							,  __magic_name__				:  List[str]							,  __magic_name__				:  Optional[int] )       ->							Dict:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	RemBertForQuestionAnswering(config=lowerCAmelCase__ )
													model.to(lowerCAmelCase__ )
													model.eval()
													UpperCAmelCase_      :   List[str]      =	model(
													    lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__							,  start_positions=lowerCAmelCase__							,  end_positions=lowerCAmelCase__							,  )
													self.parent.assertEqual(result.start_logits.shape							,  (self.batch_size, self.seq_length) )
													self.parent.assertEqual(result.end_logits.shape							,  (self.batch_size, self.seq_length) )

							def      UpperCAmelCase__						(				self				:  Any							,  __magic_name__				:  Dict							,  __magic_name__				:  Dict							,  __magic_name__				:  str							,  __magic_name__				:  Dict							,  __magic_name__				:  Tuple							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  Union[str, Any] )       ->							str:







													"""simple docstring"""
													UpperCAmelCase_      :   str      =	self.num_labels
													UpperCAmelCase_      :   Optional[int]      =	RemBertForSequenceClassification(lowerCAmelCase__ )
													model.to(lowerCAmelCase__ )
													model.eval()
													UpperCAmelCase_      :   Tuple      =	model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__							,  labels=lowerCAmelCase__ )
													self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.num_labels) )

							def      UpperCAmelCase__						(				self				:  Tuple							,  __magic_name__				:  str							,  __magic_name__				:  Optional[int]							,  __magic_name__				:  Any							,  __magic_name__				:  List[str]							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  Optional[Any]							,  __magic_name__				:  List[str] )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	self.num_labels
													UpperCAmelCase_      :   Union[str, Any]      =	RemBertForTokenClassification(config=lowerCAmelCase__ )
													model.to(lowerCAmelCase__ )
													model.eval()
													UpperCAmelCase_      :   int      =	model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__							,  labels=lowerCAmelCase__ )
													self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.num_labels) )

							def      UpperCAmelCase__						(				self				:  Tuple							,  __magic_name__				:  Tuple							,  __magic_name__				:  int							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  int							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  str							,  __magic_name__				:  Optional[int] )       ->							int:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	self.num_choices
													UpperCAmelCase_      :   str      =	RemBertForMultipleChoice(config=lowerCAmelCase__ )
													model.to(lowerCAmelCase__ )
													model.eval()
													UpperCAmelCase_      :   List[Any]      =	input_ids.unsqueeze(1 ).expand(-1							,  self.num_choices							,  -1 ).contiguous()
													UpperCAmelCase_      :   List[Any]      =	token_type_ids.unsqueeze(1 ).expand(-1							,  self.num_choices							,  -1 ).contiguous()
													UpperCAmelCase_      :   Any      =	input_mask.unsqueeze(1 ).expand(-1							,  self.num_choices							,  -1 ).contiguous()
													UpperCAmelCase_      :   List[Any]      =	model(
													    lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__							,  labels=lowerCAmelCase__							,  )
													self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.num_choices) )



							def      UpperCAmelCase__						(				self				:  Optional[Any] )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   Union[str, Any]      =	self.prepare_config_and_inputs()
													(
													    UpperCAmelCase_      
													)      :   str      =	config_and_inputs
													UpperCAmelCase_      :   List[Any]      =	{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
													return config, inputs_dict





@require_torch
class        __a   (__snake_case							,		__snake_case							,		unittest.TestCase  ):
							__a       : Any          =							(
							    (
							        RemBertModel,
							        RemBertForMaskedLM,
							        RemBertForCausalLM,
							        RemBertForMultipleChoice,
							        RemBertForQuestionAnswering,
							        RemBertForSequenceClassification,
							        RemBertForTokenClassification,
							    )
							    if is_torch_available()
							    else ()
							)
							__a       : Any          =							(RemBertForCausalLM,) if is_torch_available() else ()
							__a       : List[str]          =							(
							    {
							        "feature-extraction": RemBertModel,
							        "fill-mask": RemBertForMaskedLM,
							        "question-answering": RemBertForQuestionAnswering,
							        "text-classification": RemBertForSequenceClassification,
							        "text-generation": RemBertForCausalLM,
							        "token-classification": RemBertForTokenClassification,
							        "zero-shot": RemBertForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)

							def      UpperCAmelCase__						(				self				:  Any )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   List[str]      =	RemBertModelTester(self )
													UpperCAmelCase_      :   Optional[Any]      =	ConfigTester(self							,  config_class=lowerCAmelCase__							,  hidden_size=37 )

							def      UpperCAmelCase__						(				self				:  Tuple )       ->							Optional[int]:







													"""simple docstring"""
													self.config_tester.run_common_tests()

							def      UpperCAmelCase__						(				self				:  Optional[Any] )       ->							Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   List[Any]      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*lowerCAmelCase__ )

							def      UpperCAmelCase__						(				self				:  List[Any] )       ->							Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Dict      =	self.model_tester.prepare_config_and_inputs()
													for type in ["absolute", "relative_key", "relative_key_query"]:
																			UpperCAmelCase_      :   int      =	type
																			self.model_tester.create_and_check_model(*lowerCAmelCase__ )

							def      UpperCAmelCase__						(				self				:  Any )       ->							int:







													"""simple docstring"""
													UpperCAmelCase_      :   int      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase__ )

							def      UpperCAmelCase__						(				self				:  List[str] )       ->							Dict:







													"""simple docstring"""
													UpperCAmelCase_      :   List[str]      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase__ )

							def      UpperCAmelCase__						(				self				:  Any )       ->							Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Tuple      =	self.model_tester.prepare_config_and_inputs_for_decoder()
													self.model_tester.create_and_check_decoder_model_past_large_inputs(*lowerCAmelCase__ )

							def      UpperCAmelCase__						(				self				:  Any )       ->							int:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[int]      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase__ )

							def      UpperCAmelCase__						(				self				:  Dict )       ->							Dict:







													"""simple docstring"""
													UpperCAmelCase_      :   int      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase__ )

							def      UpperCAmelCase__						(				self				:  List[Any] )       ->							Any:







													"""simple docstring"""
													UpperCAmelCase_      :   Union[str, Any]      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase__ )

							def      UpperCAmelCase__						(				self				:  Dict )       ->							Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Union[str, Any]      =	self.model_tester.prepare_config_and_inputs_for_decoder()
													self.model_tester.create_and_check_model_as_decoder(*lowerCAmelCase__ )

							def      UpperCAmelCase__						(				self				:  Optional[Any] )       ->							Union[str, Any]:







													"""simple docstring"""
													(
													    UpperCAmelCase_      
													)      :   Dict      =	self.model_tester.prepare_config_and_inputs_for_decoder()

													UpperCAmelCase_      :   str      =	None

													self.model_tester.create_and_check_model_as_decoder(
													    lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  )



							@slow
							def      UpperCAmelCase__						(				self				:  Union[str, Any] )       ->							Tuple:







													"""simple docstring"""





													for model_name in REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase_      :   List[Any]      =	RemBertModel.from_pretrained(lowerCAmelCase__ )
																			self.assertIsNotNone(lowerCAmelCase__ )





@require_torch
class        __a   (unittest.TestCase  ):

							@slow
							def      UpperCAmelCase__						(				self				:  str )       ->							Any:







													"""simple docstring"""
													UpperCAmelCase_      :   str      =	RemBertModel.from_pretrained('''google/rembert''' )
													UpperCAmelCase_      :   Any      =	torch.tensor([[3_12, 5_64_98, 3_13, 21_25, 3_13]] )
													UpperCAmelCase_      :   str      =	torch.tensor([[0, 0, 0, 1, 1]] )
													with torch.no_grad():
																			UpperCAmelCase_      :   Union[str, Any]      =	model(lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__							,  output_hidden_states=lowerCAmelCase__ )

													UpperCAmelCase_      :   int      =	11_52

													UpperCAmelCase_      :   Optional[Any]      =	torch.Size((1, 5, hidden_size) )
													self.assertEqual(output['''last_hidden_state'''].shape							,  lowerCAmelCase__ )

													UpperCAmelCase_      :   Any      =	torch.tensor(
													    [
													        [
													            [0.0_7_5_4, -0.2_0_2_2, 0.1_9_0_4],
													            [-0.3_3_5_4, -0.3_6_9_2, -0.4_7_9_1],
													            [-0.2_3_1_4, -0.6_7_2_9, -0.0_7_4_9],
													            [-0.0_3_9_6, -0.3_1_0_5, -0.4_2_3_4],
													            [-0.1_5_7_1, -0.0_5_2_5, 0.5_3_5_3],
													        ]
													    ] )

													# Running on the original tf implementation gives slightly different results here.
													# Not clear why this variations is present
													# TODO: Find reason for discrepancy
													# expected_original_implementation = [[
													#     [0.07630594074726105, -0.20146065950393677, 0.19107051193714142],
													#     [-0.3405614495277405, -0.36971670389175415, -0.4808273911476135],
													#     [-0.22587086260318756, -0.6656315922737122, -0.07844287157058716],
													#     [-0.04145475849509239, -0.3077218234539032, -0.42316967248916626],
													#     [-0.15887849032878876, -0.054529931396245956, 0.5356100797653198]
													# ]]

													self.assertTrue(torch.allclose(output['''last_hidden_state'''][:, :, :3]							,  lowerCAmelCase__							,  atol=1E-4 ) )






'''simple docstring'''

from sklearn.metrics import mean_absolute_error

import datasets


_lowerCamelCase :				Union[str, Any]														= """\
@article{scikit-learn,
 title={Scikit-learn: Machine Learning in {P}ython},
 author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
 journal={Journal of Machine Learning Research},
 volume={12},
 pages={2825--2830},
 year={2011}
}
"""

_lowerCamelCase :				List[Any]														= """\
Mean Absolute Error (MAE) is the mean of the magnitude of difference between the predicted and actual
values.
"""


_lowerCamelCase :				Union[str, Any]														= """
Args:
    predictions: array-like of shape (n_samples,) or (n_samples, n_outputs)
        Estimated target values.
    references: array-like of shape (n_samples,) or (n_samples, n_outputs)
        Ground truth (correct) target values.
    sample_weight: array-like of shape (n_samples,), default=None
        Sample weights.
    multioutput: {\"raw_values\", \"uniform_average\"} or array-like of shape (n_outputs,), default=\"uniform_average\"
        Defines aggregating of multiple output values. Array-like value defines weights used to average errors.

                 \"raw_values\" : Returns a full set of errors in case of multioutput input.

                 \"uniform_average\" : Errors of all outputs are averaged with uniform weight.

Returns:
    mae : mean absolute error.
        If multioutput is \"raw_values\", then mean absolute error is returned for each output separately. If multioutput is \"uniform_average\" or an ndarray of weights, then the weighted average of all output errors is returned.
        MAE output is non-negative floating point. The best value is 0.0.
Examples:

    >>> mae_metric = datasets.load_metric(\"mae\")
    >>> predictions = [2.5, 0.0, 2, 8]
    >>> references = [3, -0.5, 2, 7]
    >>> results = mae_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'mae': 0.5}

    If you're using multi-dimensional lists, then set the config as follows :

    >>> mae_metric = datasets.load_metric(\"mae\", \"multilist\")
    >>> predictions = [[0.5, 1], [-1, 1], [7, -6]]
    >>> references = [[0, 2], [-1, 2], [8, -5]]
    >>> results = mae_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'mae': 0.75}
    >>> results = mae_metric.compute(predictions=predictions, references=references, multioutput='raw_values')
    >>> print(results)
    {'mae': array([0.5, 1. ])}
"""




@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION       ,				_KWARGS_DESCRIPTION     )
class    lowerCamelCase__  (   datasets.Metric     ):



   def  _UpperCamelCase		(    self     )				->     int:
        """simple docstring"""





        return datasets.MetricInfo(
            description=_DESCRIPTION					,      citation=_CITATION					,      inputs_description=_KWARGS_DESCRIPTION					,      features=datasets.Features(self._get_feature_types()     )					,      reference_urls=[
                """https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_absolute_error.html"""
            ]					,      )



   def  _UpperCamelCase		(    self     )				->     Tuple:
        """simple docstring"""





        if self.config_name == "multilist":
             return {
                 "predictions": datasets.Sequence(datasets.Value("""float"""     )     ),
                 "references": datasets.Sequence(datasets.Value("""float"""     )     ),
             }
        else:
             return {
                 "predictions": datasets.Value("""float"""     ),
                 "references": datasets.Value("""float"""     ),
             }




   def  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__=None					,      lowerCAmelCase__="uniform_average"     )				->     List[str]:
        """simple docstring"""





        _UpperCamelCase  :Tuple       =mean_absolute_error(lowerCAmelCase__					,      lowerCAmelCase__					,      sample_weight=lowerCAmelCase__					,      multioutput=lowerCAmelCase__     )

        return {"mae": mae_score}