


import numpy as np
import qiskit


def 	_UpperCamelCase							(				lowercase__   ,	lowercase__				):
      __SCREAMING_SNAKE_CASE						:					List[str]		      =		qiskit.QuantumCircuit(num_qubits + 1				)

      # First, let's deal with the case in which oracle is balanced
      if case == "balanced":
            # First generate a random number that tells us which CNOTs to
            # wrap in X-gates:
            __SCREAMING_SNAKE_CASE						:					Any		      =		np.random.randint(1   ,	2**num_qubits				)
            # Next, format 'b' as a binary string of length 'n', padded with zeros:
            __SCREAMING_SNAKE_CASE						:					List[Any]		      =		format(lowercase__   ,	F'''0{num_qubits}b'''				)
            # Next, we place the first X-gates. Each digit in our binary string
            # corresponds to a qubit, if the digit is 0, we do nothing, if it's 1
            # we apply an X-gate to that qubit:
            for index, bit in enumerate(lowercase__				):
                  if bit == "1":
                        oracle_qc.x(lowercase__				)
        # Do the controlled-NOT gates for each qubit, using the output qubit
        # as the target:
            for index in range(lowercase__				):
                  oracle_qc.cx(lowercase__   ,	lowercase__				)
            # Next, place the final X-gates
            for index, bit in enumerate(lowercase__				):
                  if bit == "1":
                        oracle_qc.x(lowercase__				)

    # Case in which oracle is constant
      if case == "constant":
            # First decide what the fixed output of the oracle will be
            # (either always 0 or always 1)
            __SCREAMING_SNAKE_CASE						:					List[Any]		      =		np.random.randint(2				)
            if output == 1:
                  oracle_qc.x(lowercase__				)

      __SCREAMING_SNAKE_CASE						:					Optional[int]		      =		oracle_qc.to_gate()
      __SCREAMING_SNAKE_CASE						:					str		      =		'''Oracle'''  # To show when we display the circuit
      return oracle_gate


def 	_UpperCamelCase							(				lowercase__   ,	lowercase__				):
      __SCREAMING_SNAKE_CASE						:					Any		      =		qiskit.QuantumCircuit(num_qubits + 1   ,	lowercase__				)
      # Set up the output qubit:
      dj_circuit.x(lowercase__				)
      dj_circuit.h(lowercase__				)
      # And set up the input register:
      for qubit in range(lowercase__				):
            dj_circuit.h(lowercase__				)
      # Let's append the oracle gate to our circuit:
      dj_circuit.append(lowercase__   ,	range(num_qubits + 1				)				)
      # Finally, perform the H-gates again and measure:
      for qubit in range(lowercase__				):
            dj_circuit.h(lowercase__				)

      for i in range(lowercase__				):
            dj_circuit.measure(lowercase__   ,	lowercase__				)

      return dj_circuit


def 	_UpperCamelCase							(				lowercase__   ,	lowercase__				):
      __SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		qiskit.Aer.get_backend('''aer_simulator'''				)

      __SCREAMING_SNAKE_CASE						:					int		      =		dj_oracle(lowercase__   ,	lowercase__				)
      __SCREAMING_SNAKE_CASE						:					str		      =		dj_algorithm(lowercase__   ,	lowercase__				)

      # Execute the circuit on the simulator
      __SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		qiskit.execute(lowercase__   ,	lowercase__   ,	shots=1000				)

      # Return the histogram data of the results of the experiment.
      return job.result().get_counts(lowercase__				)


