




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


SCREAMING_SNAKE_CASE:     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 					_a							(					lowerCAmelCase    ,						lowerCAmelCase    ,						lowerCAmelCase    ,						lowerCAmelCase=None )->	Tuple:
		SCREAMING_SNAKE_CASE_					      =							XLNetConfig.from_json_file(_lowercase )

		SCREAMING_SNAKE_CASE_					      =							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}''' )
				SCREAMING_SNAKE_CASE_					      =							finetuning_task
				SCREAMING_SNAKE_CASE_					      =							GLUE_TASKS_NUM_LABELS[finetuning_task]
				SCREAMING_SNAKE_CASE_					      =							XLNetForSequenceClassification(_lowercase )
		elif "squad" in finetuning_task:
				SCREAMING_SNAKE_CASE_					      =							finetuning_task
				SCREAMING_SNAKE_CASE_					      =							XLNetForQuestionAnswering(_lowercase )
		else:
				SCREAMING_SNAKE_CASE_					      =							XLNetLMHeadModel(_lowercase )

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

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


if __name__ == "__main__":
						SCREAMING_SNAKE_CASE:     List[Any]									= 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''',
						)
						SCREAMING_SNAKE_CASE:     Union[str, 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
						)





# Lint as: python3
# pylint: enable=line-too-long
# pylint: disable=g-import-not-at-top,g-bad-import-order,wrong-import-position

__a							     =					'2.13.1'

import platform

import pyarrow
from packaging import version


if version.parse(platform.python_version()) < version.parse('3.7'):
     raise ImportWarning(
         'To use `datasets`, Python>=3.7 is required, and the current version of Python doesn\'t match this condition.'
     )

if version.parse(pyarrow.__version__).major < 8:
     raise ImportWarning(
         'To use `datasets`, the module `pyarrow>=8.0.0` is required, and the current version of `pyarrow` doesn\'t match this condition.\n'
         'If you are running this in a Google Colab, you should probably just restart the runtime to use the right version of `pyarrow`.'
     )

del platform
del pyarrow
del version

from .arrow_dataset import Dataset
from .arrow_reader import ReadInstruction
from .builder import ArrowBasedBuilder, BeamBasedBuilder, BuilderConfig, DatasetBuilder, GeneratorBasedBuilder
from .combine import concatenate_datasets, interleave_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .download import *
from .features import *
from .fingerprint import disable_caching, enable_caching, is_caching_enabled, set_caching_enabled
from .info import DatasetInfo, MetricInfo
from .inspect import (
    get_dataset_config_info,
    get_dataset_config_names,
    get_dataset_infos,
    get_dataset_split_names,
    inspect_dataset,
    inspect_metric,
    list_datasets,
    list_metrics,
)
from .iterable_dataset import IterableDataset
from .load import load_dataset, load_dataset_builder, load_from_disk, load_metric
from .metric import Metric
from .splits import (
    NamedSplit,
    NamedSplitAll,
    Split,
    SplitBase,
    SplitDict,
    SplitGenerator,
    SplitInfo,
    SubSplitInfo,
    percent,
)
from .tasks import *
from .utils import *
from .utils import logging


# deprecated modules
from datasets import arrow_dataset as _arrow_dataset  # isort:skip
from datasets import utils as _utils  # isort:skip
from datasets.utils import download_manager as _deprecated_download_manager  # isort:skip

__a							     =					concatenate_datasets
__a							     =					DownloadConfig
__a							     =					DownloadManager
__a							     =					DownloadMode
__a							     =					DownloadConfig
__a							     =					DownloadMode
__a							     =					DownloadManager

del _arrow_dataset, _utils, _deprecated_download_manager