


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

		"""simple docstring"""





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

					"""simple docstring"""



					_UpperCamelCase				:List[str]				    =  parent
					_UpperCamelCase				:Dict				    =  batch_size
					_UpperCamelCase				:List[Any]				    =  seq_length
					_UpperCamelCase				:List[str]				    =  is_training
					_UpperCamelCase				:List[Any]				    =  use_input_mask
					_UpperCamelCase				:Dict				    =  use_token_type_ids
					_UpperCamelCase				:str				    =  use_labels
					_UpperCamelCase				:Optional[Any]				    =  vocab_size
					_UpperCamelCase				:Optional[int]				    =  hidden_size
					_UpperCamelCase				:Tuple				    =  input_embedding_size
					_UpperCamelCase				:int				    =  output_embedding_size
					_UpperCamelCase				:Optional[Any]				    =  num_hidden_layers
					_UpperCamelCase				:List[Any]				    =  num_attention_heads
					_UpperCamelCase				:Tuple				    =  intermediate_size
					_UpperCamelCase				:str				    =  hidden_act
					_UpperCamelCase				:Dict				    =  hidden_dropout_prob
					_UpperCamelCase				:Optional[Any]				    =  attention_probs_dropout_prob
					_UpperCamelCase				:Optional[Any]				    =  max_position_embeddings
					_UpperCamelCase				:List[Any]				    =  type_vocab_size
					_UpperCamelCase				:int				    =  type_sequence_label_size
					_UpperCamelCase				:Union[str, Any]				    =  initializer_range
					_UpperCamelCase				:Union[str, Any]				    =  num_labels
					_UpperCamelCase				:List[Any]				    =  num_choices
					_UpperCamelCase				:str				    =  scope
		def      _UpperCamelCase(   self      )			->  str:

					"""simple docstring"""



					_UpperCamelCase				:Dict				    =  ids_tensor([self.batch_size, self.seq_length]				,							self.vocab_size      )

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

					_UpperCamelCase				:Any				    =  None
					if self.use_token_type_ids:
								_UpperCamelCase				:int				    =  ids_tensor([self.batch_size, self.seq_length]				,							self.type_vocab_size      )

					_UpperCamelCase				:str				    =  None
					_UpperCamelCase				:Union[str, Any]				    =  None
					_UpperCamelCase				:Any				    =  None
					if self.use_labels:
								_UpperCamelCase				:Any				    =  ids_tensor([self.batch_size]				,							self.type_sequence_label_size      )
								_UpperCamelCase				:int				    =  ids_tensor([self.batch_size, self.seq_length]				,							self.num_labels      )
								_UpperCamelCase				:Optional[int]				    =  ids_tensor([self.batch_size]				,							self.num_choices      )

					_UpperCamelCase				:List[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=SCREAMING_SNAKE_CASE__				,							initializer_range=self.initializer_range				,							)

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
		def      _UpperCamelCase(   self      )			->  List[str]:

					"""simple docstring"""



					(
					    (
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			
					)				:List[Any]				    =  self.prepare_config_and_inputs()

					_UpperCamelCase				:int				    =  True
					_UpperCamelCase				:Union[str, Any]				    =  floats_tensor([self.batch_size, self.seq_length, self.hidden_size]      )
					_UpperCamelCase				:Union[str, 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				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__      )			->  Dict:

					"""simple docstring"""



					_UpperCamelCase				:int				    =  RemBertModel(config=SCREAMING_SNAKE_CASE__      )
					model.to(SCREAMING_SNAKE_CASE__      )
					model.eval()
					_UpperCamelCase				:Any				    =  model(SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__      )
					_UpperCamelCase				:List[Any]				    =  model(SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__      )
					_UpperCamelCase				:Optional[int]				    =  model(SCREAMING_SNAKE_CASE__      )
					self.parent.assertEqual(result.last_hidden_state.shape				,							(self.batch_size, self.seq_length, self.hidden_size)      )
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							)			->  Optional[int]:

					"""simple docstring"""



					_UpperCamelCase				:Tuple				    =  True
					_UpperCamelCase				:Optional[Any]				    =  RemBertModel(SCREAMING_SNAKE_CASE__      )
					model.to(SCREAMING_SNAKE_CASE__      )
					model.eval()
					_UpperCamelCase				:str				    =  model(
					    SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__				,							encoder_hidden_states=SCREAMING_SNAKE_CASE__				,							encoder_attention_mask=SCREAMING_SNAKE_CASE__				,							)
					_UpperCamelCase				:Any				    =  model(
					    SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__				,							encoder_hidden_states=SCREAMING_SNAKE_CASE__				,							)
					_UpperCamelCase				:Optional[Any]				    =  model(SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__      )
					self.parent.assertEqual(result.last_hidden_state.shape				,							(self.batch_size, self.seq_length, self.hidden_size)      )
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							)			->  int:

					"""simple docstring"""



					_UpperCamelCase				:List[Any]				    =  RemBertForCausalLM(config=SCREAMING_SNAKE_CASE__      )
					model.to(SCREAMING_SNAKE_CASE__      )
					model.eval()
					_UpperCamelCase				:Any				    =  model(SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__				,							labels=SCREAMING_SNAKE_CASE__      )
					self.parent.assertEqual(result.logits.shape				,							(self.batch_size, self.seq_length, self.vocab_size)      )
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__      )			->  str:

					"""simple docstring"""



					_UpperCamelCase				:Any				    =  RemBertForMaskedLM(config=SCREAMING_SNAKE_CASE__      )
					model.to(SCREAMING_SNAKE_CASE__      )
					model.eval()
					_UpperCamelCase				:List[str]				    =  model(SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__				,							labels=SCREAMING_SNAKE_CASE__      )
					self.parent.assertEqual(result.logits.shape				,							(self.batch_size, self.seq_length, self.vocab_size)      )
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							)			->  Union[str, Any]:

					"""simple docstring"""



					_UpperCamelCase				:Optional[int]				    =  True
					_UpperCamelCase				:Union[str, Any]				    =  True
					_UpperCamelCase				:Optional[int]				    =  RemBertForCausalLM(config=SCREAMING_SNAKE_CASE__      )
					model.to(SCREAMING_SNAKE_CASE__      )
					model.eval()

					# first forward pass
					_UpperCamelCase				:Any				    =  model(
					    SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							encoder_hidden_states=SCREAMING_SNAKE_CASE__				,							encoder_attention_mask=SCREAMING_SNAKE_CASE__				,							use_cache=SCREAMING_SNAKE_CASE__				,							)
					_UpperCamelCase				:Any				    =  outputs.past_key_values

					# create hypothetical multiple next token and extent to next_input_ids
					_UpperCamelCase				:Any				    =  ids_tensor((self.batch_size, 3)				,							config.vocab_size      )
					_UpperCamelCase				:int				    =  ids_tensor((self.batch_size, 3)				,							vocab_size=2      )

					# append to next input_ids and
					_UpperCamelCase				:List[Any]				    =  torch.cat([input_ids, next_tokens]				,							dim=-1      )
					_UpperCamelCase				:Dict				    =  torch.cat([input_mask, next_mask]				,							dim=-1      )

					_UpperCamelCase				:List[Any]				    =  model(
					    SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							encoder_hidden_states=SCREAMING_SNAKE_CASE__				,							encoder_attention_mask=SCREAMING_SNAKE_CASE__				,							output_hidden_states=SCREAMING_SNAKE_CASE__				,							)['''hidden_states'''][0]
					_UpperCamelCase				:Tuple				    =  model(
					    SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							encoder_hidden_states=SCREAMING_SNAKE_CASE__				,							encoder_attention_mask=SCREAMING_SNAKE_CASE__				,							past_key_values=SCREAMING_SNAKE_CASE__				,							output_hidden_states=SCREAMING_SNAKE_CASE__				,							)['''hidden_states'''][0]

					# select random slice
					_UpperCamelCase				:str				    =  ids_tensor((1,)				,							output_from_past.shape[-1]      ).item()
					_UpperCamelCase				:List[str]				    =  output_from_no_past[:, -3:, random_slice_idx].detach()
					_UpperCamelCase				:Tuple				    =  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(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							atol=1E-3      )      )
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__      )			->  List[Any]:

					"""simple docstring"""



					_UpperCamelCase				:Any				    =  RemBertForQuestionAnswering(config=SCREAMING_SNAKE_CASE__      )
					model.to(SCREAMING_SNAKE_CASE__      )
					model.eval()
					_UpperCamelCase				:str				    =  model(
					    SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__				,							start_positions=SCREAMING_SNAKE_CASE__				,							end_positions=SCREAMING_SNAKE_CASE__				,							)
					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				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__      )			->  List[str]:

					"""simple docstring"""



					_UpperCamelCase				:int				    =  self.num_labels
					_UpperCamelCase				:str				    =  RemBertForSequenceClassification(SCREAMING_SNAKE_CASE__      )
					model.to(SCREAMING_SNAKE_CASE__      )
					model.eval()
					_UpperCamelCase				:Optional[Any]				    =  model(SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__				,							labels=SCREAMING_SNAKE_CASE__      )
					self.parent.assertEqual(result.logits.shape				,							(self.batch_size, self.num_labels)      )
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__      )			->  str:

					"""simple docstring"""



					_UpperCamelCase				:Optional[Any]				    =  self.num_labels
					_UpperCamelCase				:str				    =  RemBertForTokenClassification(config=SCREAMING_SNAKE_CASE__      )
					model.to(SCREAMING_SNAKE_CASE__      )
					model.eval()
					_UpperCamelCase				:Optional[int]				    =  model(SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__				,							labels=SCREAMING_SNAKE_CASE__      )
					self.parent.assertEqual(result.logits.shape				,							(self.batch_size, self.seq_length, self.num_labels)      )
		def      _UpperCamelCase(   self				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__      )			->  Optional[int]:

					"""simple docstring"""



					_UpperCamelCase				:str				    =  self.num_choices
					_UpperCamelCase				:Optional[int]				    =  RemBertForMultipleChoice(config=SCREAMING_SNAKE_CASE__      )
					model.to(SCREAMING_SNAKE_CASE__      )
					model.eval()
					_UpperCamelCase				:List[str]				    =  input_ids.unsqueeze(1      ).expand(-1				,							self.num_choices				,							-1      ).contiguous()
					_UpperCamelCase				:Optional[int]				    =  token_type_ids.unsqueeze(1      ).expand(-1				,							self.num_choices				,							-1      ).contiguous()
					_UpperCamelCase				:Union[str, Any]				    =  input_mask.unsqueeze(1      ).expand(-1				,							self.num_choices				,							-1      ).contiguous()
					_UpperCamelCase				:int				    =  model(
					    SCREAMING_SNAKE_CASE__				,							attention_mask=SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__				,							labels=SCREAMING_SNAKE_CASE__				,							)
					self.parent.assertEqual(result.logits.shape				,							(self.batch_size, self.num_choices)      )





		def      _UpperCamelCase(   self      )			->  str:

					"""simple docstring"""



					_UpperCamelCase				:Any				    =  self.prepare_config_and_inputs()
					(
					    (
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _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(     lowerCamelCase__							,       lowerCamelCase__							,       unittest.TestCase		):

		"""simple docstring"""





		A         =       (
		    (
		        RemBertModel,
		        RemBertForMaskedLM,
		        RemBertForCausalLM,
		        RemBertForMultipleChoice,
		        RemBertForQuestionAnswering,
		        RemBertForSequenceClassification,
		        RemBertForTokenClassification,
		    )
		    if is_torch_available()
		    else ()
		)
		A         =       (RemBertForCausalLM,) if is_torch_available() else ()
		A         =       (
		    {
		        "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:

					"""simple docstring"""



					_UpperCamelCase				:Union[str, Any]				    =  RemBertModelTester(self      )
					_UpperCamelCase				:Union[str, Any]				    =  ConfigTester(self				,							config_class=SCREAMING_SNAKE_CASE__				,							hidden_size=37      )
		def      _UpperCamelCase(   self      )			->  Union[str, Any]:

					"""simple docstring"""



					self.config_tester.run_common_tests()
		def      _UpperCamelCase(   self      )			->  Union[str, Any]:

					"""simple docstring"""



					_UpperCamelCase				:Optional[int]				    =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__      )
		def      _UpperCamelCase(   self      )			->  Any:

					"""simple docstring"""



					_UpperCamelCase				:List[Any]				    =  self.model_tester.prepare_config_and_inputs()
					for type in ["absolute", "relative_key", "relative_key_query"]:
								_UpperCamelCase				:Dict				    =  type
								self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__      )
		def      _UpperCamelCase(   self      )			->  str:

					"""simple docstring"""



					_UpperCamelCase				:Any				    =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE__      )
		def      _UpperCamelCase(   self      )			->  List[Any]:

					"""simple docstring"""



					_UpperCamelCase				:List[str]				    =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_multiple_choice(*SCREAMING_SNAKE_CASE__      )
		def      _UpperCamelCase(   self      )			->  int:

					"""simple docstring"""



					_UpperCamelCase				:List[Any]				    =  self.model_tester.prepare_config_and_inputs_for_decoder()
					self.model_tester.create_and_check_decoder_model_past_large_inputs(*SCREAMING_SNAKE_CASE__      )
		def      _UpperCamelCase(   self      )			->  Dict:

					"""simple docstring"""



					_UpperCamelCase				:List[Any]				    =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE__      )
		def      _UpperCamelCase(   self      )			->  Any:

					"""simple docstring"""



					_UpperCamelCase				:Optional[Any]				    =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE__      )
		def      _UpperCamelCase(   self      )			->  Optional[int]:

					"""simple docstring"""



					_UpperCamelCase				:Any				    =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE__      )
		def      _UpperCamelCase(   self      )			->  List[Any]:

					"""simple docstring"""



					_UpperCamelCase				:Optional[Any]				    =  self.model_tester.prepare_config_and_inputs_for_decoder()
					self.model_tester.create_and_check_model_as_decoder(*SCREAMING_SNAKE_CASE__      )
		def      _UpperCamelCase(   self      )			->  Union[str, Any]:

					"""simple docstring"""



					(
					    (
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			(
					    _UpperCamelCase
					)    ,			
					)				:Optional[int]				    =  self.model_tester.prepare_config_and_inputs_for_decoder()

					_UpperCamelCase				:Tuple				    =  None

					self.model_tester.create_and_check_model_as_decoder(
					    SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__				,							)





		@slow
		def      _UpperCamelCase(   self      )			->  Any:

					"""simple docstring"""



					for model_name in REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								_UpperCamelCase				:Optional[int]				    =  RemBertModel.from_pretrained(SCREAMING_SNAKE_CASE__      )
								self.assertIsNotNone(SCREAMING_SNAKE_CASE__      )






@require_torch
class     A(     unittest.TestCase		):

		"""simple docstring"""





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

					"""simple docstring"""



					_UpperCamelCase				:List[str]				    =  RemBertModel.from_pretrained('''google/rembert'''      )
					_UpperCamelCase				:List[Any]				    =  torch.tensor([[3_12, 5_64_98, 3_13, 21_25, 3_13]]      )
					_UpperCamelCase				:Any				    =  torch.tensor([[0, 0, 0, 1, 1]]      )
					with torch.no_grad():
								_UpperCamelCase				:str				    =  model(SCREAMING_SNAKE_CASE__				,							token_type_ids=SCREAMING_SNAKE_CASE__				,							output_hidden_states=SCREAMING_SNAKE_CASE__      )

					_UpperCamelCase				:List[Any]				    =  11_52

					_UpperCamelCase				:Optional[int]				    =  torch.Size((1, 5, hidden_size)      )
					self.assertEqual(output['''last_hidden_state'''].shape				,							SCREAMING_SNAKE_CASE__      )

					_UpperCamelCase				:List[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]				,							SCREAMING_SNAKE_CASE__				,							atol=1E-4      )      )





"""simple docstring"""






from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL

from ...utils import BaseOutput, is_invisible_watermark_available, is_torch_available, is_transformers_available






@dataclass
class     A(     lowerCamelCase__		):

		"""simple docstring"""





		A         =       42


if is_transformers_available() and is_torch_available() and is_invisible_watermark_available():
					from .pipeline_stable_diffusion_xl import StableDiffusionXLPipeline
					from .pipeline_stable_diffusion_xl_imgaimg import StableDiffusionXLImgaImgPipeline