if __name__ == "__main__":
      print(f"""Deutsch Jozsa - Constant Oracle: {deutsch_jozsa("constant", 3)}""")
      print(f"""Deutsch Jozsa - Balanced Oracle: {deutsch_jozsa("balanced", 3)}""")




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






				'''simple docstring'''



				def __init__(	self      :int      ,      lowerCAmelCase__      :Optional[int]      ,      lowerCAmelCase__      :Optional[Any]=13      ,      lowerCAmelCase__      :int=7      ,      lowerCAmelCase__      :Any=True      ,      lowerCAmelCase__      :Optional[int]=True      ,      lowerCAmelCase__      :Union[str, Any]=True      ,      lowerCAmelCase__      :Union[str, Any]=True      ,      lowerCAmelCase__      :List[str]=99      ,      lowerCAmelCase__      :Tuple=32      ,      lowerCAmelCase__      :List[str]=18      ,      lowerCAmelCase__      :List[Any]=43      ,      lowerCAmelCase__      :int=5      ,      lowerCAmelCase__      :Any=4      ,      lowerCAmelCase__      :List[str]=37      ,      lowerCAmelCase__      :List[Any]="gelu"      ,      lowerCAmelCase__      :Union[str, Any]=0.1      ,      lowerCAmelCase__      :Union[str, Any]=0.1      ,      lowerCAmelCase__      :Optional[int]=512      ,      lowerCAmelCase__      :Union[str, Any]=16      ,      lowerCAmelCase__      :Optional[Any]=2      ,      lowerCAmelCase__      :Any=0.02      ,      lowerCAmelCase__      :Optional[int]=3      ,      lowerCAmelCase__      :str=4      ,      lowerCAmelCase__      :str=None      ,      )		->      Optional[int]:
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		parent
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		batch_size
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		seq_length
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		is_training
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		use_input_mask
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		use_token_type_ids
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		use_labels
										__SCREAMING_SNAKE_CASE						:					int		      =		vocab_size
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		hidden_size
										__SCREAMING_SNAKE_CASE						:					int		      =		input_embedding_size
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		output_embedding_size
										__SCREAMING_SNAKE_CASE						:					int		      =		num_hidden_layers
										__SCREAMING_SNAKE_CASE						:					int		      =		num_attention_heads
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		intermediate_size
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		hidden_act
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		hidden_dropout_prob
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		attention_probs_dropout_prob
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		max_position_embeddings
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		type_vocab_size
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		type_sequence_label_size
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		initializer_range
										__SCREAMING_SNAKE_CASE						:					Any		      =		num_labels
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		num_choices
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		scope


				def 		__magic_name__(	self      :Any     )		->      Dict:
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		ids_tensor([self.batch_size, self.seq_length]      ,      self.vocab_size     )

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

										__SCREAMING_SNAKE_CASE						:					Dict		      =		None
										if self.use_token_type_ids:
																__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		ids_tensor([self.batch_size, self.seq_length]      ,      self.type_vocab_size     )

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

										__SCREAMING_SNAKE_CASE						:					str		      =		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 		__magic_name__(	self      :int     )		->      Any:
										(
										    (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      
										)						:					Dict		      =		self.prepare_config_and_inputs()

										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		True
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		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 		__magic_name__(	self      :Optional[int]      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :List[Any]     )		->      Optional[int]:
										__SCREAMING_SNAKE_CASE						:					str		      =		RemBertModel(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		model(lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__     )
										__SCREAMING_SNAKE_CASE						:					int		      =		model(lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__     )
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		model(lowerCAmelCase__     )
										self.parent.assertEqual(result.last_hidden_state.shape      ,      (self.batch_size, self.seq_length, self.hidden_size)     )


				def 		__magic_name__(	self      :Optional[int]      ,      lowerCAmelCase__      :Optional[int]      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :List[str]      ,      lowerCAmelCase__      :Dict      ,      lowerCAmelCase__      :int      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :Dict      ,      lowerCAmelCase__      :Any      ,      )		->      Any:
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		True
										__SCREAMING_SNAKE_CASE						:					Tuple		      =		RemBertModel(lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		model(
										    lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      encoder_hidden_states=lowerCAmelCase__      ,      encoder_attention_mask=lowerCAmelCase__      ,      )
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		model(
										    lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      encoder_hidden_states=lowerCAmelCase__      ,      )
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		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 		__magic_name__(	self      :Optional[Any]      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :Dict      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :Dict      ,      lowerCAmelCase__      :str      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :int      ,      )		->      Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:					Dict		      =		RemBertForCausalLM(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					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 		__magic_name__(	self      :Optional[int]      ,      lowerCAmelCase__      :int      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :List[str]     )		->      Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:					int		      =		RemBertForMaskedLM(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					Dict		      =		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 		__magic_name__(	self      :Tuple      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :int      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :str      ,      lowerCAmelCase__      :Optional[int]      ,      lowerCAmelCase__      :Dict      ,      lowerCAmelCase__      :int      ,      lowerCAmelCase__      :str      ,      )		->      Dict:
										__SCREAMING_SNAKE_CASE						:					Dict		      =		True
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		True
										__SCREAMING_SNAKE_CASE						:					str		      =		RemBertForCausalLM(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()

										# first forward pass
										__SCREAMING_SNAKE_CASE						:					Dict		      =		model(
										    lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      encoder_hidden_states=lowerCAmelCase__      ,      encoder_attention_mask=lowerCAmelCase__      ,      use_cache=lowerCAmelCase__      ,      )
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		outputs.past_key_values

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

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

										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		model(
										    lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      encoder_hidden_states=lowerCAmelCase__      ,      encoder_attention_mask=lowerCAmelCase__      ,      output_hidden_states=lowerCAmelCase__      ,      )['''hidden_states'''][0]
										__SCREAMING_SNAKE_CASE						:					int		      =		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
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		ids_tensor((1,)      ,      output_from_past.shape[-1]     ).item()
										__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		output_from_no_past[:, -3:, random_slice_idx].detach()
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		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 		__magic_name__(	self      :Any      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :Optional[int]      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :Union[str, Any]     )		->      Any:
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		RemBertForQuestionAnswering(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		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 		__magic_name__(	self      :Optional[Any]      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :Optional[int]      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :Optional[int]      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :Dict      ,      lowerCAmelCase__      :Optional[Any]     )		->      Tuple:
										__SCREAMING_SNAKE_CASE						:					Dict		      =		self.num_labels
										__SCREAMING_SNAKE_CASE						:					Any		      =		RemBertForSequenceClassification(lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					Dict		      =		model(lowerCAmelCase__      ,      attention_mask=lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      labels=lowerCAmelCase__     )
										self.parent.assertEqual(result.logits.shape      ,      (self.batch_size, self.num_labels)     )


				def 		__magic_name__(	self      :int      ,      lowerCAmelCase__      :str      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :Any      ,      lowerCAmelCase__      :Optional[Any]      ,      lowerCAmelCase__      :List[str]     )		->      Optional[Any]:
										__SCREAMING_SNAKE_CASE						:					Any		      =		self.num_labels
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		RemBertForTokenClassification(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					Optional[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.num_labels)     )


				def 		__magic_name__(	self      :List[str]      ,      lowerCAmelCase__      :Dict      ,      lowerCAmelCase__      :Tuple      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :List[Any]      ,      lowerCAmelCase__      :Union[str, Any]      ,      lowerCAmelCase__      :Optional[int]      ,      lowerCAmelCase__      :Union[str, Any]     )		->      List[str]:
										__SCREAMING_SNAKE_CASE						:					Any		      =		self.num_choices
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		RemBertForMultipleChoice(config=lowerCAmelCase__     )
										model.to(lowerCAmelCase__     )
										model.eval()
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		input_ids.unsqueeze(1     ).expand(-1      ,      self.num_choices      ,      -1     ).contiguous()
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		token_type_ids.unsqueeze(1     ).expand(-1      ,      self.num_choices      ,      -1     ).contiguous()
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		input_mask.unsqueeze(1     ).expand(-1      ,      self.num_choices      ,      -1     ).contiguous()
										__SCREAMING_SNAKE_CASE						:					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 		__magic_name__(	self      :Union[str, Any]     )		->      Any:
										__SCREAMING_SNAKE_CASE						:					int		      =		self.prepare_config_and_inputs()
										(
										    (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      (
										    __SCREAMING_SNAKE_CASE
										)      ,      
										)						:					int		      =		config_and_inputs
										__SCREAMING_SNAKE_CASE						:					Any		      =		{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
										return config, inputs_dict




@require_torch
class 	_lowercase				(      A__						,      A__						,      unittest.TestCase	):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE__    :      Dict      =		(
				    (
				        RemBertModel,
				        RemBertForMaskedLM,
				        RemBertForCausalLM,
				        RemBertForMultipleChoice,
				        RemBertForQuestionAnswering,
				        RemBertForSequenceClassification,
				        RemBertForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE__    :      Tuple      =		(RemBertForCausalLM,) if is_torch_available() else ()
				SCREAMING_SNAKE_CASE__    :      Tuple      =		(
				    {
				        '''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 		__magic_name__(	self      :List[str]     )		->      List[str]:
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		RemBertModelTester(self     )
										__SCREAMING_SNAKE_CASE						:					Dict		      =		ConfigTester(self      ,      config_class=lowerCAmelCase__      ,      hidden_size=37     )


				def 		__magic_name__(	self      :Dict     )		->      int:
										self.config_tester.run_common_tests()


				def 		__magic_name__(	self      :Any     )		->      List[str]:
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :Optional[int]     )		->      Union[str, Any]:
										__SCREAMING_SNAKE_CASE						:					int		      =		self.model_tester.prepare_config_and_inputs()
										for type in ["absolute", "relative_key", "relative_key_query"]:
																__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		type
																self.model_tester.create_and_check_model(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :Optional[int]     )		->      Dict:
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :List[Any]     )		->      int:
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :Dict     )		->      Dict:
										__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		self.model_tester.prepare_config_and_inputs_for_decoder()
										self.model_tester.create_and_check_decoder_model_past_large_inputs(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :Optional[int]     )		->      Optional[Any]:
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :Any     )		->      Dict:
										__SCREAMING_SNAKE_CASE						:					List[str]		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :Optional[int]     )		->      List[str]:
										__SCREAMING_SNAKE_CASE						:					str		      =		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :str     )		->      Dict:
										__SCREAMING_SNAKE_CASE						:					int		      =		self.model_tester.prepare_config_and_inputs_for_decoder()
										self.model_tester.create_and_check_model_as_decoder(*lowerCAmelCase__     )


				def 		__magic_name__(	self      :Optional[int]     )		->      Optional[int]:
										# This regression test was failing with PyTorch < 1.3
										(
										    (
										    __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[Any]		      =		self.model_tester.prepare_config_and_inputs_for_decoder()

										__SCREAMING_SNAKE_CASE						:					Any		      =		None

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



				@slow
				def 		__magic_name__(	self      :Any     )		->      Union[str, Any]:
										for model_name in REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																__SCREAMING_SNAKE_CASE						:					List[Any]		      =		RemBertModel.from_pretrained(lowerCAmelCase__     )
																self.assertIsNotNone(lowerCAmelCase__     )




@require_torch
class 	_lowercase				(      unittest.TestCase	):






				'''simple docstring'''



				@slow
				def 		__magic_name__(	self      :str     )		->      List[Any]:
										# Test exact values at the last hidden layer
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		RemBertModel.from_pretrained('''google/rembert'''     )
										__SCREAMING_SNAKE_CASE						:					List[Any]		      =		torch.tensor([[312, 56_498, 313, 2_125, 313]]     )
										__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		torch.tensor([[0, 0, 0, 1, 1]]     )
										with torch.no_grad():
																__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		model(lowerCAmelCase__      ,      token_type_ids=lowerCAmelCase__      ,      output_hidden_states=lowerCAmelCase__     )

										__SCREAMING_SNAKE_CASE						:					List[str]		      =		1_152

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

										__SCREAMING_SNAKE_CASE						:					str		      =		torch.tensor(
										    [
										        [
										            [0.0754, -0.2022, 0.1904],
										            [-0.3354, -0.3692, -0.4791],
										            [-0.2314, -0.6729, -0.0749],
										            [-0.0396, -0.3105, -0.4234],
										            [-0.1571, -0.0525, 0.5353],
										        ]
										    ]     )

										# 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     )     )
