


'''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


__snake_case											=					{
    '''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       a				(      __a			, __a			, __a			, __a=None       )  ->     Tuple:



					'''simple docstring'''






					UpperCamelCase__       :List[str]							 =			XLNetConfig.from_json_file(__a       )

					UpperCamelCase__       :int							 =			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}'''       )
										UpperCamelCase__       :Dict							 =			finetuning_task
										UpperCamelCase__       :str							 =			GLUE_TASKS_NUM_LABELS[finetuning_task]
										UpperCamelCase__       :Optional[Any]							 =			XLNetForSequenceClassification(__a       )
					elif "squad" in finetuning_task:
										UpperCamelCase__       :List[str]							 =			finetuning_task
										UpperCamelCase__       :Optional[Any]							 =			XLNetForQuestionAnswering(__a       )
					else:
										UpperCamelCase__       :str							 =			XLNetLMHeadModel(__a       )

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

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


if __name__ == "__main__":
		__snake_case											=					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''',
		)
		__snake_case											=					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'''
import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_distilbert import DistilBertTokenizer


__snake_case											=					logging.get_logger(__name__)

__snake_case											=					{'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}

__snake_case											=					{
    '''vocab_file''': {
        '''distilbert-base-uncased''': '''https://huggingface.co/distilbert-base-uncased/resolve/main/vocab.txt''',
        '''distilbert-base-uncased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/vocab.txt'''
        ),
        '''distilbert-base-cased''': '''https://huggingface.co/distilbert-base-cased/resolve/main/vocab.txt''',
        '''distilbert-base-cased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/vocab.txt'''
        ),
        '''distilbert-base-german-cased''': '''https://huggingface.co/distilbert-base-german-cased/resolve/main/vocab.txt''',
        '''distilbert-base-multilingual-cased''': (
            '''https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/vocab.txt'''
        ),
    },
    '''tokenizer_file''': {
        '''distilbert-base-uncased''': '''https://huggingface.co/distilbert-base-uncased/resolve/main/tokenizer.json''',
        '''distilbert-base-uncased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/tokenizer.json'''
        ),
        '''distilbert-base-cased''': '''https://huggingface.co/distilbert-base-cased/resolve/main/tokenizer.json''',
        '''distilbert-base-cased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/tokenizer.json'''
        ),
        '''distilbert-base-german-cased''': (
            '''https://huggingface.co/distilbert-base-german-cased/resolve/main/tokenizer.json'''
        ),
        '''distilbert-base-multilingual-cased''': (
            '''https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/tokenizer.json'''
        ),
    },
}

__snake_case											=					{
    '''distilbert-base-uncased''': 512,
    '''distilbert-base-uncased-distilled-squad''': 512,
    '''distilbert-base-cased''': 512,
    '''distilbert-base-cased-distilled-squad''': 512,
    '''distilbert-base-german-cased''': 512,
    '''distilbert-base-multilingual-cased''': 512,
}


__snake_case											=					{
    '''distilbert-base-uncased''': {'''do_lower_case''': True},
    '''distilbert-base-uncased-distilled-squad''': {'''do_lower_case''': True},
    '''distilbert-base-cased''': {'''do_lower_case''': False},
    '''distilbert-base-cased-distilled-squad''': {'''do_lower_case''': False},
    '''distilbert-base-german-cased''': {'''do_lower_case''': False},
    '''distilbert-base-multilingual-cased''': {'''do_lower_case''': False},
}
class        lowercase     (							A__ ):

		"""simple docstring"""

		_a   			=    VOCAB_FILES_NAMES
		_a   			=    PRETRAINED_VOCAB_FILES_MAP
		_a   			=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		_a   			=    PRETRAINED_INIT_CONFIGURATION
		_a   			=    ['input_ids', 'attention_mask']
		_a   			=    DistilBertTokenizer




		def __init__(		self   ,       UpperCamelCase_=None   ,       UpperCamelCase_=None   ,       UpperCamelCase_=True   ,       UpperCamelCase_="[UNK]"   ,       UpperCamelCase_="[SEP]"   ,       UpperCamelCase_="[PAD]"   ,       UpperCamelCase_="[CLS]"   ,       UpperCamelCase_="[MASK]"   ,       UpperCamelCase_=True   ,       UpperCamelCase_=None   ,       **UpperCamelCase_   ,       ):

							'''simple docstring'''


							super().__init__(
							    UpperCamelCase_   ,       tokenizer_file=UpperCamelCase_   ,       do_lower_case=UpperCamelCase_   ,       unk_token=UpperCamelCase_   ,       sep_token=UpperCamelCase_   ,       pad_token=UpperCamelCase_   ,       cls_token=UpperCamelCase_   ,       mask_token=UpperCamelCase_   ,       tokenize_chinese_chars=UpperCamelCase_   ,       strip_accents=UpperCamelCase_   ,       **UpperCamelCase_   ,       )

							UpperCamelCase__       :int							 =			json.loads(self.backend_tokenizer.normalizer.__getstate__()							)
							if (
							    normalizer_state.get('''lowercase'''   ,       UpperCamelCase_							) != do_lower_case
							    or normalizer_state.get('''strip_accents'''   ,       UpperCamelCase_							) != strip_accents
							    or normalizer_state.get('''handle_chinese_chars'''   ,       UpperCamelCase_							) != tokenize_chinese_chars
							):
												UpperCamelCase__       :int							 =			getattr(UpperCamelCase_   ,       normalizer_state.pop('''type'''							)							)
												UpperCamelCase__       :Optional[Any]							 =			do_lower_case
												UpperCamelCase__       :Optional[Any]							 =			strip_accents
												UpperCamelCase__       :List[Any]							 =			tokenize_chinese_chars
												UpperCamelCase__       :Any							 =			normalizer_class(**UpperCamelCase_							)

							UpperCamelCase__       :int							 =			do_lower_case




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_=None							):

							'''simple docstring'''


							UpperCamelCase__       :Tuple							 =			[self.cls_token_id] + token_ids_a + [self.sep_token_id]

							if token_ids_a:
												output += token_ids_a + [self.sep_token_id]

							return output




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_ = None							):

							'''simple docstring'''


							UpperCamelCase__       :List[str]							 =			[self.sep_token_id]
							UpperCamelCase__       :List[str]							 =			[self.cls_token_id]
							if token_ids_a is None:
												return len(cls + token_ids_a + sep							) * [0]
							return len(cls + token_ids_a + sep							) * [0] + len(token_ids_a + sep							) * [1]




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_ = None							):

							'''simple docstring'''


							UpperCamelCase__       :str							 =			self._tokenizer.model.save(UpperCamelCase_   ,       name=UpperCamelCase_							)
							return tuple(UpperCamelCase_							)