




UpperCAmelCase_    ={hex(i)[2:]: i for i in range(16)}  # Use [:2] to strip off the leading '0x'



def    UpperCAmelCase							(  _snake_case				):
							lowerCAmelCase =		hex_string.strip().lower()
							if not hex_string:
														raise ValueError('''Empty string was passed to the function'''				)
							lowerCAmelCase =		hex_string[0] == '''-'''
							if is_negative:
														lowerCAmelCase =		hex_string[1:]
							if not all(char in hex_table for char in hex_string				):
														raise ValueError('''Non-hexadecimal value was passed to the function'''				)
							lowerCAmelCase =		0
							for char in hex_string:
														lowerCAmelCase =		16 * decimal_number + hex_table[char]
							return -decimal_number if is_negative else decimal_number


if __name__ == "__main__":
		from doctest import testmod

		testmod()









import argparse

from transformers import CanineConfig, CanineModel, CanineTokenizer, load_tf_weights_in_canine
from transformers.utils import logging


logging.set_verbosity_info()



def    UpperCAmelCase							(  _snake_case    ,			_snake_case				):
							# Initialize PyTorch model
							lowerCAmelCase =		CanineConfig()
							lowerCAmelCase =		CanineModel(_snake_case				)
							model.eval()

							print(F"""Building PyTorch model from configuration: {config}"""				)

							# Load weights from tf checkpoint
							load_tf_weights_in_canine(_snake_case    ,			_snake_case    ,			_snake_case				)

							# Save pytorch-model (weights and configuration)
							print(F"""Save PyTorch model to {pytorch_dump_path}"""				)
							model.save_pretrained(_snake_case				)

							# Save tokenizer files
							lowerCAmelCase =		CanineTokenizer()
							print(F"""Save tokenizer files to {pytorch_dump_path}"""				)
							tokenizer.save_pretrained(_snake_case				)


if __name__ == "__main__":
		UpperCAmelCase_    =argparse.ArgumentParser()
		# Required parameters
		parser.add_argument(
		    """--tf_checkpoint_path""",
		    default=None,
		    type=str,
		    required=True,
		    help="""Path to the TensorFlow checkpoint. Should end with model.ckpt""",
		)
		parser.add_argument(
		    """--pytorch_dump_path""",
		    default=None,
		    type=str,
		    required=True,
		    help="""Path to a folder where the PyTorch model will be placed.""",
		)
		UpperCAmelCase_    =parser.parse_args()
		convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.pytorch_dump_path)



