
'''simple docstring'''







import sys

_lowercase			:  Union[str, Any]       							=	(
    "73167176531330624919225119674426574742355349194934"
    "96983520312774506326239578318016984801869478851843"
    "85861560789112949495459501737958331952853208805511"
    "12540698747158523863050715693290963295227443043557"
    "66896648950445244523161731856403098711121722383113"
    "62229893423380308135336276614282806444486645238749"
    "30358907296290491560440772390713810515859307960866"
    "70172427121883998797908792274921901699720888093776"
    "65727333001053367881220235421809751254540594752243"
    "52584907711670556013604839586446706324415722155397"
    "53697817977846174064955149290862569321978468622482"
    "83972241375657056057490261407972968652414535100474"
    "82166370484403199890008895243450658541227588666881"
    "16427171479924442928230863465674813919123162824586"
    "17866458359124566529476545682848912883142607690042"
    "24219022671055626321111109370544217506941658960408"
    "07198403850962455444362981230987879927244284909188"
    "84580156166097919133875499200524063689912560717606"
    "05886116467109405077541002256983155200055935729725"
    "71636269561882670428252483600823257530420752963450"
)
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			str							):



						"""simple docstring"""





						lowercase_     :					Any													=	1
						for digit in s:
												product *= int(__SCREAMING_SNAKE_CASE							)
						return product
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			str = N							):



						"""simple docstring"""





						lowercase_     :					Any													=	-sys.maxsize - 1
						lowercase_     :					List[Any]													=	n[:13]
						lowercase_     :					List[str]													=	13
						while cur_index < len(__SCREAMING_SNAKE_CASE							) - 13:
												if int(n[cur_index]							) >= int(substr[0]							):
																		lowercase_     :					Tuple													=	substr[1:] + n[cur_index]
																		cur_index += 1
												else:
																		lowercase_     :					str													=	max(__SCREAMING_SNAKE_CASE				,				str_eval(__SCREAMING_SNAKE_CASE							)							)
																		lowercase_     :					List[Any]													=	n[cur_index : cur_index + 13]
																		cur_index += 13
						return largest_product


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





'''simple docstring'''







import argparse
import os
import re

import torch
from flax.traverse_util import flatten_dict
from tax import checkpoints

