






"""simple docstring"""



import argparse
import os

import torch

from transformers import (
    XLNetConfig,
    XLNetForQuestionAnswering,
    XLNetForSequenceClassification,
    XLNetLMHeadModel,
    load_tf_weights_in_xlnet,
)
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


__A		:       List[str]  				=		{
    '''cola''': 2,
    '''mnli''': 3,
    '''mrpc''': 2,
    '''sst-2''': 2,
    '''sts-b''': 1,
    '''qqp''': 2,
    '''qnli''': 2,
    '''rte''': 2,
    '''wnli''': 2,
}


logging.set_verbosity_info()



def 						lowercase    (				__snake_case				: Union[str, Any]		,					__snake_case				: Any		,					__snake_case				: str		,					__snake_case				: Tuple=None	):
		# Initialise PyTorch model
		lowercase_ : int							       =   XLNetConfig.from_json_file(__snake_case	)

		lowercase_ : Union[str, Any]							       =   finetuning_task.lower() if finetuning_task is not None else """"""
		if finetuning_task in GLUE_TASKS_NUM_LABELS:
				print(F'''Building PyTorch XLNetForSequenceClassification model from configuration: {config}'''	)
				lowercase_ : str							       =   finetuning_task
				lowercase_ : List[str]							       =   GLUE_TASKS_NUM_LABELS[finetuning_task]
				lowercase_ : List[Any]							       =   XLNetForSequenceClassification(__snake_case	)
		elif "squad" in finetuning_task:
				lowercase_ : Union[str, Any]							       =   finetuning_task
				lowercase_ : str							       =   XLNetForQuestionAnswering(__snake_case	)
		else:
				lowercase_ : Optional[Any]							       =   XLNetLMHeadModel(__snake_case	)

		# Load weights from tf checkpoint
		load_tf_weights_in_xlnet(__snake_case		,					__snake_case		,					__snake_case	)

		# Save pytorch-model
		lowercase_ : Any							       =   os.path.join(__snake_case		,					__snake_case	)
		lowercase_ : str							       =   os.path.join(__snake_case		,					__snake_case	)
		print(F'''Save PyTorch model to {os.path.abspath(__snake_case	)}'''	)
		torch.save(model.state_dict()		,					__snake_case	)
		print(F'''Save configuration file to {os.path.abspath(__snake_case	)}'''	)
		with open(__snake_case		,					'''w'''		,					encoding='''utf-8'''	) as f:
				f.write(config.to_json_string()	)


if __name__ == "__main__":
						__A		:       int  				=		argparse.ArgumentParser()
						# Required parameters
						parser.add_argument(
						    '''--tf_checkpoint_path''', default=None, type=str, required=True, help='''Path to the TensorFlow checkpoint path.'''
						)
						parser.add_argument(
						    '''--xlnet_config_file''',
						    default=None,
						    type=str,
						    required=True,
						    help=(
						        '''The config json file corresponding to the pre-trained XLNet model. \n'''
						        '''This specifies the model architecture.'''
						    ),
						)
						parser.add_argument(
						    '''--pytorch_dump_folder_path''',
						    default=None,
						    type=str,
						    required=True,
						    help='''Path to the folder to store the PyTorch model or dataset/vocab.''',
						)
						parser.add_argument(
						    '''--finetuning_task''',
						    default=None,
						    type=str,
						    help='''Name of a task on which the XLNet TensorFlow model was fine-tuned''',
						)
						__A		:       List[Any]  				=		parser.parse_args()
						print(args)

						convert_xlnet_checkpoint_to_pytorch(
						    args.tf_checkpoint_path, args.xlnet_config_file, args.pytorch_dump_folder_path, args.finetuning_task
						)











'''simple docstring'''







from heapq import heappop, heappush

import numpy as np





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase				,			)      ->       tuple[float | int, list[tuple[int, int]]]:
							lowerCamelCase__  ,		lowerCamelCase__					:	Union[str, Any]         =       grid.shape
							lowerCamelCase__					:	List[str]         =       [-1, 1, 0, 0]
							lowerCamelCase__					:	Dict         =       [0, 0, -1, 1]
							if allow_diagonal:
														dx += [-1, -1, 1, 1]
														dy += [-1, 1, -1, 1]

							lowerCamelCase__  ,		lowerCamelCase__					:	Any         =       [(0, source)], set()
							lowerCamelCase__					:	Tuple         =       np.full((rows, cols)				,			np.inf      )
							lowerCamelCase__					:	List[str]         =       0
							lowerCamelCase__					:	Optional[int]         =       np.empty((rows, cols)				,			dtype=UpperCamelCase      )
							lowerCamelCase__					:	str         =       None

							while queue:
														((lowerCamelCase__)  ,		(lowerCamelCase__))					:	List[str]         =       heappop(UpperCamelCase      )
														if (x, y) in visited:
																					continue
														visited.add((x, y)      )

														if (x, y) == destination:
																					lowerCamelCase__					:	Optional[int]         =       []
																					while (x, y) != source:
																												path.append((x, y)      )
																												lowerCamelCase__  ,		lowerCamelCase__					:	List[Any]         =       predecessors[x, y]
																					path.append(UpperCamelCase      )  # add the source manually
																					path.reverse()
																					return matrix[destination], path

														for i in range(len(UpperCamelCase      )      ):
																					lowerCamelCase__  ,		lowerCamelCase__					:	Union[str, Any]         =       x + dx[i], y + dy[i]
																					if 0 <= nx < rows and 0 <= ny < cols:
																												lowerCamelCase__					:	Any         =       grid[nx][ny]
																												if next_node == 1 and matrix[nx, ny] > dist + 1:
																																			heappush(UpperCamelCase				,			(dist + 1, (nx, ny))      )
																																			lowerCamelCase__					:	Union[str, Any]         =       dist + 1
																																			lowerCamelCase__					:	List[str]         =       (x, y)

							return np.inf, []


if __name__ == "__main__":
			import doctest

			doctest.testmod()

