



import argparse
import os
import re

import packaging.version


SCREAMING_SNAKE_CASE_				= """examples/"""
SCREAMING_SNAKE_CASE_				= {
    """examples""": (re.compile(r"""^check_min_version\(\"[^\"]+\"\)\s*$""", re.MULTILINE), """check_min_version(\"VERSION\")\n"""),
    """init""": (re.compile(r"""^__version__\s+=\s+\"([^\"]+)\"\s*$""", re.MULTILINE), """__version__ = \"VERSION\"\n"""),
    """setup""": (re.compile(r"""^(\s*)version\s*=\s*\"[^\"]+\",""", re.MULTILINE), r"""\1version=\"VERSION\","""),
    """doc""": (re.compile(r"""^(\s*)release\s*=\s*\"[^\"]+\"$""", re.MULTILINE), """release = \"VERSION\"\n"""),
}
SCREAMING_SNAKE_CASE_				= {
    """init""": """src/transformers/__init__.py""",
    """setup""": """setup.py""",
}
SCREAMING_SNAKE_CASE_				= """README.md"""



def        lowerCAmelCase_						(							SCREAMING_SNAKE_CASE__, SCREAMING_SNAKE_CASE__, SCREAMING_SNAKE_CASE__	)			->      Any:






		with open(_snake_case, "r", encoding="utf-8", newline="\n"	) as f:
				a_     :      Optional[int] 						=     f.read()
		a_						,				a_     :      List[str] 						=     REPLACE_PATTERNS[pattern]
		a_     :      Any 						=     replace.replace("VERSION", _snake_case	)
		a_     :      Union[str, Any] 						=     re_pattern.sub(_snake_case, _snake_case	)
		with open(_snake_case, "w", encoding="utf-8", newline="\n"	) as f:
				f.write(_snake_case	)



def        lowerCAmelCase_						(							SCREAMING_SNAKE_CASE__	)			->      Any:






		for folder, directories, fnames in os.walk(_snake_case	):
				# Removing some of the folders with non-actively maintained examples from the walk
				if "research_projects" in directories:
						directories.remove("research_projects"	)
				if "legacy" in directories:
						directories.remove("legacy"	)
				for fname in fnames:
						if fname.endswith(".py"	):
								update_version_in_file(os.path.join(_snake_case, _snake_case	), _snake_case, pattern="examples"	)



def        lowerCAmelCase_						(							SCREAMING_SNAKE_CASE__, SCREAMING_SNAKE_CASE__=False	)			->      int:






		for pattern, fname in REPLACE_FILES.items():
				update_version_in_file(_snake_case, _snake_case, _snake_case	)
		if not patch:
				update_version_in_examples(_snake_case	)



def        lowerCAmelCase_						(							)			->      List[str]:
		a_     :      List[Any] 						=     "🤗 Transformers currently provides the following architectures"
		a_     :      List[str] 						=     "1. Want to contribute a new model?"
		with open(_snake_case, "r", encoding="utf-8", newline="\n"	) as f:
				a_     :      str 						=     f.readlines()

		# Find the start of the list.
		a_     :      Union[str, Any] 						=     0
		while not lines[start_index].startswith(_start_prompt	):
				start_index += 1
		start_index += 1

		a_     :      List[Any] 						=     start_index
		# Update the lines in the model list.
		while not lines[index].startswith(_end_prompt	):
				if lines[index].startswith("1."	):
						a_     :      int 						=     lines[index].replace(
						    "https://huggingface.co/docs/transformers/main/model_doc", "https://huggingface.co/docs/transformers/model_doc", )
				index += 1

		with open(_snake_case, "w", encoding="utf-8", newline="\n"	) as f:
				f.writelines(_snake_case	)



def        lowerCAmelCase_						(							)			->      Tuple:






		with open(REPLACE_FILES["init"], "r"	) as f:
				a_     :      int 						=     f.read()
		a_     :      str 						=     REPLACE_PATTERNS["init"][0].search(_snake_case	).groups()[0]
		return packaging.version.parse(_snake_case	)



def        lowerCAmelCase_						(							SCREAMING_SNAKE_CASE__=False	)			->      Union[str, Any]:
		a_     :      List[str] 						=     get_version()
		if patch and default_version.is_devrelease:
				raise ValueError("Can't create a patch version from the dev branch, checkout a released version!"	)
		if default_version.is_devrelease:
				a_     :      Optional[Any] 						=     default_version.base_version
		elif patch:
				a_     :      List[Any] 						=     F"""{default_version.major}.{default_version.minor}.{default_version.micro + 1}"""
		else:
				a_     :      List[Any] 						=     F"""{default_version.major}.{default_version.minor + 1}.0"""

		# Now let's ask nicely if that's the right one.
		a_     :      Any 						=     input(F"""Which version are you releasing? [{default_version}]"""	)
		if len(_snake_case	) == 0:
				a_     :      Any 						=     default_version

		print(F"""Updating version to {version}."""	)
		global_version_update(_snake_case, patch=_snake_case	)
		if not patch:
				print("Cleaning main README, don't forget to run `make fix-copies`."	)
				clean_main_ref_in_model_list()



def        lowerCAmelCase_						(							)			->      str:
		a_     :      int 						=     get_version()
		a_     :      Optional[int] 						=     F"""{current_version.major}.{current_version.minor + 1}.0.dev0"""
		a_     :      Tuple 						=     current_version.base_version

		# Check with the user we got that right.
		a_     :      List[Any] 						=     input(F"""Which version are we developing now? [{dev_version}]"""	)
		if len(_snake_case	) == 0:
				a_     :      Optional[Any] 						=     dev_version

		print(F"""Updating version to {version}."""	)
		global_version_update(_snake_case	)
		print("Cleaning main README, don't forget to run `make fix-copies`."	)
		clean_main_ref_in_model_list()


if __name__ == "__main__":
					SCREAMING_SNAKE_CASE_				= argparse.ArgumentParser()
					parser.add_argument("""--post_release""", action="""store_true""", help="""Whether this is pre or post release.""")
					parser.add_argument("""--patch""", action="""store_true""", help="""Whether or not this is a patch release.""")
					SCREAMING_SNAKE_CASE_				= parser.parse_args()
					if not args.post_release:
										pre_release_work(patch=args.patch)
					elif args.patch:
										print("""Nothing to do after a patch :-)""")
					else:
										post_release_work()




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


SCREAMING_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        lowerCAmelCase_						(							SCREAMING_SNAKE_CASE__, SCREAMING_SNAKE_CASE__, SCREAMING_SNAKE_CASE__, SCREAMING_SNAKE_CASE__=None	)			->      int:
		# Initialise PyTorch model
		a_     :      Optional[int] 						=     XLNetConfig.from_json_file(SCREAMING_SNAKE_CASE__	)

		a_     :      List[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}"""	)
				a_     :      Tuple 						=     finetuning_task
				a_     :      Dict 						=     GLUE_TASKS_NUM_LABELS[finetuning_task]
				a_     :      Tuple 						=     XLNetForSequenceClassification(SCREAMING_SNAKE_CASE__	)
		elif "squad" in finetuning_task:
				a_     :      Tuple 						=     finetuning_task
				a_     :      List[Any] 						=     XLNetForQuestionAnswering(SCREAMING_SNAKE_CASE__	)
		else:
				a_     :      Any 						=     XLNetLMHeadModel(SCREAMING_SNAKE_CASE__	)

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

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


if __name__ == "__main__":
					SCREAMING_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""",
					)
					SCREAMING_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
					)