





'''simple docstring'''

import argparse

from transformers import BigBirdConfig, BigBirdForPreTraining, BigBirdForQuestionAnswering, load_tf_weights_in_big_bird
from transformers.utils import logging


logging.set_verbosity_info()







def 							UpperCAmelCase_    (	lowerCAmelCase_		,							lowerCAmelCase_		,							lowerCAmelCase_		,							lowerCAmelCase_							):

				"""simple docstring"""






				lowercase         = BigBirdConfig.from_json_file(lowerCAmelCase_							)
				print(f'Building PyTorch model from configuration: {config}'							)

				if is_trivia_qa:
								lowercase         = BigBirdForQuestionAnswering(lowerCAmelCase_							)
				else:
								lowercase         = BigBirdForPreTraining(lowerCAmelCase_							)

				# Load weights from tf checkpoint
				load_tf_weights_in_big_bird(lowerCAmelCase_		,							lowerCAmelCase_		,							is_trivia_qa=lowerCAmelCase_							)

				# Save pytorch-model
				print(f'Save PyTorch model to {pytorch_dump_path}'							)
				model.save_pretrained(lowerCAmelCase_							)


if __name__ == "__main__":
			__lowerCamelCase : Tuple											=			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(
			    "--big_bird_config_file",
			    default=None,
			    type=str,
			    required=True,
			    help=(
			        "The config json file corresponding to the pre-trained BERT 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."
			)
			parser.add_argument(
			    "--is_trivia_qa", action="store_true", help="Whether to convert a model with a trivia_qa head."
			)
			__lowerCamelCase : Any											=			parser.parse_args()
			convert_tf_checkpoint_to_pytorch(
			    args.tf_checkpoint_path, args.big_bird_config_file, args.pytorch_dump_path, args.is_trivia_qa
			)











'''simple docstring'''

from argparse import ArgumentParser

from . import BaseTransformersCLICommand







def 							UpperCAmelCase_    (	lowerCAmelCase_							):

				"""simple docstring"""






				return DownloadCommand(args.model		,							args.cache_dir		,							args.force		,							args.trust_remote_code							)


class       UpperCAmelCase (						_lowercase  ):




		@staticmethod
		def 				UpperCAmelCase__   (A__      :	ArgumentParser				)					-> List[Any]:
						lowercase         = parser.add_parser("download"				)
						download_parser.add_argument(
						    "--cache-dir"							,			type=A__							,			default=A__							,			help="Path to location to store the models"				)
						download_parser.add_argument(
						    "--force"							,			action="store_true"							,			help="Force the model to be download even if already in cache-dir"				)
						download_parser.add_argument(
						    "--trust-remote-code"							,			action="store_true"							,			help="Whether or not to allow for custom models defined on the Hub in their own modeling files. Use only if you've reviewed the code as it will execute on your local machine"							,			)
						download_parser.add_argument("model"							,			type=A__							,			help="Name of the model to download"				)
						download_parser.set_defaults(func=A__				)




		def __init__(self      :	Tuple							,			A__      :	str							,			A__      :	str							,			A__      :	bool							,			A__      :	bool				)					-> str:
						lowercase         = model
						lowercase         = cache
						lowercase         = force
						lowercase         = trust_remote_code





		def 				UpperCAmelCase__   (self      :	Union[str, Any]				)					-> Dict:
						from ..models.auto import AutoModel, AutoTokenizer

						AutoModel.from_pretrained(
						    self._model							,			cache_dir=self._cache							,			force_download=self._force							,			trust_remote_code=self._trust_remote_code				)
						AutoTokenizer.from_pretrained(
						    self._model							,			cache_dir=self._cache							,			force_download=self._force							,			trust_remote_code=self._trust_remote_code				)