from transformers import (
    AutoTokenizer,
    PixaStructConfig,
    PixaStructForConditionalGeneration,
    PixaStructImageProcessor,
    PixaStructProcessor,
    PixaStructTextConfig,
    PixaStructVisionConfig,
)
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			List[Any]							):



						"""simple docstring"""





						lowercase_     :					Optional[int]													=	checkpoints.load_tax_checkpoint(__SCREAMING_SNAKE_CASE							)
						lowercase_     :					Dict													=	flatten_dict(__SCREAMING_SNAKE_CASE							)
						return flax_params
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			List[Any]							):



						"""simple docstring"""





						lowercase_     :					int													=	{}

						lowercase_     :					Any													=	{
						    '''token_embedder''': '''embeddings''',
						    '''encoder_norm''': '''layernorm''',
						    '''kernel''': '''weight''',
						    '''.out''': '''.output''',
						    '''scale''': '''weight''',
						    '''embedders_0.pos_embedding''': '''row_embedder.weight''',
						    '''embedders_1.pos_embedding''': '''column_embedder.weight''',
						}

						lowercase_     :					Tuple													=	{
						    '''query''': '''attention.query''',
						    '''key''': '''attention.key''',
						    '''value''': '''attention.value''',
						    '''output.dense''': '''output''',
						    '''encoder_decoder_attention.o''': '''encoder_decoder_attention.attention.o''',
						    '''pre_self_attention_layer_norm''': '''self_attention.layer_norm''',
						    '''pre_cross_attention_layer_norm''': '''encoder_decoder_attention.layer_norm''',
						    '''mlp.''': '''mlp.DenseReluDense.''',
						    '''pre_mlp_layer_norm''': '''mlp.layer_norm''',
						    '''self_attention.o''': '''self_attention.attention.o''',
						    '''decoder.embeddings.embedding''': '''decoder.embed_tokens.weight''',
						    '''decoder.relpos_bias.rel_embedding''': '''decoder.layer.0.self_attention.attention.relative_attention_bias.weight''',
						    '''decoder.decoder_norm.weight''': '''decoder.final_layer_norm.weight''',
						    '''decoder.logits_dense.weight''': '''decoder.lm_head.weight''',
						}

						for key in flax_dict.keys():
												if "target" in key:
																		# remove the first prefix from the key
																		lowercase_     :					Tuple													=	'''.'''.join(key[1:]							)

																		# rename the key
																		for old, new in CONVERSION_MAPPING.items():
																								lowercase_     :					Optional[Any]													=	new_key.replace(__SCREAMING_SNAKE_CASE				,				__SCREAMING_SNAKE_CASE							)

																		if "decoder" in new_key:
																								for old, new in DECODER_CONVERSION_MAPPING.items():
																														lowercase_     :					Optional[Any]													=	new_key.replace(__SCREAMING_SNAKE_CASE				,				__SCREAMING_SNAKE_CASE							)

																		if "layers" in new_key and "decoder" not in new_key:
																								# use regex to replace the layer number
																								lowercase_     :					List[Any]													=	re.sub(R'''layers_(\d+)'''				,				R'''layer.\1'''				,				__SCREAMING_SNAKE_CASE							)
																								lowercase_     :					Union[str, Any]													=	new_key.replace('''encoder'''				,				'''encoder.encoder'''							)

																		elif "layers" in new_key and "decoder" in new_key:
																								# use regex to replace the layer number
																								lowercase_     :					str													=	re.sub(R'''layers_(\d+)'''				,				R'''layer.\1'''				,				__SCREAMING_SNAKE_CASE							)

																		lowercase_     :					Dict													=	flax_dict[key]

						lowercase_     :					Any													=	{}
						# convert converted_dict into torch format
						for key in converted_dict.keys():
												if ("embed_tokens" not in key) and ("embedder" not in key):
																		lowercase_     :					str													=	torch.from_numpy(converted_dict[key].T							)
												else:
																		lowercase_     :					str													=	torch.from_numpy(converted_dict[key]							)

						return converted_torch_dict
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			List[Any]				,				__SCREAMING_SNAKE_CASE :			List[Any]				,				__SCREAMING_SNAKE_CASE :			Tuple=False				,				__SCREAMING_SNAKE_CASE :			List[Any]=False							):



						"""simple docstring"""





						lowercase_     :					List[str]													=	get_flax_param(__SCREAMING_SNAKE_CASE							)

						if not use_large:
												lowercase_     :					List[str]													=	PixaStructVisionConfig()
												lowercase_     :					Optional[Any]													=	PixaStructTextConfig()
						else:
												lowercase_     :					Optional[int]													=	PixaStructVisionConfig(
												    hidden_size=1536				,				d_ff=3968				,				num_attention_heads=24				,				num_hidden_layers=18							)
												lowercase_     :					Dict													=	PixaStructTextConfig(hidden_size=1536				,				d_ff=3968				,				num_heads=24				,				num_layers=18							)
						lowercase_     :					str													=	PixaStructConfig(
						    vision_config=encoder_config.to_dict()				,				text_config=decoder_config.to_dict()				,				is_vqa=__SCREAMING_SNAKE_CASE							)

						lowercase_     :					List[str]													=	PixaStructForConditionalGeneration(__SCREAMING_SNAKE_CASE							)

						lowercase_     :					int													=	rename_and_convert_flax_params(__SCREAMING_SNAKE_CASE							)
						model.load_state_dict(__SCREAMING_SNAKE_CASE							)

						lowercase_     :					str													=	AutoTokenizer.from_pretrained('''ybelkada/test-pix2struct-tokenizer'''							)
						lowercase_     :					List[Any]													=	PixaStructImageProcessor()
						lowercase_     :					int													=	PixaStructProcessor(image_processor=__SCREAMING_SNAKE_CASE				,				tokenizer=__SCREAMING_SNAKE_CASE							)

						if use_large:
												lowercase_     :					Tuple													=	4096

						lowercase_     :					Optional[int]													=	True

						# mkdir if needed
						os.makedirs(__SCREAMING_SNAKE_CASE				,				exist_ok=__SCREAMING_SNAKE_CASE							)

						model.save_pretrained(__SCREAMING_SNAKE_CASE							)
						processor.save_pretrained(__SCREAMING_SNAKE_CASE							)

						print('''Model saved in {}'''.format(__SCREAMING_SNAKE_CASE							)							)


if __name__ == "__main__":
							_lowercase			:  str   							=	argparse.ArgumentParser()
							parser.add_argument("--t5x_checkpoint_path", default=None, type=str, help="Path to the original T5x checkpoint.")
							parser.add_argument("--pytorch_dump_folder_path", default=None, type=str, help="Path to the output PyTorch model.")
							parser.add_argument("--use_large", action="store_true", help="Use large model.")
							parser.add_argument("--is_vqa", action="store_true", help="Use large model.")
							_lowercase			:  Tuple   							=	parser.parse_args()

							convert_pixastruct_original_pytorch_checkpoint_to_hf(
							    args.tax_checkpoint_path, args.pytorch_dump_folder_path, args.use_large
							)



