



"""simple docstring"""

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							:					List[str]    ,					_SCREAMING_SNAKE_CASE							:					Dict						)	->  str:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       List[Any] 							=    parent
					SCREAMING_SNAKE_CASE	:       List[Any] 							=    13
					SCREAMING_SNAKE_CASE	:       str 							=    7
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    True
					SCREAMING_SNAKE_CASE	:       Tuple 							=    True
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    True
					SCREAMING_SNAKE_CASE	:       Dict 							=    True
					SCREAMING_SNAKE_CASE	:       Tuple 							=    True
					SCREAMING_SNAKE_CASE	:       str 							=    99
					SCREAMING_SNAKE_CASE	:       List[Any] 							=    32
					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    4
					SCREAMING_SNAKE_CASE	:       Dict 							=    2
					SCREAMING_SNAKE_CASE	:       Tuple 							=    4
					SCREAMING_SNAKE_CASE	:       str 							=    37
					SCREAMING_SNAKE_CASE	:       str 							=    'gelu'
					SCREAMING_SNAKE_CASE	:       Tuple 							=    0.1
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    0.1
					SCREAMING_SNAKE_CASE	:       Any 							=    512
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    16
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    2
					SCREAMING_SNAKE_CASE	:       Any 							=    0.0_2
					SCREAMING_SNAKE_CASE	:       List[str] 							=    3
					SCREAMING_SNAKE_CASE	:       Any 							=    4
					SCREAMING_SNAKE_CASE	:       List[str] 							=    None
					SCREAMING_SNAKE_CASE	:       Tuple 							=    self.vocab_size - 1
					SCREAMING_SNAKE_CASE	:       Any 							=    self.vocab_size - 1
					SCREAMING_SNAKE_CASE	:       List[Any] 							=    self.vocab_size - 1





	def  _lowerCAmelCase    (			self							:					Tuple						)	->  Optional[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Tuple 							=    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	:       str 							=    random_attention_mask([self.batch_size, self.seq_length]						)

					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    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	:       Tuple 							=    None
					if self.use_mc_token_ids:
									SCREAMING_SNAKE_CASE	:       int 							=    ids_tensor([self.batch_size, self.num_choices]    ,					self.seq_length						)

					SCREAMING_SNAKE_CASE	:       str 							=    None
					SCREAMING_SNAKE_CASE	:       List[Any] 							=    None
					SCREAMING_SNAKE_CASE	:       Dict 							=    None
					if self.use_labels:
									SCREAMING_SNAKE_CASE	:       List[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	:       Optional[Any] 							=    ids_tensor([self.batch_size]    ,					self.num_choices						)

					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    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_    ,					)

					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    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  _lowerCAmelCase    (			self							:					Optional[int]    ,					_SCREAMING_SNAKE_CASE							:					Union[str, Any]    ,					_SCREAMING_SNAKE_CASE							:					Tuple    ,					_SCREAMING_SNAKE_CASE							:					List[str]    ,					_SCREAMING_SNAKE_CASE							:					int    ,					_SCREAMING_SNAKE_CASE							:					Tuple    ,					*_SCREAMING_SNAKE_CASE							:					Union[str, Any]						)	->  List[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       List[Any] 							=    TFGPTJModel(config=a_						)
					SCREAMING_SNAKE_CASE	:       int 							=    {
					    'input_ids': input_ids,
					    'attention_mask': input_mask,
					    'token_type_ids': token_type_ids,
					}
					SCREAMING_SNAKE_CASE	:       Dict 							=    model(a_						)

					SCREAMING_SNAKE_CASE	:       int 							=    [input_ids, None, input_mask]  # None is the input for 'past'
					SCREAMING_SNAKE_CASE	:       List[str] 							=    model(a_						)

					SCREAMING_SNAKE_CASE	:       str 							=    model(a_						)

					self.parent.assertEqual(result.last_hidden_state.shape    ,					(self.batch_size, self.seq_length, self.hidden_size)						)





	def  _lowerCAmelCase    (			self							:					Tuple    ,					_SCREAMING_SNAKE_CASE							:					str    ,					_SCREAMING_SNAKE_CASE							:					Tuple    ,					_SCREAMING_SNAKE_CASE							:					Tuple    ,					_SCREAMING_SNAKE_CASE							:					Optional[int]    ,					_SCREAMING_SNAKE_CASE							:					List[Any]    ,					*_SCREAMING_SNAKE_CASE							:					Union[str, Any]						)	->  List[str]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    TFGPTJModel(config=a_						)

					# first forward pass
					SCREAMING_SNAKE_CASE	:       List[Any] 							=    model(a_    ,					token_type_ids=a_    ,					use_cache=a_						)
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    model(a_    ,					token_type_ids=a_						)
					SCREAMING_SNAKE_CASE	:       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						)

					SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE	:       Any 							=    outputs.to_tuple()

					# create hypothetical next token and extent to next_input_ids
					SCREAMING_SNAKE_CASE	:       Dict 							=    ids_tensor((self.batch_size, 1)    ,					config.vocab_size						)
					SCREAMING_SNAKE_CASE	:       int 							=    ids_tensor([self.batch_size, 1]    ,					self.type_vocab_size						)

					# append to next input_ids and token_type_ids
					SCREAMING_SNAKE_CASE	:       List[str] 							=    tf.concat([input_ids, next_tokens]    ,					axis=-1						)
					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    tf.concat([token_type_ids, next_token_types]    ,					axis=-1						)

					SCREAMING_SNAKE_CASE	:       List[str] 							=    model(a_    ,					token_type_ids=a_						)['last_hidden_state']
					SCREAMING_SNAKE_CASE	:       str 							=    model(a_    ,					token_type_ids=a_    ,					past_key_values=a_						)[
					    'last_hidden_state'
					]

					# select random slice
					SCREAMING_SNAKE_CASE	:       Tuple 							=    int(ids_tensor((1,)    ,					shape_list(a_						)[-1]						)						)
					SCREAMING_SNAKE_CASE	:       str 							=    output_from_no_past[:, -1, random_slice_idx]
					SCREAMING_SNAKE_CASE	:       Union[str, 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  _lowerCAmelCase    (			self							:					str    ,					_SCREAMING_SNAKE_CASE							:					Any    ,					_SCREAMING_SNAKE_CASE							:					str    ,					_SCREAMING_SNAKE_CASE							:					str    ,					_SCREAMING_SNAKE_CASE							:					str    ,					_SCREAMING_SNAKE_CASE							:					Optional[int]    ,					*_SCREAMING_SNAKE_CASE							:					Union[str, Any]						)	->  Union[str, Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       int 							=    TFGPTJModel(config=a_						)

					# create attention mask
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    self.seq_length // 2
					SCREAMING_SNAKE_CASE	:       Tuple 							=    tf.ones((self.batch_size, half_seq_length)    ,					dtype=tf.intaa						)
					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    tf.zeros((self.batch_size, self.seq_length - half_seq_length)    ,					dtype=tf.intaa						)
					SCREAMING_SNAKE_CASE	:       Dict 							=    tf.concat([attn_mask_begin, attn_mask_end]    ,					axis=1						)

					# first forward pass
					SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE	:       List[str] 							=    model(a_    ,					attention_mask=a_						).to_tuple()

					# create hypothetical next token and extent to next_input_ids
					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    ids_tensor((self.batch_size, 1)    ,					config.vocab_size						)

					# change a random masked slice from input_ids
					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    ids_tensor((1,)    ,					a_						).numpy() + 1
					SCREAMING_SNAKE_CASE	:       Dict 							=    ids_tensor((self.batch_size, self.seq_length)    ,					config.vocab_size						)
					SCREAMING_SNAKE_CASE	:       Tuple 							=    tf.range(self.seq_length						) == (self.seq_length - random_seq_idx_to_change)
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    tf.transpose(
					    tf.broadcast_to(tf.expand_dims(a_    ,					-1						)    ,					(self.seq_length, self.batch_size)						)						)
					SCREAMING_SNAKE_CASE	:       List[str] 							=    tf.where(a_    ,					a_    ,					a_						)

					# append to next input_ids and attn_mask
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    tf.concat([input_ids, next_tokens]    ,					axis=-1						)
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    tf.concat([attn_mask, tf.ones((shape_list(a_						)[0], 1)    ,					dtype=tf.intaa						)]    ,					axis=1						)

					# get two different outputs
					SCREAMING_SNAKE_CASE	:       List[Any] 							=    model(a_    ,					attention_mask=a_						)['last_hidden_state']
					SCREAMING_SNAKE_CASE	:       List[Any] 							=    model(a_    ,					past_key_values=a_    ,					attention_mask=a_						)[
					    'last_hidden_state'
					]

					# select random slice
					SCREAMING_SNAKE_CASE	:       str 							=    int(ids_tensor((1,)    ,					shape_list(a_						)[-1]						)						)
					SCREAMING_SNAKE_CASE	:       str 							=    output_from_no_past[:, -1, random_slice_idx]
					SCREAMING_SNAKE_CASE	:       List[Any] 							=    output_from_past[:, 0, random_slice_idx]

					# test that outputs are equal for slice
					tf.debugging.assert_near(a_    ,					a_    ,					rtol=1E-1_2						)





	def  _lowerCAmelCase    (			self							:					Any    ,					_SCREAMING_SNAKE_CASE							:					Tuple    ,					_SCREAMING_SNAKE_CASE							:					Union[str, Any]    ,					_SCREAMING_SNAKE_CASE							:					Dict    ,					_SCREAMING_SNAKE_CASE							:					str    ,					_SCREAMING_SNAKE_CASE							:					List[str]    ,					*_SCREAMING_SNAKE_CASE							:					Dict						)	->  Optional[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    TFGPTJModel(config=a_						)

					SCREAMING_SNAKE_CASE	:       Dict 							=    input_ids[:1, :]
					SCREAMING_SNAKE_CASE	:       Dict 							=    input_mask[:1, :]
					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    token_type_ids[:1, :]
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    1

					# first forward pass
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    model(a_    ,					attention_mask=a_    ,					token_type_ids=a_    ,					use_cache=a_						)

					SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE	:       int 							=    outputs.to_tuple()

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

					# append to next input_ids and token_type_ids
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    tf.concat([input_ids, next_tokens]    ,					axis=-1						)
					SCREAMING_SNAKE_CASE	:       Dict 							=    tf.concat([input_mask, next_attn_mask]    ,					axis=-1						)
					SCREAMING_SNAKE_CASE	:       Any 							=    tf.concat([token_type_ids, next_token_types]    ,					axis=-1						)

					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    model(
					    a_    ,					token_type_ids=a_    ,					attention_mask=a_						)['last_hidden_state']
					SCREAMING_SNAKE_CASE	:       Dict 							=    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
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    int(ids_tensor((1,)    ,					shape_list(a_						)[-1]						)						)
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    output_from_no_past[:, -3:, random_slice_idx]
					SCREAMING_SNAKE_CASE	:       Tuple 							=    output_from_past[:, :, random_slice_idx]

					# test that outputs are equal for slice
					tf.debugging.assert_near(a_    ,					a_    ,					rtol=1E-3						)





	def  _lowerCAmelCase    (			self							:					str    ,					_SCREAMING_SNAKE_CASE							:					Union[str, Any]    ,					_SCREAMING_SNAKE_CASE							:					Optional[int]    ,					_SCREAMING_SNAKE_CASE							:					Optional[int]    ,					_SCREAMING_SNAKE_CASE							:					List[str]    ,					_SCREAMING_SNAKE_CASE							:					Optional[int]    ,					*_SCREAMING_SNAKE_CASE							:					List[Any]						)	->  Optional[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       List[str] 							=    TFGPTJForCausalLM(config=a_						)
					SCREAMING_SNAKE_CASE	:       int 							=    {
					    'input_ids': input_ids,
					    'attention_mask': input_mask,
					    'token_type_ids': token_type_ids,
					}
					SCREAMING_SNAKE_CASE	:       Any 							=    model(a_						)
					self.parent.assertEqual(result.logits.shape    ,					(self.batch_size, self.seq_length, self.vocab_size)						)







	def  _lowerCAmelCase    (			self							:					Any						)	->  int:





					"""simple docstring"""


					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      
					)							,	(
					    SCREAMING_SNAKE_CASE      
					)							,	(
					    SCREAMING_SNAKE_CASE      
					)							,	      
					)	:       Dict 							=    config_and_inputs

					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    {
					    'input_ids': input_ids,
					    'token_type_ids': token_type_ids,
					    'attention_mask': input_mask,
					}
					return config, inputs_dict






@require_tf
class 						lowerCAmelCase__	(  _lowerCamelCase       ,       _lowerCamelCase       ,       _lowerCamelCase       ,       unittest.TestCase   ):


	'''simple docstring'''







	_SCREAMING_SNAKE_CASE  :		List[Any]     	=   (
	    (TFGPTJForCausalLM, TFGPTJForSequenceClassification, TFGPTJForQuestionAnswering, TFGPTJModel)
	    if is_tf_available()
	    else ()
	)

	_SCREAMING_SNAKE_CASE  :		int     	=   (TFGPTJForCausalLM,) if is_tf_available() else ()
	_SCREAMING_SNAKE_CASE  :		Optional[Any]     	=   (
	    {
	        '''feature-extraction''': TFGPTJModel,
	        '''question-answering''': TFGPTJForQuestionAnswering,
	        '''text-classification''': TFGPTJForSequenceClassification,
	        '''text-generation''': TFGPTJForCausalLM,
	        '''zero-shot''': TFGPTJForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	_SCREAMING_SNAKE_CASE  :		Dict     	=   False
	_SCREAMING_SNAKE_CASE  :		Optional[int]     	=   False
	_SCREAMING_SNAKE_CASE  :		List[Any]     	=   False
	_SCREAMING_SNAKE_CASE  :		List[str]     	=   False





	def  _lowerCAmelCase    (			self							:					Any    ,					_SCREAMING_SNAKE_CASE							:					Union[str, Any]    ,					_SCREAMING_SNAKE_CASE							:					int    ,					_SCREAMING_SNAKE_CASE							:					int    ,					_SCREAMING_SNAKE_CASE							:					List[str]    ,					_SCREAMING_SNAKE_CASE							:					Dict						)	->  List[str]:





					"""simple docstring"""


					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  _lowerCAmelCase    (			self							:					Optional[Any]						)	->  str:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       List[Any] 							=    TFGPTJModelTester(self						)
					SCREAMING_SNAKE_CASE	:       Tuple 							=    ConfigTester(self    ,					config_class=a_    ,					n_embd=37						)





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





					"""simple docstring"""


					self.config_tester.run_common_tests()





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





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_gptj_model(*a_						)





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





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       int 							=    self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_gptj_model_past(*a_						)





	def  _lowerCAmelCase    (			self							:					str						)	->  Optional[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       List[str] 							=    self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_gptj_model_attention_mask_past(*a_						)





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





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       str 							=    self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_gptj_model_past_large_inputs(*a_						)





	def  _lowerCAmelCase    (			self							:					Tuple						)	->  int:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Any 							=    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  _lowerCAmelCase    (			self							:					List[str]						)	->  Optional[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       List[str] 							=    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  _lowerCAmelCase    (			self							:					Any						)	->  str:





					"""simple docstring"""


					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  _lowerCAmelCase    (			self							:					str						)	->  Tuple:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Any 							=    TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B'    ,					from_pt=a_						)
					SCREAMING_SNAKE_CASE	:       Any 							=    tf.convert_to_tensor([[464, 3_290]]    ,					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
					SCREAMING_SNAKE_CASE	:       str 							=    [464, 3_290, 318, 257, 582, 338, 1_266, 1_545, 13, 632, 318, 257, 9_112, 15_185, 11, 290, 340, 318, 257, 1_545]
					# fmt: on
					SCREAMING_SNAKE_CASE	:       Tuple 							=    model.generate(a_    ,					do_sample=a_						)
					self.assertListEqual(output_ids[0].numpy().tolist()    ,					a_						)





	def  _lowerCAmelCase    (			self							:					Dict						)	->  Dict:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Any 							=    AutoTokenizer.from_pretrained('EleutherAI/gpt-j-6B'    ,					revision='float16'						)
					SCREAMING_SNAKE_CASE	:       Dict 							=    TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B'    ,					revision='float16'    ,					from_pt=a_						)

					SCREAMING_SNAKE_CASE	:       Union[str, 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'						):
									SCREAMING_SNAKE_CASE	:       Optional[int] 							=    model.generate(**a_    ,					do_sample=a_    ,					seed=[42, 0]						)
					SCREAMING_SNAKE_CASE	:       Any 							=    tokenizer.decode(output_ids[0]    ,					skip_special_tokens=a_						)

					SCREAMING_SNAKE_CASE	:       Dict 							=    'Today is a nice day and I’m going to go for a walk. I’'
					self.assertEqual(a_    ,					a_						)





	def  _lowerCAmelCase    (			self							:					Tuple						)	->  int:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Dict 							=    TFGPTJForCausalLM.from_pretrained('EleutherAI/gpt-j-6B'    ,					revision='float16'    ,					from_pt=a_						)
					SCREAMING_SNAKE_CASE	:       Any 							=    AutoTokenizer.from_pretrained('EleutherAI/gpt-j-6B'    ,					revision='float16'						)

					SCREAMING_SNAKE_CASE	:       List[Any] 							=    'left'

					# Define PAD Token = EOS Token = 50256
					SCREAMING_SNAKE_CASE	:       Dict 							=    tokenizer.eos_token
					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    model.config.eos_token_id

					# use different length sentences to test batching
					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    [
					    'Hello, my dog is a little',
					    'Today, I',
					]
					SCREAMING_SNAKE_CASE	:       Tuple 							=    [
					    '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  _lowerCAmelCase    (			self							:					Union[str, Any]						)	->  Optional[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE	:       Dict 							=    self._get_beam_search_test_objects()

					SCREAMING_SNAKE_CASE	:       List[str] 							=    tokenizer(a_    ,					return_tensors='tf'    ,					padding=a_						)
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    model.generate(**a_    ,					do_sample=a_    ,					num_beams=2						)
					SCREAMING_SNAKE_CASE	:       Any 							=    tokenizer.batch_decode(a_    ,					skip_special_tokens=a_						)
					self.assertListEqual(a_    ,					a_						)





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





					"""simple docstring"""


					SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE	:       Any 							=    self._get_beam_search_test_objects()

					SCREAMING_SNAKE_CASE	:       Dict 							=    tokenizer(a_    ,					return_tensors='tf'    ,					padding=a_						)
					SCREAMING_SNAKE_CASE	:       Tuple 							=    tokenizer(sentences[0]    ,					return_tensors='tf'						)
					SCREAMING_SNAKE_CASE	:       List[Any] 							=    model.generate(**a_    ,					do_sample=a_    ,					num_beams=2						)
					SCREAMING_SNAKE_CASE	:       Dict 							=    (
					    shape_list(inputs_non_padded['input_ids']						)[-1]
					    - tf.reduce_sum(tf.cast(inputs['attention_mask'][-1]    ,					tf.intaa						)						).numpy()
					)
					SCREAMING_SNAKE_CASE	:       str 							=    tokenizer(sentences[1]    ,					return_tensors='tf'						)
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    model.generate(
					    **a_    ,					do_sample=a_    ,					num_beams=2    ,					max_length=model.config.max_length - num_paddings						)
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    tokenizer.decode(output_non_padded[0]    ,					skip_special_tokens=a_						)
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    tokenizer.decode(output_padded[0]    ,					skip_special_tokens=a_						)
					self.assertListEqual(a_    ,					[non_padded_sentence, padded_sentence]						)







	def  _lowerCAmelCase    (			self							:					int						)	->  str:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE	:       str 							=    self._get_beam_search_test_objects()

					SCREAMING_SNAKE_CASE	:       List[Any] 							=    tokenizer(a_    ,					return_tensors='tf'    ,					padding=a_						)
					SCREAMING_SNAKE_CASE	:       int 							=    tf.function(model.generate    ,					jit_compile=a_						)
					SCREAMING_SNAKE_CASE	:       List[Any] 							=    xla_generate(**a_    ,					do_sample=a_    ,					num_beams=2						)
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    tokenizer.batch_decode(a_    ,					skip_special_tokens=a_						)
					self.assertListEqual(a_    ,					a_						)










"""simple docstring"""

import warnings

from ...utils import logging
from .image_processing_convnext import ConvNextImageProcessor


A_	:						Any				=			logging.get_logger(__name__)
class 						lowerCAmelCase__	(  _lowerCamelCase   ):


	'''simple docstring'''







	def __init__(			self							:					Tuple    ,					*_SCREAMING_SNAKE_CASE							:					Optional[int]    ,					**_SCREAMING_SNAKE_CASE							:					Optional[int]						)	->  None:





					"""simple docstring"""


					warnings.warn(
					    'The class ConvNextFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'
					    ' Please use ConvNextImageProcessor instead.'    ,					_SCREAMING_SNAKE_CASE    ,					)
					super().__init__(*_SCREAMING_SNAKE_CASE    ,					**_SCREAMING_SNAKE_CASE						)





