




import unittest
from pathlib import Path
from tempfile import TemporaryDirectory

from transformers import AutoConfig, TFGPTaLMHeadModel, is_keras_nlp_available, is_tf_available
from transformers.models.gpta.tokenization_gpta import GPTaTokenizer
from transformers.testing_utils import require_keras_nlp, require_tf, slow


if is_tf_available():
	import tensorflow as tf

if is_keras_nlp_available():
	from transformers.models.gpta import TFGPTaTokenizer


_lowerCamelCase      :  Tuple      						=						["gpt2"]
_lowerCamelCase      :  List[Any]      						=						"gpt2"

if is_tf_available():
	class        __snake_case  (tf.Module		):



					def __init__(      self      :		Optional[Any]		,	_UpperCAmelCase      :		Any      )  ->    Any:





									'''simple docstring'''




									super().__init__()
									_lowerCAmelCase    :    Any										=      tokenizer
									_lowerCAmelCase    :    Dict										=      AutoConfig.from_pretrained(_UpperCAmelCase      )
									_lowerCAmelCase    :    List[str]										=      TFGPTaLMHeadModel.from_config(_UpperCAmelCase      )



					@tf.function(input_signature=(tf.TensorSpec((None,)		,	tf.string		,	name="""text"""      ),)      )
					def       SCREAMING_SNAKE_CASE       (      self      :		Any		,	_UpperCAmelCase      :		List[Any]      )  ->    Tuple:





									'''simple docstring'''




									_lowerCAmelCase    :    List[str]										=      self.tokenizer(_UpperCAmelCase      )
									_lowerCAmelCase    :    List[str]										=      tokenized["""input_ids"""].to_tensor()

									_lowerCAmelCase    :    Dict										=      tf.cast(input_ids_dense > 0		,	tf.intaa      )
									# input_mask = tf.reshape(input_mask, [-1, MAX_SEQ_LEN])

									_lowerCAmelCase    :    Tuple										=      self.model(input_ids=_UpperCAmelCase		,	attention_mask=_UpperCAmelCase      )["""logits"""]

									return outputs
