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

				def __init__(  self							:     List[Any]							,     _lowercase							:     Tuple  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		parent
										UpperCAmelCase__       						=		1_3
										UpperCAmelCase__       						=		7
										UpperCAmelCase__       						=		True
										UpperCAmelCase__       						=		True
										UpperCAmelCase__       						=		True
										UpperCAmelCase__       						=		True
										UpperCAmelCase__       						=		True
										UpperCAmelCase__       						=		9_9
										UpperCAmelCase__       						=		3_2
										UpperCAmelCase__       						=		4
										UpperCAmelCase__       						=		2
										UpperCAmelCase__       						=		4
										UpperCAmelCase__       						=		3_7
										UpperCAmelCase__       						=		"""gelu"""
										UpperCAmelCase__       						=		0.1
										UpperCAmelCase__       						=		0.1
										UpperCAmelCase__       						=		5_1_2
										UpperCAmelCase__       						=		1_6
										UpperCAmelCase__       						=		2
										UpperCAmelCase__       						=		0.02
										UpperCAmelCase__       						=		3
										UpperCAmelCase__       						=		4
										UpperCAmelCase__       						=		None
										UpperCAmelCase__       						=		self.vocab_size - 1
										UpperCAmelCase__       						=		self.vocab_size - 1
										UpperCAmelCase__       						=		self.vocab_size - 1

				def 							A			(  self							:     List[Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		ids_tensor([self.batch_size, self.seq_length]							,     self.vocab_size  )

										UpperCAmelCase__       						=		None
										if self.use_input_mask:
																UpperCAmelCase__       						=		random_attention_mask([self.batch_size, self.seq_length]  )

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

										UpperCAmelCase__       						=		None
										if self.use_mc_token_ids:
																UpperCAmelCase__       						=		ids_tensor([self.batch_size, self.num_choices]							,     self.seq_length  )

										UpperCAmelCase__       						=		None
										UpperCAmelCase__       						=		None
										UpperCAmelCase__       						=		None
										if self.use_labels:
																UpperCAmelCase__       						=		ids_tensor([self.batch_size]							,     self.type_sequence_label_size  )
																UpperCAmelCase__       						=		ids_tensor([self.batch_size, self.seq_length]							,     self.num_labels  )
																UpperCAmelCase__       						=		ids_tensor([self.batch_size]							,     self.num_choices  )

										UpperCAmelCase__       						=		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=_lowercase							,     )

										UpperCAmelCase__       						=		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 							A			(  self							:     Dict							,     _lowercase							:     Dict							,     _lowercase							:     str							,     _lowercase							:     Optional[int]							,     _lowercase							:     Optional[Any]							,     _lowercase							:     str							,     *_lowercase							:     str  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		TFGPTJModel(config=_lowercase  )
										UpperCAmelCase__       						=		{
										    """input_ids""": input_ids,
										    """attention_mask""": input_mask,
										    """token_type_ids""": token_type_ids,
										}
										UpperCAmelCase__       						=		model(_lowercase  )

										UpperCAmelCase__       						=		[input_ids, None, input_mask]  # None is the input for 'past'
										UpperCAmelCase__       						=		model(_lowercase  )

										UpperCAmelCase__       						=		model(_lowercase  )

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

				def 							A			(  self							:     str							,     _lowercase							:     int							,     _lowercase							:     Dict							,     _lowercase							:     Tuple							,     _lowercase							:     Tuple							,     _lowercase							:     List[str]							,     *_lowercase							:     List[Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		TFGPTJModel(config=_lowercase  )

										# first forward pass
										UpperCAmelCase__       						=		model(_lowercase							,     token_type_ids=_lowercase							,     use_cache=_lowercase  )
										UpperCAmelCase__       						=		model(_lowercase							,     token_type_ids=_lowercase  )
										UpperCAmelCase__       						=		model(_lowercase							,     token_type_ids=_lowercase							,     use_cache=_lowercase  )

										self.parent.assertTrue(len(_lowercase  ) == len(_lowercase  )  )
										self.parent.assertTrue(len(_lowercase  ) == len(_lowercase  ) + 1  )

										UpperCAmelCase__						,   UpperCAmelCase__       						=		outputs.to_tuple()

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

										# append to next input_ids and token_type_ids
										UpperCAmelCase__       						=		tf.concat([input_ids, next_tokens]							,     axis=-1  )
										UpperCAmelCase__       						=		tf.concat([token_type_ids, next_token_types]							,     axis=-1  )

										UpperCAmelCase__       						=		model(_lowercase							,     token_type_ids=_lowercase  )["""last_hidden_state"""]
										UpperCAmelCase__       						=		model(_lowercase							,     token_type_ids=_lowercase							,     past_key_values=_lowercase  )[
										    """last_hidden_state"""
										]

										# select random slice
										UpperCAmelCase__       						=		int(ids_tensor((1,)							,     shape_list(_lowercase  )[-1]  )  )
										UpperCAmelCase__       						=		output_from_no_past[:, -1, random_slice_idx]
										UpperCAmelCase__       						=		output_from_past[:, 0, random_slice_idx]

										# test that outputs are equal for slice
										tf.debugging.assert_near(_lowercase							,     _lowercase							,     rtol=1e-6  )

				def 							A			(  self							:     int							,     _lowercase							:     Optional[int]							,     _lowercase							:     int							,     _lowercase							:     Union[str, Any]							,     _lowercase							:     str							,     _lowercase							:     List[str]							,     *_lowercase							:     Optional[int]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		TFGPTJModel(config=_lowercase  )

										# create attention mask
										UpperCAmelCase__       						=		self.seq_length // 2
										UpperCAmelCase__       						=		tf.ones((self.batch_size, half_seq_length)							,     dtype=tf.intaa  )
										UpperCAmelCase__       						=		tf.zeros((self.batch_size, self.seq_length - half_seq_length)							,     dtype=tf.intaa  )
										UpperCAmelCase__       						=		tf.concat([attn_mask_begin, attn_mask_end]							,     axis=1  )

										# first forward pass
										UpperCAmelCase__						,   UpperCAmelCase__       						=		model(_lowercase							,     attention_mask=_lowercase  ).to_tuple()

										# create hypothetical next token and extent to next_input_ids
										UpperCAmelCase__       						=		ids_tensor((self.batch_size, 1)							,     config.vocab_size  )

										# change a random masked slice from input_ids
										UpperCAmelCase__       						=		ids_tensor((1,)							,     _lowercase  ).numpy() + 1
										UpperCAmelCase__       						=		ids_tensor((self.batch_size, self.seq_length)							,     config.vocab_size  )
										UpperCAmelCase__       						=		tf.range(self.seq_length  ) == (self.seq_length - random_seq_idx_to_change)
										UpperCAmelCase__       						=		tf.transpose(
										    tf.broadcast_to(tf.expand_dims(_lowercase							,     -1  )							,     (self.seq_length, self.batch_size)  )  )
										UpperCAmelCase__       						=		tf.where(_lowercase							,     _lowercase							,     _lowercase  )

										# append to next input_ids and attn_mask
										UpperCAmelCase__       						=		tf.concat([input_ids, next_tokens]							,     axis=-1  )
										UpperCAmelCase__       						=		tf.concat([attn_mask, tf.ones((shape_list(_lowercase  )[0], 1)							,     dtype=tf.intaa  )]							,     axis=1  )

										# get two different outputs
										UpperCAmelCase__       						=		model(_lowercase							,     attention_mask=_lowercase  )["""last_hidden_state"""]
										UpperCAmelCase__       						=		model(_lowercase							,     past_key_values=_lowercase							,     attention_mask=_lowercase  )[
										    """last_hidden_state"""
										]

										# select random slice
										UpperCAmelCase__       						=		int(ids_tensor((1,)							,     shape_list(_lowercase  )[-1]  )  )
										UpperCAmelCase__       						=		output_from_no_past[:, -1, random_slice_idx]
										UpperCAmelCase__       						=		output_from_past[:, 0, random_slice_idx]

										# test that outputs are equal for slice
										tf.debugging.assert_near(_lowercase							,     _lowercase							,     rtol=1e-12  )

				def 							A			(  self							:     List[str]							,     _lowercase							:     str							,     _lowercase							:     Optional[Any]							,     _lowercase							:     Union[str, Any]							,     _lowercase							:     List[str]							,     _lowercase							:     Optional[int]							,     *_lowercase							:     Union[str, Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		TFGPTJModel(config=_lowercase  )

										UpperCAmelCase__       						=		input_ids[:1, :]
										UpperCAmelCase__       						=		input_mask[:1, :]
										UpperCAmelCase__       						=		token_type_ids[:1, :]
										UpperCAmelCase__       						=		1

										# first forward pass
										UpperCAmelCase__       						=		model(_lowercase							,     attention_mask=_lowercase							,     token_type_ids=_lowercase							,     use_cache=_lowercase  )

										UpperCAmelCase__						,   UpperCAmelCase__       						=		outputs.to_tuple()

										# create hypothetical next token and extent to next_input_ids
										UpperCAmelCase__       						=		ids_tensor((self.batch_size, 3)							,     config.vocab_size  )
										UpperCAmelCase__       						=		ids_tensor((self.batch_size, 3)							,     2  )
										UpperCAmelCase__       						=		ids_tensor((self.batch_size, 3)							,     self.type_vocab_size  )

										# append to next input_ids and token_type_ids
										UpperCAmelCase__       						=		tf.concat([input_ids, next_tokens]							,     axis=-1  )
										UpperCAmelCase__       						=		tf.concat([input_mask, next_attn_mask]							,     axis=-1  )
										UpperCAmelCase__       						=		tf.concat([token_type_ids, next_token_types]							,     axis=-1  )

										UpperCAmelCase__       						=		model(
										    _lowercase							,     token_type_ids=_lowercase							,     attention_mask=_lowercase  )["""last_hidden_state"""]
										UpperCAmelCase__       						=		model(
										    _lowercase							,     token_type_ids=_lowercase							,     attention_mask=_lowercase							,     past_key_values=_lowercase							,     )["""last_hidden_state"""]
										self.parent.assertTrue(output_from_past.shape[1] == next_tokens.shape[1]  )

										# select random slice
										UpperCAmelCase__       						=		int(ids_tensor((1,)							,     shape_list(_lowercase  )[-1]  )  )
										UpperCAmelCase__       						=		output_from_no_past[:, -3:, random_slice_idx]
										UpperCAmelCase__       						=		output_from_past[:, :, random_slice_idx]

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

				def 							A			(  self							:     Union[str, Any]							,     _lowercase							:     int							,     _lowercase							:     Optional[int]							,     _lowercase							:     List[Any]							,     _lowercase							:     Dict							,     _lowercase							:     Any							,     *_lowercase							:     Dict  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		TFGPTJForCausalLM(config=_lowercase  )
										UpperCAmelCase__       						=		{
										    """input_ids""": input_ids,
										    """attention_mask""": input_mask,
										    """token_type_ids""": token_type_ids,
										}
										UpperCAmelCase__       						=		model(_lowercase  )
										self.parent.assertEqual(result.logits.shape							,     (self.batch_size, self.seq_length, self.vocab_size)  )

				def 							A			(  self							:     Optional[Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		self.prepare_config_and_inputs()

										(
										    (
										    UpperCAmelCase__
										)						,   (
										    UpperCAmelCase__
										)						,   (
										    UpperCAmelCase__
										)						,   (
										    UpperCAmelCase__
										)						,   (
										    UpperCAmelCase__
										)						,   (
										    UpperCAmelCase__
										)						,   (
										    UpperCAmelCase__
										)						,   (
										    UpperCAmelCase__
										)						,   (
										    UpperCAmelCase__
										)						,   
										)       						=		config_and_inputs

										UpperCAmelCase__       						=		{
										    """input_ids""": input_ids,
										    """token_type_ids""": token_type_ids,
										    """attention_mask""": input_mask,
										}
										return config, inputs_dict


@require_tf
class       _lowercase		( __lowerCamelCase   ,   __lowerCamelCase   ,   __lowerCamelCase   ,   unittest.TestCase	):
				lowerCamelCase__							=							(
				    (TFGPTJForCausalLM, TFGPTJForSequenceClassification, TFGPTJForQuestionAnswering, TFGPTJModel)
				    if is_tf_available()
				    else ()
				)

				lowerCamelCase__							=							(TFGPTJForCausalLM,) if is_tf_available() else ()
				lowerCamelCase__							=							(
				    {
				        'feature-extraction': TFGPTJModel,
				        'question-answering': TFGPTJForQuestionAnswering,
				        'text-classification': TFGPTJForSequenceClassification,
				        'text-generation': TFGPTJForCausalLM,
				        'zero-shot': TFGPTJForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				lowerCamelCase__							=							False
				lowerCamelCase__							=							False
				lowerCamelCase__							=							False
				lowerCamelCase__							=							False

				def 							A			(  self							:     Union[str, Any]							,     _lowercase							:     Union[str, Any]							,     _lowercase							:     str							,     _lowercase							:     Optional[Any]							,     _lowercase							:     str							,     _lowercase							:     Union[str, Any]  ):


										'''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 							A			(  self							:     Optional[int]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		TFGPTJModelTester(self  )
										UpperCAmelCase__       						=		ConfigTester(self							,     config_class=_lowercase							,     n_embd=3_7  )

				def 							A			(  self							:     List[Any]  ):


										'''simple docstring'''
										self.config_tester.run_common_tests()

				def 							A			(  self							:     str  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_gptj_model(*_lowercase  )

				def 							A			(  self							:     Optional[int]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_gptj_model_past(*_lowercase  )

				def 							A			(  self							:     List[Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_gptj_model_attention_mask_past(*_lowercase  )

				def 							A			(  self							:     int  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_gptj_model_past_large_inputs(*_lowercase  )

				def 							A			(  self							:     int  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_gptj_lm_head_model(*_lowercase  )

				@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 							A			(  self							:     int  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		TFGPTJModel.from_pretrained("""EleutherAI/gpt-j-6B"""							,     from_pt=_lowercase  )
										self.assertIsNotNone(_lowercase  )

				@unittest.skip(reason="""Currently, model embeddings are going to undergo a major refactor."""  )
				def 							A			(  self							:     Optional[Any]  ):


										'''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       _lowercase		( unittest.TestCase	):

				def 							A			(  self							:     List[Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		TFGPTJForCausalLM.from_pretrained("""EleutherAI/gpt-j-6B"""							,     from_pt=_lowercase  )
										UpperCAmelCase__       						=		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__       						=		[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__       						=		model.generate(_lowercase							,     do_sample=_lowercase  )
										self.assertListEqual(output_ids[0].numpy().tolist()							,     _lowercase  )

				def 							A			(  self							:     List[Any]  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		AutoTokenizer.from_pretrained("""EleutherAI/gpt-j-6B"""							,     revision="""float16"""  )
										UpperCAmelCase__       						=		TFGPTJForCausalLM.from_pretrained("""EleutherAI/gpt-j-6B"""							,     revision="""float16"""							,     from_pt=_lowercase  )

										UpperCAmelCase__       						=		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__       						=		model.generate(**_lowercase							,     do_sample=_lowercase							,     seed=[4_2, 0]  )
										UpperCAmelCase__       						=		tokenizer.decode(output_ids[0]							,     skip_special_tokens=_lowercase  )

										UpperCAmelCase__       						=		"""Today is a nice day and I’m going to go for a walk. I’"""
										self.assertEqual(_lowercase							,     _lowercase  )

				def 							A			(  self							:     Any  ):


										'''simple docstring'''
										UpperCAmelCase__       						=		TFGPTJForCausalLM.from_pretrained("""EleutherAI/gpt-j-6B"""							,     revision="""float16"""							,     from_pt=_lowercase  )
										UpperCAmelCase__       						=		AutoTokenizer.from_pretrained("""EleutherAI/gpt-j-6B"""							,     revision="""float16"""  )

										UpperCAmelCase__       						=		"""left"""

										# Define PAD Token = EOS Token = 50256
										UpperCAmelCase__       						=		tokenizer.eos_token
										UpperCAmelCase__       						=		model.config.eos_token_id

										# use different length sentences to test batching
										UpperCAmelCase__       						=		[
										    """Hello, my dog is a little""",
										    """Today, I""",
										]
										UpperCAmelCase__       						=		[
										    """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 							A			(  self							:     List[str]  ):


										'''simple docstring'''
										# Confirms that we get the expected results with left-padded beam search
										UpperCAmelCase__						,   UpperCAmelCase__						,   UpperCAmelCase__						,   UpperCAmelCase__       						=		self._get_beam_search_test_objects()

										UpperCAmelCase__       						=		tokenizer(_lowercase							,     return_tensors="""tf"""							,     padding=_lowercase  )
										UpperCAmelCase__       						=		model.generate(**_lowercase							,     do_sample=_lowercase							,     num_beams=2  )
										UpperCAmelCase__       						=		tokenizer.batch_decode(_lowercase							,     skip_special_tokens=_lowercase  )
										self.assertListEqual(_lowercase							,     _lowercase  )

				def 							A			(  self							:     Optional[Any]  ):


										'''simple docstring'''
										# Confirms that left-padding is working properly
										UpperCAmelCase__						,   UpperCAmelCase__						,   UpperCAmelCase__						,   UpperCAmelCase__       						=		self._get_beam_search_test_objects()

										UpperCAmelCase__       						=		tokenizer(_lowercase							,     return_tensors="""tf"""							,     padding=_lowercase  )
										UpperCAmelCase__       						=		tokenizer(sentences[0]							,     return_tensors="""tf"""  )
										UpperCAmelCase__       						=		model.generate(**_lowercase							,     do_sample=_lowercase							,     num_beams=2  )
										UpperCAmelCase__       						=		(
										    shape_list(inputs_non_padded["""input_ids"""]  )[-1]
										    - tf.reduce_sum(tf.cast(inputs["""attention_mask"""][-1]							,     tf.intaa  )  ).numpy()
										)
										UpperCAmelCase__       						=		tokenizer(sentences[1]							,     return_tensors="""tf"""  )
										UpperCAmelCase__       						=		model.generate(
										    **_lowercase							,     do_sample=_lowercase							,     num_beams=2							,     max_length=model.config.max_length - num_paddings  )
										UpperCAmelCase__       						=		tokenizer.decode(output_non_padded[0]							,     skip_special_tokens=_lowercase  )
										UpperCAmelCase__       						=		tokenizer.decode(output_padded[0]							,     skip_special_tokens=_lowercase  )
										self.assertListEqual(_lowercase							,     [non_padded_sentence, padded_sentence]  )

				def 							A			(  self							:     str  ):


										'''simple docstring'''
										# Confirms that XLA is working properly
										UpperCAmelCase__						,   UpperCAmelCase__						,   UpperCAmelCase__						,   UpperCAmelCase__       						=		self._get_beam_search_test_objects()

										UpperCAmelCase__       						=		tokenizer(_lowercase							,     return_tensors="""tf"""							,     padding=_lowercase  )
										UpperCAmelCase__       						=		tf.function(model.generate							,     jit_compile=_lowercase  )
										UpperCAmelCase__       						=		xla_generate(**_lowercase							,     do_sample=_lowercase							,     num_beams=2  )
										UpperCAmelCase__       						=		tokenizer.batch_decode(_lowercase							,     skip_special_tokens=_lowercase  )
										self.assertListEqual(_lowercase							,     _lowercase  )


"""simple docstring"""







from __future__ import annotations


def 	a__   (		UpperCAmelCase__							:      list      )->						int | float:
						UpperCAmelCase__       						=		sorted(UpperCAmelCase__      )
						UpperCAmelCase__       						=		len(UpperCAmelCase__      )
						UpperCAmelCase__       						=		length >> 1
						return (
						    (sorted_list[mid_index] + sorted_list[mid_index - 1]) / 2
						    if length % 2 == 0
						    else sorted_list[mid_index]
						)


def 	a__   (		)->						Dict:
						import doctest

						doctest.testmod()


if __name__ == "__main__":
						main()

