code: from __future__ import annotations
  
  import unittest
  
  from transformers import AutoTokenizer, GPTJConfig, is_tf_available
  from transformers.testing_utils import require_tf, slow, tooslow
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
  from ...test_pipeline_mixin import PipelineTesterMixin
  from ...utils.test_modeling_tf_core import TFCoreModelTesterMixin
  
  
  if is_tf_available():
   import tensorflow as tf
  
   from transformers.models.gptj.modeling_tf_gptj import (
       TFGPTJForCausalLM,
       TFGPTJForQuestionAnswering,
       TFGPTJForSequenceClassification,
       TFGPTJModel,
       shape_list,
   )
  
  
  
  
  class    __lowerCAmelCase  :
  
  
  
   '''simple docstring'''
  
   def __init__(			self       :		Dict       ,			lowerCamelCase       :		Optional[Any]  ) ->							str:
          _UpperCamelCase     :       Tuple  						=  parent
          _UpperCamelCase     :       Optional[Any]  						=  1_3
          _UpperCamelCase     :       Union[str, Any]  						=  7
          _UpperCamelCase     :       List[Any]  						=  True
          _UpperCamelCase     :       List[str]  						=  True
          _UpperCamelCase     :       List[Any]  						=  True
          _UpperCamelCase     :       Dict  						=  True
          _UpperCamelCase     :       Tuple  						=  True
          _UpperCamelCase     :       Tuple  						=  9_9
          _UpperCamelCase     :       Any  						=  3_2
          _UpperCamelCase     :       Optional[Any]  						=  4
          _UpperCamelCase     :       Union[str, Any]  						=  2
          _UpperCamelCase     :       Dict  						=  4
          _UpperCamelCase     :       Dict  						=  3_7
          _UpperCamelCase     :       str  						=  'gelu'
          _UpperCamelCase     :       Any  						=  0.1
          _UpperCamelCase     :       Optional[Any]  						=  0.1
          _UpperCamelCase     :       Optional[int]  						=  5_1_2
          _UpperCamelCase     :       int  						=  1_6
          _UpperCamelCase     :       Union[str, Any]  						=  2
          _UpperCamelCase     :       Dict  						=  0.0_2
          _UpperCamelCase     :       List[str]  						=  3
          _UpperCamelCase     :       Any  						=  4
          _UpperCamelCase     :       Optional[Any]  						=  None
          _UpperCamelCase     :       List[Any]  						=  self.vocab_size - 1
          _UpperCamelCase     :       Any  						=  self.vocab_size - 1
          _UpperCamelCase     :       Tuple  						=  self.vocab_size - 1
  
   def 					__snake_case					(			self       :		Tuple  ) ->							Optional[Any]:
          _UpperCamelCase     :       Tuple  						=  ids_tensor([self.batch_size, self.seq_length]       ,			self.vocab_size  )
  
          _UpperCamelCase     :       Optional[Any]  						=  None
          if self.use_input_mask:
                 _UpperCamelCase     :       str  						=  random_attention_mask([self.batch_size, self.seq_length]  )
  
          _UpperCamelCase     :       str  						=  None
          if self.use_token_type_ids:
                 _UpperCamelCase     :       str  						=  ids_tensor([self.batch_size, self.seq_length]       ,			self.type_vocab_size  )
  
          _UpperCamelCase     :       Union[str, Any]  						=  None
          if self.use_mc_token_ids:
                 _UpperCamelCase     :       Any  						=  ids_tensor([self.batch_size, self.num_choices]       ,			self.seq_length  )
  
          _UpperCamelCase     :       List[str]  						=  None
          _UpperCamelCase     :       Tuple  						=  None
          _UpperCamelCase     :       Union[str, Any]  						=  None
          if self.use_labels:
                 _UpperCamelCase     :       Dict  						=  ids_tensor([self.batch_size]       ,			self.type_sequence_label_size  )
                 _UpperCamelCase     :       Optional[Any]  						=  ids_tensor([self.batch_size, self.seq_length]       ,			self.num_labels  )
                 _UpperCamelCase     :       Dict  						=  ids_tensor([self.batch_size]       ,			self.num_choices  )
  
          _UpperCamelCase     :       int  						=  GPTJConfig(
              vocab_size=self.vocab_size       ,			n_embd=self.hidden_size       ,			n_layer=self.num_hidden_layers       ,			n_head=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       ,			n_positions=self.max_position_embeddings       ,			type_vocab_size=self.type_vocab_size       ,			initializer_range=self.initializer_range       ,			bos_token_id=self.bos_token_id       ,			eos_token_id=self.eos_token_id       ,			pad_token_id=self.pad_token_id       ,			rotary_dim=self.rotary_dim       ,			return_dict=a_       ,			)
  
          _UpperCamelCase     :       Tuple  						=  ids_tensor([self.num_hidden_layers, self.num_attention_heads]       ,			2  )
  
          return (
              config,
              input_ids,
              input_mask,
              head_mask,
              token_type_ids,
              mc_token_ids,
              sequence_labels,
              token_labels,
              choice_labels,
          )
  
   def 					__snake_case					(			self       :		Any       ,			lowerCamelCase       :		List[str]       ,			lowerCamelCase       :		int       ,			lowerCamelCase       :		int       ,			lowerCamelCase       :		Optional[Any]       ,			lowerCamelCase       :		List[str]       ,			*lowerCamelCase       :		Tuple  ) ->							List[Any]:
          _UpperCamelCase     :       Optional[int]  						=  TFGPTJModel(config=a_  )
          _UpperCamelCase     :       Optional[Any]  						=  {
              'input_ids': input_ids,
              'attention_mask': input_mask,
              'token_type_ids': token_type_ids,
          }
          _UpperCamelCase     :       Optional[Any]  						=  model(a_  )
  
          _UpperCamelCase     :       List[str]  						=  [input_ids, None, input_mask]  # None is the input for 'past'
          _UpperCamelCase     :       int  						=  model(a_  )
  
          _UpperCamelCase     :       str  						=  model(a_  )
  
          self.parent.assertEqual(result.last_hidden_state.shape       ,			(self.batch_size, self.seq_length, self.hidden_size)  )
  
   def 					__snake_case					(			self       :		Any       ,			lowerCamelCase       :		List[str]       ,			lowerCamelCase       :		str       ,			lowerCamelCase       :		List[str]       ,			lowerCamelCase       :		Union[str, Any]       ,			lowerCamelCase       :		Optional[int]       ,			*lowerCamelCase       :		int  ) ->							List[str]:
          _UpperCamelCase     :       Optional[int]  						=  TFGPTJModel(config=a_  )
  
          # first forward pass
          _UpperCamelCase     :       List[str]  						=  model(a_       ,			token_type_ids=a_       ,			use_cache=a_  )
          _UpperCamelCase     :       Tuple  						=  model(a_       ,			token_type_ids=a_  )
          _UpperCamelCase     :       Union[str, Any]  						=  model(a_       ,			token_type_ids=a_       ,			use_cache=a_  )
  
          self.parent.assertTrue(len(a_  ) == len(a_  )  )
          self.parent.assertTrue(len(a_  ) == len(a_  ) + 1  )
  
          _UpperCamelCase						,      _UpperCamelCase     :       List[Any]  						=  outputs.to_tuple()
  
          # create hypothetical next token and extent to next_input_ids
          _UpperCamelCase     :       int  						=  ids_tensor((self.batch_size, 1)       ,			config.vocab_size  )
          _UpperCamelCase     :       List[Any]  						=  ids_tensor([self.batch_size, 1]       ,			self.type_vocab_size  )
  
          # append to next input_ids and token_type_ids
          _UpperCamelCase     :       int  						=  tf.concat([input_ids, next_tokens]       ,			axis=-1  )
          _UpperCamelCase     :       Union[str, Any]  						=  tf.concat([token_type_ids, next_token_types]       ,			axis=-1  )
  
          _UpperCamelCase     :       Tuple  						=  model(a_       ,			token_type_ids=a_  )['last_hidden_state']
          _UpperCamelCase     :       Tuple  						=  model(a_       ,			token_type_ids=a_       ,			past_key_values=a_  )[
              'last_hidden_state'
          ]
  
          # select random slice
          _UpperCamelCase     :       Union[str, Any]  						=  int(ids_tensor((1,)       ,			shape_list(a_  )[-1]  )  )
          _UpperCamelCase     :       List[str]  						=  output_from_no_past[:, -1, random_slice_idx]
          _UpperCamelCase     :       Any  						=  output_from_past[:, 0, random_slice_idx]
  
          # test that outputs are equal for slice
          tf.debugging.assert_near(a_       ,			a_       ,			rtol=1e-6  )
  
   def 					__snake_case					(			self       :		Any       ,			lowerCamelCase       :		Union[str, Any]       ,			lowerCamelCase       :		Any       ,			lowerCamelCase       :		Optional[int]       ,			lowerCamelCase       :		str       ,			lowerCamelCase       :		str       ,			*lowerCamelCase       :		Any  ) ->							Union[str, Any]:
          _UpperCamelCase     :       int  						=  TFGPTJModel(config=a_  )
  
          # create attention mask
          _UpperCamelCase     :       Union[str, Any]  						=  self.seq_length // 2
          _UpperCamelCase     :       Union[str, Any]  						=  tf.ones((self.batch_size, half_seq_length)       ,			dtype=tf.intaa  )
          _UpperCamelCase     :       Optional[Any]  						=  tf.zeros((self.batch_size, self.seq_length - half_seq_length)       ,			dtype=tf.intaa  )
          _UpperCamelCase     :       str  						=  tf.concat([attn_mask_begin, attn_mask_end]       ,			axis=1  )
  
          # first forward pass
          _UpperCamelCase						,      _UpperCamelCase     :       Union[str, Any]  						=  model(a_       ,			attention_mask=a_  ).to_tuple()
  
          # create hypothetical next token and extent to next_input_ids
          _UpperCamelCase     :       Dict  						=  ids_tensor((self.batch_size, 1)       ,			config.vocab_size  )
  
          # change a random masked slice from input_ids
          _UpperCamelCase     :       Optional[int]  						=  ids_tensor((1,)       ,			a_  ).numpy() + 1
          _UpperCamelCase     :       Optional[Any]  						=  ids_tensor((self.batch_size, self.seq_length)       ,			config.vocab_size  )
          _UpperCamelCase     :       Optional[Any]  						=  tf.range(self.seq_length  ) == (self.seq_length - random_seq_idx_to_change)
          _UpperCamelCase     :       Tuple  						=  tf.transpose(
              tf.broadcast_to(tf.expand_dims(a_       ,			-1  )       ,			(self.seq_length, self.batch_size)  )  )
          _UpperCamelCase     :       Optional[Any]  						=  tf.where(a_       ,			a_       ,			a_  )
  
          # append to next input_ids and attn_mask
          _UpperCamelCase     :       Dict  						=  tf.concat([input_ids, next_tokens]       ,			axis=-1  )
          _UpperCamelCase     :       List[str]  						=  tf.concat([attn_mask, tf.ones((shape_list(a_  )[0], 1)       ,			dtype=tf.intaa  )]       ,			axis=1  )
  
          # get two different outputs
          _UpperCamelCase     :       Union[str, Any]  						=  model(a_       ,			attention_mask=a_  )['last_hidden_state']
          _UpperCamelCase     :       Tuple  						=  model(a_       ,			past_key_values=a_       ,			attention_mask=a_  )[
              'last_hidden_state'
          ]
  
          # select random slice
          _UpperCamelCase     :       Any  						=  int(ids_tensor((1,)       ,			shape_list(a_  )[-1]  )  )
          _UpperCamelCase     :       Union[str, Any]  						=  output_from_no_past[:, -1, random_slice_idx]
          _UpperCamelCase     :       Optional[Any]  						=  output_from_past[:, 0, random_slice_idx]
  
          # test that outputs are equal for slice
          tf.debugging.assert_near(a_       ,			a_       ,			rtol=1e-12  )
  
   def 					__snake_case					(			self       :		List[str]       ,			lowerCamelCase       :		Any       ,			lowerCamelCase       :		int       ,			lowerCamelCase       :		List[Any]       ,			lowerCamelCase       :		List[Any]       ,			lowerCamelCase       :		Optional[int]       ,			*lowerCamelCase       :		List[Any]  ) ->							Optional[Any]:
          _UpperCamelCase     :       List[Any]  						=  TFGPTJModel(config=a_  )
  
          _UpperCamelCase     :       Any  						=  input_ids[:1, :]
          _UpperCamelCase     :       Dict  						=  input_mask[:1, :]
          _UpperCamelCase     :       Union[str, Any]  						=  token_type_ids[:1, :]
          _UpperCamelCase     :       Optional[int]  						=  1
  
          # first forward pass
          _UpperCamelCase     :       Optional[int]  						=  model(a_       ,			attention_mask=a_       ,			token_type_ids=a_       ,			use_cache=a_  )
  
          _UpperCamelCase						,      _UpperCamelCase     :       Union[str, Any]  						=  outputs.to_tuple()
  
          # create hypothetical next token and extent to next_input_ids
          _UpperCamelCase     :       Optional[Any]  						=  ids_tensor((self.batch_size, 3)       ,			config.vocab_size  )
          _UpperCamelCase     :       Any  						=  ids_tensor((self.batch_size, 3)       ,			2  )
          _UpperCamelCase     :       Union[str, Any]  						=  ids_tensor((self.batch_size, 3)       ,			self.type_vocab_size  )
  
          # append to next input_ids and token_type_ids
          _UpperCamelCase     :       List[str]  						=  tf.concat([input_ids, next_tokens]       ,			axis=-1  )
          _UpperCamelCase     :       Any  						=  tf.concat([input_mask, next_attn_mask]       ,			axis=-1  )
          _UpperCamelCase     :       int  						=  tf.concat([token_type_ids, next_token_types]       ,			axis=-1  )
  
          _UpperCamelCase     :       Dict  						=  model(
              a_       ,			token_type_ids=a_       ,			attention_mask=a_  )['last_hidden_state']
          _UpperCamelCase     :       List[str]  						=  model(
              a_       ,			token_type_ids=a_       ,			attention_mask=a_       ,			past_key_values=a_       ,			)['last_hidden_state']
          self.parent.assertTrue(output_from_past.shape[1] == next_tokens.shape[1]  )
  
          # select random slice
          _UpperCamelCase     :       Any  						=  int(ids_tensor((1,)       ,			shape_list(a_  )[-1]  )  )
          _UpperCamelCase     :       Any  						=  output_from_no_past[:, -3:, random_slice_idx]
          _UpperCamelCase     :       List[str]  						=  output_from_past[:, :, random_slice_idx]
  
          # test that outputs are equal for slice
          tf.debugging.assert_near(a_       ,			a_       ,			rtol=1e-3  )
  
   def 					__snake_case					(			self       :		Dict       ,			lowerCamelCase       :		Optional[Any]       ,			lowerCamelCase       :		int       ,			lowerCamelCase       :		Union[str, Any]       ,			lowerCamelCase       :		Union[str, Any]       ,			lowerCamelCase       :		Union[str, Any]       ,			*lowerCamelCase       :		List[str]  ) ->							Optional[Any]:
          _UpperCamelCase     :       List[Any]  						=  TFGPTJForCausalLM(config=a_  )
          _UpperCamelCase     :       int  						=  {
              'input_ids': input_ids,
              'attention_mask': input_mask,
              'token_type_ids': token_type_ids,
          }
          _UpperCamelCase     :       Tuple  						=  model(a_  )
          self.parent.assertEqual(result.logits.shape       ,			(self.batch_size, self.seq_length, self.vocab_size)  )
  
   def 					__snake_case					(			self       :		int  ) ->							int:
          _UpperCamelCase     :       List[str]  						=  self.prepare_config_and_inputs()
  
          (
              (
              _UpperCamelCase      
          )						,      (
              _UpperCamelCase      
          )						,      (
              _UpperCamelCase      
          )						,      (
              _UpperCamelCase      
          )						,      (
              _UpperCamelCase      
          )						,      (
              _UpperCamelCase      
          )						,      (
              _UpperCamelCase      
          )						,      (
              _UpperCamelCase      
          )						,      (
              _UpperCamelCase      
          )						,            
          )     :       Union[str, Any]  						=  config_and_inputs
  
          _UpperCamelCase     :       Optional[int]  						=  {
              'input_ids': input_ids,
              'token_type_ids': token_type_ids,
              'attention_mask': input_mask,
          }
          return config, inputs_dict
  
  
  
  
  
  
  
  @require_tf
  class    __lowerCAmelCase  (       a_,	a_,	a_,	unittest.TestCase						):
  
  
  
   '''simple docstring'''
   _lowerCamelCase						:	List[Any]				    = (
       (TFGPTJForCausalLM, TFGPTJForSequenceClassification, TFGPTJForQuestionAnswering, TFGPTJModel)
       if is_tf_available()
       else ()
   )
  
   _lowerCamelCase						:	int				    = (TFGPTJForCausalLM,) if is_tf_available() else ()
   _lowerCamelCase						:	Optional[Any]				    = (
       {
           '''feature-extraction''': TFGPTJModel,
           '''question-answering''': TFGPTJForQuestionAnswering,
           '''text-classification''': TFGPTJForSequenceClassification,
           '''text-generation''': TFGPTJForCausalLM,
           '''zero-shot''': TFGPTJForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   _lowerCamelCase						:	Dict				    = False
   _lowerCamelCase						:	Optional[int]				    = False
   _lowerCamelCase						:	List[Any]				    = False
   _lowerCamelCase						:	List[str]				    = False
  
   def 					__snake_case					(			self       :		List[Any]       ,			lowerCamelCase       :		Dict       ,			lowerCamelCase       :		int       ,			lowerCamelCase       :		Optional[int]       ,			lowerCamelCase       :		Tuple       ,			lowerCamelCase       :		List[str]  ) ->							List[str]:
          if (
              pipeline_test_casse_name == "QAPipelineTests"
              and tokenizer_name is not None
              and not tokenizer_name.endswith('Fast'  )
          ):
                 # `QAPipelineTests` fails for a few models when the slower tokenizer are used.
                 # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
                 # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
                 return True
  
          return False
  
   def 					__snake_case					(			self       :		List[Any]  ) ->							str:
          _UpperCamelCase     :       List[Any]  						=  TFGPTJModelTester(self  )
          _UpperCamelCase     :       Union[str, Any]  						=  ConfigTester(self       ,			config_class=a_       ,			n_embd=3_7  )
  
   def 					__snake_case					(			self       :		str  ) ->							Any:
          self.config_tester.run_common_tests()
  
   def 					__snake_case					(			self       :		str  ) ->							Union[str, Any]:
          _UpperCamelCase     :       Any  						=  self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_gptj_model(*a_  )
  
   def 					__snake_case					(			self       :		Dict  ) ->							List[Any]:
          _UpperCamelCase     :       List[str]  						=  self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_gptj_model_past(*a_  )
  
   def 					__snake_case					(			self       :		Any  ) ->							Optional[Any]:
          _UpperCamelCase     :       List[str]  						=  self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_gptj_model_attention_mask_past(*a_  )
  
   def 					__snake_case					(			self       :		Union[str, Any]  ) ->							List[str]:
          _UpperCamelCase     :       List[str]  						=  self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_gptj_model_past_large_inputs(*a_  )
  
   def 					__snake_case					(			self       :		Any  ) ->							int:
          _UpperCamelCase     :       int  						=  self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_gptj_lm_head_model(*a_  )
  
   @slow
   @unittest.skipIf(
       not is_tf_available() or len(tf.config.list_physical_devices('GPU'  )  ) > 0       ,			'skip testing on GPU for now to avoid GPU OOM.'       ,			)
   def 					__snake_case					(			self       :		str  ) ->							Optional[Any]:
          _UpperCamelCase     :       Tuple  						=  TFGPTJModel.from_pretrained('EleutherAI/gpt-j-6B'       ,			from_pt=a_  )
          self.assertIsNotNone(a_  )
  
   @unittest.skip(reason='Currently, model embeddings are going to undergo a major refactor.'  )
   def 					__snake_case					(			self       :		List[str]  ) ->							str:
          super().test_resize_token_embeddings()
  
  
  
  
  
  
  
  @require_tf
  @tooslow
  # Marked as @tooslow due to GPU OOM -- but still useful to run locally. Requires ~39GB of RAM.
  class    __lowerCAmelCase  (       unittest.TestCase						):
  
  
  
   '''simple docstring'''
  
   def 					__snake_case					(			self       :		int  ) ->							Tuple:
          _UpperCamelCase     :       Union[str, Any]  						=  TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B'       ,			from_pt=a_  )
          _UpperCamelCase     :       List[str]  						=  tf.convert_to_tensor([[4_6_4, 3_2_9_0]]       ,			dtype=tf.intaa  )  # The dog
          # fmt: off
          # The dog is a man's best friend. It is a loyal companion, and it is a friend
          _UpperCamelCase     :       List[Any]  						=  [4_6_4, 3_2_9_0, 3_1_8, 2_5_7, 5_8_2, 3_3_8, 1_2_6_6, 1_5_4_5, 1_3, 6_3_2, 3_1_8, 2_5_7, 9_1_1_2, 1_5_1_8_5, 1_1, 2_9_0, 3_4_0, 3_1_8, 2_5_7, 1_5_4_5]
          # fmt: on
          _UpperCamelCase     :       Tuple  						=  model.generate(a_       ,			do_sample=a_  )
          self.assertListEqual(output_ids[0].numpy().tolist()       ,			a_  )
  
   def 					__snake_case					(			self       :		Any  ) ->							Dict:
          _UpperCamelCase     :       int  						=  AutoTokenizer.from_pretrained('EleutherAI/gpt-j-6B'       ,			revision='float16'  )
          _UpperCamelCase     :       Optional[int]  						=  TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B'       ,			revision='float16'       ,			from_pt=a_  )
  
          _UpperCamelCase     :       Any  						=  tokenizer('Today is a nice day and'       ,			return_tensors='tf'  )
          # forces the generation to happen on CPU, to avoid GPU-related quirks
          with tf.device(':/CPU:0'  ):
                 _UpperCamelCase     :       Tuple  						=  model.generate(**a_       ,			do_sample=a_       ,			seed=[4_2, 0]  )
          _UpperCamelCase     :       List[str]  						=  tokenizer.decode(output_ids[0]       ,			skip_special_tokens=a_  )
  
          _UpperCamelCase     :       Union[str, Any]  						=  'Today is a nice day and I’m going to go for a walk. I’'
          self.assertEqual(a_       ,			a_  )
  
   def 					__snake_case					(			self       :		Any  ) ->							int:
          _UpperCamelCase     :       str  						=  TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B'       ,			revision='float16'       ,			from_pt=a_  )
          _UpperCamelCase     :       str  						=  AutoTokenizer.from_pretrained('EleutherAI/gpt-j-6B'       ,			revision='float16'  )
  
          _UpperCamelCase     :       str  						=  'left'
  
          # Define PAD Token = EOS Token = 50256
          _UpperCamelCase     :       Optional[int]  						=  tokenizer.eos_token
          _UpperCamelCase     :       Tuple  						=  model.config.eos_token_id
  
          # use different length sentences to test batching
          _UpperCamelCase     :       List[str]  						=  [
              'Hello, my dog is a little',
              'Today, I',
          ]
          _UpperCamelCase     :       int  						=  [
              'Hello, my dog is a little over a year old and has been diagnosed with hip dysplasia',
              'Today, I’m going to be talking about a topic that’',
          ]
          return model, tokenizer, sentences, expected_output_sentences
  
   def 					__snake_case					(			self       :		Dict  ) ->							Optional[Any]:
          # Confirms that we get the expected results with left-padded beam search
          _UpperCamelCase						,      _UpperCamelCase						,      _UpperCamelCase						,      _UpperCamelCase     :       int  						=  self._get_beam_search_test_objects()
  
          _UpperCamelCase     :       Optional[int]  						=  tokenizer(a_       ,			return_tensors='tf'       ,			padding=a_  )
          _UpperCamelCase     :       List[str]  						=  model.generate(**a_       ,			do_sample=a_       ,			num_beams=2  )
          _UpperCamelCase     :       List[str]  						=  tokenizer.batch_decode(a_       ,			skip_special_tokens=a_  )
          self.assertListEqual(a_       ,			a_  )
  
   def 					__snake_case					(			self       :		Any  ) ->							List[str]:
          # Confirms that left-padding is working properly
          _UpperCamelCase						,      _UpperCamelCase						,      _UpperCamelCase						,      _UpperCamelCase     :       int  						=  self._get_beam_search_test_objects()
  
          _UpperCamelCase     :       int  						=  tokenizer(a_       ,			return_tensors='tf'       ,			padding=a_  )
          _UpperCamelCase     :       List[str]  						=  tokenizer(sentences[0]       ,			return_tensors='tf'  )
          _UpperCamelCase     :       Union[str, Any]  						=  model.generate(**a_       ,			do_sample=a_       ,			num_beams=2  )
          _UpperCamelCase     :       Optional[Any]  						=  (
              shape_list(inputs_non_padded['input_ids']  )[-1]
              - tf.reduce_sum(tf.cast(inputs['attention_mask'][-1]       ,			tf.intaa  )  ).numpy()
          )
          _UpperCamelCase     :       int  						=  tokenizer(sentences[1]       ,			return_tensors='tf'  )
          _UpperCamelCase     :       Optional[int]  						=  model.generate(
              **a_       ,			do_sample=a_       ,			num_beams=2       ,			max_length=model.config.max_length - num_paddings  )
          _UpperCamelCase     :       Optional[Any]  						=  tokenizer.decode(output_non_padded[0]       ,			skip_special_tokens=a_  )
          _UpperCamelCase     :       Dict  						=  tokenizer.decode(output_padded[0]       ,			skip_special_tokens=a_  )
          self.assertListEqual(a_       ,			[non_padded_sentence, padded_sentence]  )
  
   def 					__snake_case					(			self       :		int  ) ->							str:
          # Confirms that XLA is working properly
          _UpperCamelCase						,      _UpperCamelCase						,      _UpperCamelCase						,      _UpperCamelCase     :       Union[str, Any]  						=  self._get_beam_search_test_objects()
  
          _UpperCamelCase     :       Optional[Any]  						=  tokenizer(a_       ,			return_tensors='tf'       ,			padding=a_  )
          _UpperCamelCase     :       List[str]  						=  tf.function(model.generate       ,			jit_compile=a_  )
          _UpperCamelCase     :       List[Any]  						=  xla_generate(**a_       ,			do_sample=a_       ,			num_beams=2  )
          _UpperCamelCase     :       List[str]  						=  tokenizer.batch_decode(a_       ,			skip_special_tokens=a_  )
          self.assertListEqual(a_       ,			a_  )
  
  
  
  
style_context: from .chunk_utils import chunk_layer
  from .data_transforms import make_atomaa_masks
  from .feats import atomaa_to_atomaa, frames_and_literature_positions_to_atomaa_pos, torsion_angles_to_frames
  from .loss import compute_predicted_aligned_error, compute_tm
  from .protein import Protein as OFProtein
  from .protein import to_pdb
  from .rigid_utils import Rigid, Rotation
  from .tensor_utils import dict_multimap, flatten_final_dims, permute_final_dims
  
  
  
  