



'''simple docstring'''
import argparse

from transformers import (
    TapasConfig,
    TapasForMaskedLM,
    TapasForQuestionAnswering,
    TapasForSequenceClassification,
    TapasModel,
    TapasTokenizer,
    load_tf_weights_in_tapas,
)
from transformers.utils import logging


logging.set_verbosity_info()






def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_    ,    UpperCAmelCase_    ,    UpperCAmelCase_    ,    UpperCAmelCase_				):
						# Initialise PyTorch model.
						# If you want to convert a checkpoint that uses absolute position embeddings, make sure to set reset_position_index_per_cell of
						# TapasConfig to False.

						# initialize configuration from json file
						_UpperCamelCase   :						Optional[Any]												=  TapasConfig.from_json_file(UpperCAmelCase_				)
						# set absolute/relative position embeddings parameter
						_UpperCamelCase   :						Optional[int]												=  reset_position_index_per_cell

						# set remaining parameters of TapasConfig as well as the model based on the task
						if task == "SQA":
												_UpperCamelCase   :						Any												=  TapasForQuestionAnswering(config=UpperCAmelCase_				)
						elif task == "WTQ":
												# run_task_main.py hparams
												_UpperCamelCase   :						List[str]												=  4
												_UpperCamelCase   :						Any												=  True
												# hparam_utils.py hparams
												_UpperCamelCase   :						str												=  0.664_694
												_UpperCamelCase   :						Dict												=  0.207_951
												_UpperCamelCase   :						List[Any]												=  0.121_194
												_UpperCamelCase   :						Union[str, Any]												=  True
												_UpperCamelCase   :						List[str]												=  True
												_UpperCamelCase   :						Any												=  False
												_UpperCamelCase   :						Optional[int]												=  0.0_352_513

												_UpperCamelCase   :						Optional[Any]												=  TapasForQuestionAnswering(config=UpperCAmelCase_				)
						elif task == "WIKISQL_SUPERVISED":
												# run_task_main.py hparams
												_UpperCamelCase   :						int												=  4
												_UpperCamelCase   :						List[Any]												=  False
												# hparam_utils.py hparams
												_UpperCamelCase   :						Union[str, Any]												=  36.4_519
												_UpperCamelCase   :						List[Any]												=  0.903_421
												_UpperCamelCase   :						List[str]												=  222.088
												_UpperCamelCase   :						int												=  True
												_UpperCamelCase   :						List[str]												=  True
												_UpperCamelCase   :						Any												=  True
												_UpperCamelCase   :						Dict												=  0.763_141

												_UpperCamelCase   :						Any												=  TapasForQuestionAnswering(config=UpperCAmelCase_				)
						elif task == "TABFACT":
												_UpperCamelCase   :						List[str]												=  TapasForSequenceClassification(config=UpperCAmelCase_				)
						elif task == "MLM":
												_UpperCamelCase   :						Optional[int]												=  TapasForMaskedLM(config=UpperCAmelCase_				)
						elif task == "INTERMEDIATE_PRETRAINING":
												_UpperCamelCase   :						Union[str, Any]												=  TapasModel(config=UpperCAmelCase_				)
						else:
												raise ValueError(f'Task {task} not supported.'				)

						print(f'Building PyTorch model from configuration: {config}'				)
						# Load weights from tf checkpoint
						load_tf_weights_in_tapas(UpperCAmelCase_    ,    UpperCAmelCase_    ,    UpperCAmelCase_				)

						# Save pytorch-model (weights and configuration)
						print(f'Save PyTorch model to {pytorch_dump_path}'				)
						model.save_pretrained(UpperCAmelCase_				)

						# Save tokenizer files
						print(f'Save tokenizer files to {pytorch_dump_path}'				)
						_UpperCamelCase   :						Optional[Any]												=  TapasTokenizer(vocab_file=tf_checkpoint_path[:-1_0] + 'vocab.txt'    ,    model_max_length=5_1_2				)
						tokenizer.save_pretrained(UpperCAmelCase_				)

						print('Used relative position embeddings:'    ,    model.config.reset_position_index_per_cell				)


if __name__ == "__main__":
					snake_case_					:      Union[str, Any]    			=    argparse.ArgumentParser()
					# Required parameters
					parser.add_argument(
					    '--task', default='SQA', type=str, help='Model task for which to convert a checkpoint. Defaults to SQA.'
					)
					parser.add_argument(
					    '--reset_position_index_per_cell',
					    default=False,
					    action='store_true',
					    help='Whether to use relative position embeddings or not. Defaults to True.',
					)
					parser.add_argument(
					    '--tf_checkpoint_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
					)
					parser.add_argument(
					    '--tapas_config_file',
					    default=None,
					    type=str,
					    required=True,
					    help=(
					        'The config json file corresponding to the pre-trained TAPAS model. \n'
					        'This specifies the model architecture.'
					    ),
					)
					parser.add_argument(
					    '--pytorch_dump_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
					)
					snake_case_					:      List[str]    			=    parser.parse_args()
					convert_tf_checkpoint_to_pytorch(
					    args.task,
					    args.reset_position_index_per_cell,
					    args.tf_checkpoint_path,
					    args.tapas_config_file,
					    args.pytorch_dump_path,
					)







'''simple docstring'''
def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_				):
						return int((input_a, input_a).count(0				) != 0				)






def A__       (	):
						assert nand_gate(0    ,    0				) == 1
						assert nand_gate(0    ,    1				) == 1
						assert nand_gate(1    ,    0				) == 1
						assert nand_gate(1    ,    1				) == 0


if __name__ == "__main__":
					print(nand_gate(0, 0))
					print(nand_gate(0, 1))
					print(nand_gate(1, 0))
					print(nand_gate(1, 1))


