code: 
  import gym
  import numpy as np
  import torch
  from mujoco_py import GlfwContext
  
  from transformers import DecisionTransformerModel
  
  
  GlfwContext(offscreen=True)  # Create a window to init GLFW.
  
  
  
  def 		UpperCamelCase    (					_UpperCAmelCase     :      Union[str, Any]   , _UpperCAmelCase     :      Optional[int]   , _UpperCAmelCase     :      Union[str, Any]   , _UpperCAmelCase     :      Optional[Any]   , _UpperCAmelCase     :      Tuple   , _UpperCAmelCase     :      Optional[int]     )      -> str:
  
  
  
  
  
  
  						'''simple docstring'''
  
  						_lowercase					:  Optional[Any]    			=      states.reshape(1   , -1   , model.config.state_dim     )
  						_lowercase					:  Optional[Any]    			=      actions.reshape(1   , -1   , model.config.act_dim     )
  						_lowercase					:  str    			=      returns_to_go.reshape(1   , -1   , 1     )
  						_lowercase					:  Any    			=      timesteps.reshape(1   , -1     )
  
  						if model.config.max_length is not None:
  												_lowercase					:  str    			=      states[:, -model.config.max_length :]
  												_lowercase					:  int    			=      actions[:, -model.config.max_length :]
  												_lowercase					:  Dict    			=      returns_to_go[:, -model.config.max_length :]
  												_lowercase					:  str    			=      timesteps[:, -model.config.max_length :]
  
  												# pad all tokens to sequence length
  												_lowercase					:  Dict    			=      torch.cat(
  												    [torch.zeros(model.config.max_length - states.shape[1]     ), torch.ones(states.shape[1]     )]     )
  												_lowercase					:  str    			=      attention_mask.to(dtype=torch.long   , device=states.device     ).reshape(1   , -1     )
  												_lowercase					:  Union[str, Any]    			=      torch.cat(
  												    [
  												        torch.zeros(
  												            (states.shape[0], model.config.max_length - states.shape[1], model.config.state_dim)   , device=states.device   , ),
  												        states,
  												    ]   , dim=1   , ).to(dtype=torch.floataa     )
  												_lowercase					:  Any    			=      torch.cat(
  												    [
  												        torch.zeros(
  												            (actions.shape[0], model.config.max_length - actions.shape[1], model.config.act_dim)   , device=actions.device   , ),
  												        actions,
  												    ]   , dim=1   , ).to(dtype=torch.floataa     )
  												_lowercase					:  Optional[int]    			=      torch.cat(
  												    [
  												        torch.zeros(
  												            (returns_to_go.shape[0], model.config.max_length - returns_to_go.shape[1], 1)   , device=returns_to_go.device   , ),
  												        returns_to_go,
  												    ]   , dim=1   , ).to(dtype=torch.floataa     )
  												_lowercase					:  Tuple    			=      torch.cat(
  												    [
  												        torch.zeros(
  												            (timesteps.shape[0], model.config.max_length - timesteps.shape[1])   , device=timesteps.device     ),
  												        timesteps,
  												    ]   , dim=1   , ).to(dtype=torch.long     )
  						else:
  												_lowercase					:  int    			=      None
  
  						_lowercase			,						_lowercase			,						_lowercase					:  Optional[Any]    			=      model(
  						    states=_UpperCAmelCase   , actions=_UpperCAmelCase   , rewards=_UpperCAmelCase   , returns_to_go=_UpperCAmelCase   , timesteps=_UpperCAmelCase   , attention_mask=_UpperCAmelCase   , return_dict=_UpperCAmelCase   , )
  
  						return action_preds[0, -1]
  
  
  # build the environment
  
  UpperCamelCase_	:    Optional[Any]  					=       gym.make("""Hopper-v3""")
  UpperCamelCase_	:    List[Any]  					=       env.observation_space.shape[0]
  UpperCamelCase_	:    Optional[int]  					=       env.action_space.shape[0]
  UpperCamelCase_	:    Dict  					=       1000
  UpperCamelCase_	:    Union[str, Any]  					=       """cuda"""
  UpperCamelCase_	:    List[str]  					=       1000.0  # normalization for rewards/returns
  UpperCamelCase_	:    str  					=       3600 / scale  # evaluation conditioning targets, 3600 is reasonable from the paper LINK
  UpperCamelCase_	:    Optional[Any]  					=       np.array(
      [
          1.31_1279,
          -0.0846_9521,
          -0.538_2719,
          -0.0720_1576,
          0.0493_2366,
          2.106_6856,
          -0.1501_7354,
          0.0087_8345,
          -0.284_8186,
          -0.1854_0096,
          -0.2846_1286,
      ]
  )
  UpperCamelCase_	:    Optional[int]  					=       np.array(
      [
          0.1779_0751,
          0.0544_4621,
          0.2129_7139,
          0.1453_0419,
          0.612_4444,
          0.8517_4465,
          1.451_5252,
          0.675_1696,
          1.53_6239,
          1.616_0746,
          5.607_2536,
      ]
  )
  UpperCamelCase_	:    Dict  					=       torch.from_numpy(state_mean).to(device=device)
  UpperCamelCase_	:    int  					=       torch.from_numpy(state_std).to(device=device)
  
  # Create the decision transformer model
  UpperCamelCase_	:    Tuple  					=       DecisionTransformerModel.from_pretrained("""edbeeching/decision-transformer-gym-hopper-medium""")
  UpperCamelCase_	:    List[Any]  					=       model.to(device)
  model.eval()
  
  for ep in range(10):
  							UpperCamelCase_					,     UpperCamelCase_	:    List[str]  					=       0, 0
  							UpperCamelCase_	:    Optional[Any]  					=       env.reset()
  							UpperCamelCase_	:    int  					=       torch.tensor(TARGET_RETURN, device=device, dtype=torch.floataa).reshape(1, 1)
  							UpperCamelCase_	:    Any  					=       torch.from_numpy(state).reshape(1, state_dim).to(device=device, dtype=torch.floataa)
  							UpperCamelCase_	:    Tuple  					=       torch.zeros((0, act_dim), device=device, dtype=torch.floataa)
  							UpperCamelCase_	:    Union[str, Any]  					=       torch.zeros(0, device=device, dtype=torch.floataa)
  
  							UpperCamelCase_	:    Optional[int]  					=       torch.tensor(0, device=device, dtype=torch.long).reshape(1, 1)
  							for t in range(max_ep_len):
  														env.render()
  														# add padding
  														UpperCamelCase_	:    Optional[int]  					=       torch.cat([actions, torch.zeros((1, act_dim), device=device)], dim=0)
  														UpperCamelCase_	:    Union[str, Any]  					=       torch.cat([rewards, torch.zeros(1, device=device)])
  
  														UpperCamelCase_	:    Any  					=       get_action(
  														    model,
  														    (states.to(dtype=torch.floataa) - state_mean) / state_std,
  														    actions.to(dtype=torch.floataa),
  														    rewards.to(dtype=torch.floataa),
  														    target_return.to(dtype=torch.floataa),
  														    timesteps.to(dtype=torch.long),
  														)
  														UpperCamelCase_	:    List[Any]  					=       action
  														UpperCamelCase_	:    Optional[int]  					=       action.detach().cpu().numpy()
  
  														UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_	:    Tuple  					=       env.step(action)
  
  														UpperCamelCase_	:    List[Any]  					=       torch.from_numpy(state).to(device=device).reshape(1, state_dim)
  														UpperCamelCase_	:    Optional[Any]  					=       torch.cat([states, cur_state], dim=0)
  														UpperCamelCase_	:    Optional[int]  					=       reward
  
  														UpperCamelCase_	:    Optional[int]  					=       target_return[0, -1] - (reward / scale)
  														UpperCamelCase_	:    Any  					=       torch.cat([target_return, pred_return.reshape(1, 1)], dim=1)
  														UpperCamelCase_	:    str  					=       torch.cat([timesteps, torch.ones((1, 1), device=device, dtype=torch.long) * (t + 1)], dim=1)
  
  														episode_return += reward
  														episode_length += 1
  
  														if done:
  																					break
  
  
  
  
  