@require_tf
@require_keras_nlp
class        __snake_case  (unittest.TestCase		):



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





								'''simple docstring'''




								super().setUp()

								_lowerCAmelCase    :    Optional[Any]										=      [GPTaTokenizer.from_pretrained(_UpperCAmelCase      ) for checkpoint in (TOKENIZER_CHECKPOINTS)]
								_lowerCAmelCase    :    Union[str, Any]										=      [TFGPTaTokenizer.from_pretrained(_UpperCAmelCase      ) for checkpoint in TOKENIZER_CHECKPOINTS]
								assert len(self.tokenizers      ) == len(self.tf_tokenizers      )

								_lowerCAmelCase    :    Tuple										=      [
								    """This is a straightforward English test sentence.""",
								    """This one has some weird characters\rto\nsee\r\nif  those\u00E9break things.""",
								    """Now we're going to add some Chinese: 一 二 三 一二三""",
								    """And some much more rare Chinese: 齉 堃 齉堃""",
								    """Je vais aussi écrire en français pour tester les accents""",
								    """Classical Irish also has some unusual characters, so in they go: Gaelaċ, ꝼ""",
								]
								_lowerCAmelCase    :    int										=      list(zip(self.test_sentences		,	self.test_sentences[::-1]      )      )



				def       SCREAMING_SNAKE_CASE       (      self      :		int      )  ->    Dict:





								'''simple docstring'''




								for tokenizer, tf_tokenizer in zip(self.tokenizers		,	self.tf_tokenizers      ):
												for test_inputs in self.test_sentences:
																_lowerCAmelCase    :    int										=      tokenizer([test_inputs]		,	return_tensors="""tf"""      )
																_lowerCAmelCase    :    Optional[Any]										=      tf_tokenizer([test_inputs]      )

																for key in python_outputs.keys():
																				# convert them to numpy to avoid messing with ragged tensors
																				_lowerCAmelCase    :    Any										=      python_outputs[key].numpy()
																				_lowerCAmelCase    :    str										=      tf_outputs[key].numpy()

																				self.assertTrue(tf.reduce_all(python_outputs_values.shape == tf_outputs_values.shape      )      )
																				self.assertTrue(tf.reduce_all(tf.cast(_UpperCAmelCase		,	tf.intaa      ) == tf_outputs_values      )      )



				@slow
				def       SCREAMING_SNAKE_CASE       (      self      :		List[str]      )  ->    str:





								'''simple docstring'''




								for tf_tokenizer in self.tf_tokenizers:
												_lowerCAmelCase    :    Any										=      tf.function(_UpperCAmelCase      )
												for test_inputs in self.test_sentences:
																_lowerCAmelCase    :    Any										=      tf.constant(_UpperCAmelCase      )
																_lowerCAmelCase    :    Optional[Any]										=      compiled_tokenizer(_UpperCAmelCase      )
																_lowerCAmelCase    :    Tuple										=      tf_tokenizer(_UpperCAmelCase      )

																for key in eager_outputs.keys():
																				self.assertTrue(tf.reduce_all(eager_outputs[key] == compiled_outputs[key]      )      )



				@slow
				def       SCREAMING_SNAKE_CASE       (      self      :		List[Any]      )  ->    Union[str, Any]:





								'''simple docstring'''




								for tf_tokenizer in self.tf_tokenizers:
												_lowerCAmelCase    :    Dict										=      ModelToSave(tokenizer=_UpperCAmelCase      )
												_lowerCAmelCase    :    Union[str, Any]										=      tf.convert_to_tensor([self.test_sentences[0]]      )
												_lowerCAmelCase    :    List[Any]										=      model.serving(_UpperCAmelCase      )  # Build model with some sample inputs
												with TemporaryDirectory() as tempdir:
																_lowerCAmelCase    :    List[Any]										=      Path(_UpperCAmelCase      ) / """saved.model"""
																tf.saved_model.save(_UpperCAmelCase		,	_UpperCAmelCase		,	signatures={"""serving_default""": model.serving}      )
																_lowerCAmelCase    :    str										=      tf.saved_model.load(_UpperCAmelCase      )
												_lowerCAmelCase    :    List[Any]										=      loaded_model.signatures["""serving_default"""](_UpperCAmelCase      )["""output_0"""]
												# We may see small differences because the loaded model is compiled, so we need an epsilon for the test
												self.assertTrue(tf.reduce_all(out == loaded_output      )      )



				@slow
				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]      )  ->    Optional[Any]:





								'''simple docstring'''




								for tf_tokenizer in self.tf_tokenizers:
												_lowerCAmelCase    :    Any										=      tf.convert_to_tensor([self.test_sentences[0]]      )
												_lowerCAmelCase    :    Union[str, Any]										=      tf_tokenizer(_UpperCAmelCase      )  # Build model with some sample inputs

												_lowerCAmelCase    :    Union[str, Any]										=      tf_tokenizer.get_config()
												_lowerCAmelCase    :    Optional[int]										=      TFGPTaTokenizer.from_config(_UpperCAmelCase      )
												_lowerCAmelCase    :    Dict										=      model_from_config(_UpperCAmelCase      )

												for key in from_config_output.keys():
																self.assertTrue(tf.reduce_all(from_config_output[key] == out[key]      )      )



				@slow
				def       SCREAMING_SNAKE_CASE       (      self      :		Tuple      )  ->    Union[str, Any]:





								'''simple docstring'''




								for tf_tokenizer in self.tf_tokenizers:
												# for the test to run
												_lowerCAmelCase    :    List[str]										=      12_3123

												for max_length in [3, 5, 1024]:
																_lowerCAmelCase    :    Union[str, Any]										=      tf.convert_to_tensor([self.test_sentences[0]]      )
																_lowerCAmelCase    :    int										=      tf_tokenizer(_UpperCAmelCase		,	max_length=_UpperCAmelCase      )

																_lowerCAmelCase    :    Union[str, Any]										=      out["""input_ids"""].numpy().shape[1]

																assert out_length == max_length







import sys

_lowerCamelCase      :  Optional[Any]      						=						(
    "73167176531330624919225119674426574742355349194934"
    "96983520312774506326239578318016984801869478851843"
    "85861560789112949495459501737958331952853208805511"
    "12540698747158523863050715693290963295227443043557"
    "66896648950445244523161731856403098711121722383113"
    "62229893423380308135336276614282806444486645238749"
    "30358907296290491560440772390713810515859307960866"
    "70172427121883998797908792274921901699720888093776"
    "65727333001053367881220235421809751254540594752243"
    "52584907711670556013604839586446706324415722155397"
    "53697817977846174064955149290862569321978468622482"
    "83972241375657056057490261407972968652414535100474"
    "82166370484403199890008895243450658541227588666881"
    "16427171479924442928230863465674813919123162824586"
    "17866458359124566529476545682848912883142607690042"
    "24219022671055626321111109370544217506941658960408"
    "07198403850962455444362981230987879927244284909188"
    "84580156166097919133875499200524063689912560717606"
    "05886116467109405077541002256983155200055935729725"
    "71636269561882670428252483600823257530420752963450"
)




def 							_UpperCAmelCase  (UpperCamelCase_ : str = N       ):
				'''simple docstring'''
				_lowerCAmelCase    :    List[str]										=      -sys.maxsize - 1
				for i in range(len(UpperCamelCase_       ) - 12       ):
								_lowerCAmelCase    :    List[str]										=      1
								for j in range(13       ):
												product *= int(n[i + j]       )
								if product > largest_product:
												_lowerCAmelCase    :    Any										=      product
				return largest_product


if __name__ == "__main__":
	print(F'''{solution() = }''')