style_context: 
  import unittest
  
  from transformers import ElectraConfig, is_torch_available
  from transformers.models.auto import get_values
  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 (
  							    MODEL_FOR_PRETRAINING_MAPPING,
  							    ElectraForCausalLM,
  							    ElectraForMaskedLM,
  							    ElectraForMultipleChoice,
  							    ElectraForPreTraining,
  							    ElectraForQuestionAnswering,
  							    ElectraForSequenceClassification,
  							    ElectraForTokenClassification,
  							    ElectraModel,
  							)
  							from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST
  
  
  
  
  class      __lowercase	:
  
  
  
  
  
  
  	def __init__(self							:   List[Any]			,  snake_case							:   Dict			,  snake_case							:   Optional[Any]=13			,  snake_case							:   Optional[Any]=7			,  snake_case							:   Optional[int]=True			,  snake_case							:   str=True			,  snake_case							:   Dict=True			,  snake_case							:   str=True			,  snake_case							:   int=99			,  snake_case							:   int=32			,  snake_case							:   Union[str, Any]=5			,  snake_case							:   Any=4			,  snake_case							:   Tuple=37			,  snake_case							:   Tuple="gelu"			,  snake_case							:   Tuple=0.1			,  snake_case							:   Optional[int]=0.1			,  snake_case							:   Optional[Any]=512			,  snake_case							:   Dict=16			,  snake_case							:   Optional[int]=2			,  snake_case							:   int=0.02			,  snake_case							:   int=3			,  snake_case							:   str=4			,  snake_case							:   Optional[Any]=None			,  )   -> List[Any]:
  							_lowercase					:  Dict    			=      parent
  							_lowercase					:  List[str]    			=      batch_size
  							_lowercase					:  int    			=      seq_length
  							_lowercase					:  Optional[Any]    			=      is_training
  							_lowercase					:  Tuple    			=      use_input_mask
  							_lowercase					:  Optional[int]    			=      use_token_type_ids
  							_lowercase					:  Optional[int]    			=      use_labels
  							_lowercase					:  List[Any]    			=      vocab_size
  							_lowercase					:  Union[str, Any]    			=      hidden_size
  							_lowercase					:  Dict    			=      num_hidden_layers
  							_lowercase					:  str    			=      num_attention_heads
  							_lowercase					:  int    			=      intermediate_size
  							_lowercase					:  Union[str, Any]    			=      hidden_act
  							_lowercase					:  Tuple    			=      hidden_dropout_prob
  							_lowercase					:  Union[str, Any]    			=      attention_probs_dropout_prob
  							_lowercase					:  Optional[Any]    			=      max_position_embeddings
  							_lowercase					:  str    			=      type_vocab_size
  							_lowercase					:  Dict    			=      type_sequence_label_size
  							_lowercase					:  List[Any]    			=      initializer_range
  							_lowercase					:  List[str]    			=      num_labels
  							_lowercase					:  Any    			=      num_choices
  							_lowercase					:  Any    			=      scope
  
  
  
  
  
  
  	def 			_a(self							:   Tuple						)   -> Tuple:
  							_lowercase					:  List[str]    			=      ids_tensor([self.batch_size, self.seq_length]			,  self.vocab_size						)
  
  							_lowercase					:  Dict    			=      None
  							if self.use_input_mask:
  													_lowercase					:  List[str]    			=      random_attention_mask([self.batch_size, self.seq_length]						)
  
  							_lowercase					:  Optional[Any]    			=      None
  							if self.use_token_type_ids:
  													_lowercase					:  Tuple    			=      ids_tensor([self.batch_size, self.seq_length]			,  self.type_vocab_size						)
  
  							_lowercase					:  str    			=      None
  							_lowercase					:  Optional[int]    			=      None
  							_lowercase					:  int    			=      None
  							if self.use_labels:
  													_lowercase					:  str    			=      ids_tensor([self.batch_size]			,  self.type_sequence_label_size						)
  													_lowercase					:  Any    			=      ids_tensor([self.batch_size, self.seq_length]			,  self.num_labels						)
  													_lowercase					:  Any    			=      ids_tensor([self.batch_size]			,  self.num_choices						)
  													_lowercase					:  Optional[Any]    			=      ids_tensor([self.batch_size, self.seq_length]			,  1						)
  
  							_lowercase					:  Optional[Any]    			=      self.get_config()
  
  							return (
  							    config,
  							    input_ids,
  							    token_type_ids,
  							    input_mask,
  							    sequence_labels,
  							    token_labels,
  							    choice_labels,
  							    fake_token_labels,
  							)
  
  
  
  
  
  
  	def 			_a(self							:   int						)   -> Optional[Any]:
  							return ElectraConfig(
  							    vocab_size=self.vocab_size			,  hidden_size=self.hidden_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=snake_case			,  initializer_range=self.initializer_range			,  )
  
  
  
  
  
  
  	def 			_a(self							:   List[str]						)   -> Optional[Any]:
  							(
  							    (
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						
  							)					:  Any    			=      self.prepare_config_and_inputs()
  
  							_lowercase					:  Union[str, Any]    			=      True
  							_lowercase					:  Dict    			=      floats_tensor([self.batch_size, self.seq_length, self.hidden_size]						)
  							_lowercase					:  Tuple    			=      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 			_a(self							:   Optional[Any]			,  snake_case							:   Optional[int]			,  snake_case							:   Dict			,  snake_case							:   Dict			,  snake_case							:   Union[str, Any]			,  snake_case							:   str			,  snake_case							:   List[Any]			,  snake_case							:   Optional[int]			,  snake_case							:   Tuple			,  )   -> str:
  							_lowercase					:  Tuple    			=      ElectraModel(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  str    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case						)
  							_lowercase					:  Optional[Any]    			=      model(snake_case			,  token_type_ids=snake_case						)
  							_lowercase					:  Optional[int]    			=      model(snake_case						)
  							self.parent.assertEqual(result.last_hidden_state.shape			,  (self.batch_size, self.seq_length, self.hidden_size)						)
  
  
  
  
  
  
  	def 			_a(self							:   List[str]			,  snake_case							:   int			,  snake_case							:   Dict			,  snake_case							:   Any			,  snake_case							:   int			,  snake_case							:   Optional[Any]			,  snake_case							:   Optional[int]			,  snake_case							:   str			,  snake_case							:   Optional[Any]			,  snake_case							:   Optional[int]			,  )   -> Dict:
  							_lowercase					:  Tuple    			=      True
  							_lowercase					:  Optional[int]    			=      ElectraModel(snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  int    			=      model(
  							    snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  encoder_hidden_states=snake_case			,  encoder_attention_mask=snake_case			,  )
  							_lowercase					:  Optional[Any]    			=      model(
  							    snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  encoder_hidden_states=snake_case			,  )
  							_lowercase					:  int    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case						)
  							self.parent.assertEqual(result.last_hidden_state.shape			,  (self.batch_size, self.seq_length, self.hidden_size)						)
  
  
  
  
  
  
  	def 			_a(self							:   Tuple			,  snake_case							:   int			,  snake_case							:   Tuple			,  snake_case							:   List[Any]			,  snake_case							:   Union[str, Any]			,  snake_case							:   str			,  snake_case							:   Dict			,  snake_case							:   Dict			,  snake_case							:   Optional[Any]			,  )   -> Any:
  							_lowercase					:  Dict    			=      ElectraForMaskedLM(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  Optional[int]    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case						)
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.vocab_size)						)
  
  
  
  
  
  
  	def 			_a(self							:   Optional[Any]			,  snake_case							:   Dict			,  snake_case							:   Optional[int]			,  snake_case							:   Any			,  snake_case							:   List[Any]			,  snake_case							:   Optional[Any]			,  snake_case							:   List[str]			,  snake_case							:   Dict			,  snake_case							:   str			,  snake_case							:   str			,  )   -> Any:
  							_lowercase					:  int    			=      ElectraForCausalLM(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  Union[str, Any]    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case						)
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.vocab_size)						)
  
  
  
  
  
  
  	def 			_a(self							:   Dict			,  snake_case							:   Union[str, Any]			,  snake_case							:   List[str]			,  snake_case							:   Any			,  snake_case							:   Dict			,  snake_case							:   Tuple			,  snake_case							:   Union[str, Any]			,  snake_case							:   Dict			,  snake_case							:   Optional[int]			,  )   -> Tuple:
  							_lowercase					:  List[Any]    			=      self.num_labels
  							_lowercase					:  Dict    			=      ElectraForTokenClassification(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  Tuple    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case						)
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.num_labels)						)
  
  
  
  
  
  
  	def 			_a(self							:   str			,  snake_case							:   Union[str, Any]			,  snake_case							:   Optional[Any]			,  snake_case							:   Dict			,  snake_case							:   Dict			,  snake_case							:   str			,  snake_case							:   int			,  snake_case							:   int			,  snake_case							:   Union[str, Any]			,  )   -> Union[str, Any]:
  							_lowercase					:  List[Any]    			=      self.num_labels
  							_lowercase					:  int    			=      ElectraForPreTraining(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  List[str]    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case						)
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length)						)
  
  
  
  
  
  
  	def 			_a(self							:   List[Any]			,  snake_case							:   Optional[Any]			,  snake_case							:   Tuple			,  snake_case							:   Optional[int]			,  snake_case							:   str			,  snake_case							:   Tuple			,  snake_case							:   Union[str, Any]			,  snake_case							:   Union[str, Any]			,  snake_case							:   Dict			,  )   -> List[Any]:
  							_lowercase					:  List[str]    			=      self.num_labels
  							_lowercase					:  Tuple    			=      ElectraForSequenceClassification(snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  Any    			=      model(snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case						)
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.num_labels)						)
  
  
  
  
  
  
  	def 			_a(self							:   Tuple			,  snake_case							:   Optional[int]			,  snake_case							:   List[Any]			,  snake_case							:   List[str]			,  snake_case							:   Any			,  snake_case							:   Optional[int]			,  snake_case							:   Tuple			,  snake_case							:   Union[str, Any]			,  snake_case							:   str			,  )   -> str:
  							_lowercase					:  int    			=      ElectraForQuestionAnswering(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  Tuple    			=      model(
  							    snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  start_positions=snake_case			,  end_positions=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 			_a(self							:   Dict			,  snake_case							:   str			,  snake_case							:   Dict			,  snake_case							:   Any			,  snake_case							:   Tuple			,  snake_case							:   str			,  snake_case							:   Optional[Any]			,  snake_case							:   str			,  snake_case							:   Tuple			,  )   -> Union[str, Any]:
  							_lowercase					:  List[Any]    			=      self.num_choices
  							_lowercase					:  Optional[Any]    			=      ElectraForMultipleChoice(config=snake_case						)
  							model.to(snake_case						)
  							model.eval()
  							_lowercase					:  str    			=      input_ids.unsqueeze(1						).expand(-1			,  self.num_choices			,  -1						).contiguous()
  							_lowercase					:  Dict    			=      token_type_ids.unsqueeze(1						).expand(-1			,  self.num_choices			,  -1						).contiguous()
  							_lowercase					:  Optional[Any]    			=      input_mask.unsqueeze(1						).expand(-1			,  self.num_choices			,  -1						).contiguous()
  							_lowercase					:  Optional[int]    			=      model(
  							    snake_case			,  attention_mask=snake_case			,  token_type_ids=snake_case			,  labels=snake_case			,  )
  							self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.num_choices)						)
  
  
  
  
  
  
  	def 			_a(self							:   Optional[Any]						)   -> Union[str, Any]:
  							_lowercase					:  Any    			=      self.prepare_config_and_inputs()
  							(
  							    (
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						(
  							    _lowercase
  							)			,						
  							)					:  Optional[int]    			=      config_and_inputs
  							_lowercase					:  Optional[Any]    			=      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
  							return config, inputs_dict
  
  
  
  
  @require_torch
  class      __lowercase	(	__snake_case      ,   __snake_case      ,   unittest.TestCase					):
  	_A   			=      (
  	    (
  	        ElectraModel,
  	        ElectraForPreTraining,
  	        ElectraForMaskedLM,
  	        ElectraForCausalLM,
  	        ElectraForMultipleChoice,
  	        ElectraForTokenClassification,
  	        ElectraForSequenceClassification,
  	        ElectraForQuestionAnswering,
  	    )
  	    if is_torch_available()
  	    else ()
  	)
  	_A   			=      (
  	    {
  	        "feature-extraction": ElectraModel,
  	        "fill-mask": ElectraForMaskedLM,
  	        "question-answering": ElectraForQuestionAnswering,
  	        "text-classification": ElectraForSequenceClassification,
  	        "text-generation": ElectraForCausalLM,
  	        "token-classification": ElectraForTokenClassification,
  	        "zero-shot": ElectraForSequenceClassification,
  	    }
  	    if is_torch_available()
  	    else {}
  	)
  	_A   			=      True
  
  
  
  
  
  
  	def 			_a(self							:   Union[str, Any]			,  snake_case							:   Any			,  snake_case							:   List[Any]			,  snake_case							:   Any=False						)   -> Optional[int]:
  							_lowercase					:  Any    			=      super()._prepare_for_class(snake_case			,  snake_case			,  return_labels=snake_case						)
  
  							if return_labels:
  													if model_class in get_values(snake_case						):
  																			_lowercase					:  List[str]    			=      torch.zeros(
  																			    (self.model_tester.batch_size, self.model_tester.seq_length)			,  dtype=torch.long			,  device=snake_case						)
  							return inputs_dict
  
  
  
  
  
  
  	def 			_a(self							:   List[str]						)   -> List[Any]:
  							_lowercase					:  Tuple    			=      ElectraModelTester(self						)
  							_lowercase					:  int    			=      ConfigTester(self			,  config_class=snake_case			,  hidden_size=37						)
  
  
  
  
  
  
  	def 			_a(self							:   int						)   -> Any:
  							self.config_tester.run_common_tests()
  
  
  
  
  
  
  	def 			_a(self							:   Optional[Any]						)   -> str:
  							_lowercase					:  List[str]    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_model(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   List[Any]						)   -> str:
  							_lowercase					:  Union[str, Any]    			=      self.model_tester.prepare_config_and_inputs_for_decoder()
  							self.model_tester.create_and_check_electra_model_as_decoder(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Tuple						)   -> Dict:
  							_lowercase					:  str    			=      self.model_tester.prepare_config_and_inputs()
  							for type in ["absolute", "relative_key", "relative_key_query"]:
  													_lowercase					:  List[Any]    			=      type
  													self.model_tester.create_and_check_electra_model(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Optional[int]						)   -> str:
  							_lowercase					:  int    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_masked_lm(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   str						)   -> Dict:
  							_lowercase					:  Optional[Any]    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_token_classification(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Dict						)   -> Optional[Any]:
  							_lowercase					:  Any    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_pretraining(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Union[str, Any]						)   -> Optional[int]:
  							_lowercase					:  Dict    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_sequence_classification(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Any						)   -> Dict:
  							_lowercase					:  Any    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_question_answering(*snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   Tuple						)   -> Tuple:
  							_lowercase					:  Union[str, Any]    			=      self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_electra_for_multiple_choice(*snake_case						)
  
  
  
  
  
  
  	@slow
  	def 			_a(self							:   List[str]						)   -> List[Any]:
  							for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  													_lowercase					:  Optional[int]    			=      ElectraModel.from_pretrained(snake_case						)
  													self.assertIsNotNone(snake_case						)
  
  
  
  
  
  
  	def 			_a(self							:   List[Any]						)   -> List[Any]:
  							_lowercase					:  int    			=      self.model_tester.prepare_config_and_inputs_for_decoder()
  							self.model_tester.create_and_check_electra_for_causal_lm(*snake_case						)
  
  
  
  
  @require_torch
  class      __lowercase	(	unittest.TestCase					):
  
  
  
  
  
  
  	@slow
  	def 			_a(self							:   str						)   -> Optional[int]:
  							_lowercase					:  int    			=      ElectraModel.from_pretrained("google/electra-small-discriminator"						)
  							_lowercase					:  Dict    			=      torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]						)
  							_lowercase					:  Union[str, Any]    			=      torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
  							_lowercase					:  Optional[Any]    			=      model(snake_case			,  attention_mask=snake_case						)[0]
  							_lowercase					:  Union[str, Any]    			=      torch.Size((1, 11, 256)						)
  							self.assertEqual(output.shape			,  snake_case						)
  							_lowercase					:  List[Any]    			=      torch.tensor(
  							    [[[0.44_71, 0.68_21, -0.32_65], [0.46_27, 0.52_55, -0.36_68], [0.45_32, 0.33_13, -0.43_44]]]						)
  
  							self.assertTrue(torch.allclose(output[:, 1:4, 1:4]			,  snake_case			,  atol=1e-4						)						)
  
  
  
  
  