




import importlib.util
import os
import platform
from argparse import ArgumentParser

import huggingface_hub

from .. import __version__ as version
from ..utils import (
    is_accelerate_available,
    is_flax_available,
    is_safetensors_available,
    is_tf_available,
    is_torch_available,
)
from . import BaseTransformersCLICommand

def lowercase    (  SCREAMING_SNAKE_CASE )			->							Any:


			'''simple docstring'''







			return EnvironmentCommand()

def lowercase    (  SCREAMING_SNAKE_CASE )			->							Any:


			'''simple docstring'''







			return EnvironmentCommand(args.accelerate_config_file )



class       a_       (     SCREAMING_SNAKE_CASE__     ):





	@staticmethod
	def 						A_(							SCREAMING_SNAKE_CASE      )  ->					Optional[int]:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						parser.add_parser('env'      )
				download_parser.set_defaults(func=SCREAMING_SNAKE_CASE      )
				download_parser.add_argument(
				    '--accelerate-config_file'      ,     default=SCREAMING_SNAKE_CASE      ,     help='The accelerate config file to use for the default values in the launching script.'      ,     )
				download_parser.set_defaults(func=SCREAMING_SNAKE_CASE      )





	def __init__(							self      ,     SCREAMING_SNAKE_CASE      ,     *SCREAMING_SNAKE_CASE      )  ->					None:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						accelerate_config_file





	def 						A_(							self      )  ->					Any:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						'not installed'
				if is_safetensors_available():
							import safetensors

							SCREAMING_SNAKE_CASE_								=						safetensors.__version__
				elif importlib.util.find_spec('safetensors'      ) is not None:
							import safetensors

							SCREAMING_SNAKE_CASE_								=						f'{safetensors.__version__} but is ignored because of PyTorch version too old.'

				SCREAMING_SNAKE_CASE_								=						'not installed'
				SCREAMING_SNAKE_CASE_								=						SCREAMING_SNAKE_CASE_								=						'not found'
				if is_accelerate_available():
							import accelerate
							from accelerate.commands.config import default_config_file, load_config_from_file

							SCREAMING_SNAKE_CASE_								=						accelerate.__version__
							# Get the default from the config file.
							if self._accelerate_config_file is not None or os.path.isfile(SCREAMING_SNAKE_CASE      ):
										SCREAMING_SNAKE_CASE_								=						load_config_from_file(self._accelerate_config_file      ).to_dict()

							SCREAMING_SNAKE_CASE_								=						(
							    '\n'.join([f'\t- {prop}: {val}' for prop, val in accelerate_config.items()]      )
							    if isinstance(SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE      )
							    else f'\t{accelerate_config}'
							)

				SCREAMING_SNAKE_CASE_								=						'not installed'
				SCREAMING_SNAKE_CASE_								=						'NA'
				if is_torch_available():
							import torch

							SCREAMING_SNAKE_CASE_								=						torch.__version__
							SCREAMING_SNAKE_CASE_								=						torch.cuda.is_available()

				SCREAMING_SNAKE_CASE_								=						'not installed'
				SCREAMING_SNAKE_CASE_								=						'NA'
				if is_tf_available():
							import tensorflow as tf

							SCREAMING_SNAKE_CASE_								=						tf.__version__
							try:
										# deprecated in v2.1
										SCREAMING_SNAKE_CASE_								=						tf.test.is_gpu_available()
							except AttributeError:
										# returns list of devices, convert to bool
										SCREAMING_SNAKE_CASE_								=						bool(tf.config.list_physical_devices('GPU'      )      )

				SCREAMING_SNAKE_CASE_								=						'not installed'
				SCREAMING_SNAKE_CASE_								=						'not installed'
				SCREAMING_SNAKE_CASE_								=						'not installed'
				SCREAMING_SNAKE_CASE_								=						'NA'
				if is_flax_available():
							import flax
							import jax
							import jaxlib

							SCREAMING_SNAKE_CASE_								=						flax.__version__
							SCREAMING_SNAKE_CASE_								=						jax.__version__
							SCREAMING_SNAKE_CASE_								=						jaxlib.__version__
							SCREAMING_SNAKE_CASE_								=						jax.lib.xla_bridge.get_backend().platform

				SCREAMING_SNAKE_CASE_								=						{
				    '`transformers` version': version,
				    'Platform': platform.platform(),
				    'Python version': platform.python_version(),
				    'Huggingface_hub version': huggingface_hub.__version__,
				    'Safetensors version': f'{safetensors_version}',
				    'Accelerate version': f'{accelerate_version}',
				    'Accelerate config': f'{accelerate_config_str}',
				    'PyTorch version (GPU?)': f'{pt_version} ({pt_cuda_available})',
				    'Tensorflow version (GPU?)': f'{tf_version} ({tf_cuda_available})',
				    'Flax version (CPU?/GPU?/TPU?)': f'{flax_version} ({jax_backend})',
				    'Jax version': f'{jax_version}',
				    'JaxLib version': f'{jaxlib_version}',
				    'Using GPU in script?': '<fill in>',
				    'Using distributed or parallel set-up in script?': '<fill in>',
				}

				print('\nCopy-and-paste the text below in your GitHub issue and FILL OUT the two last points.\n'      )
				print(self.format_dict(SCREAMING_SNAKE_CASE      )      )

				return info





	@staticmethod
	def 						A_(							SCREAMING_SNAKE_CASE      )  ->					List[str]:




				"""simple docstring"""



				return "\n".join([f'- {prop}: {val}' for prop, val in d.items()]      ) + "\n"






import argparse

import torch

from transformers import FunnelBaseModel, FunnelConfig, FunnelModel, load_tf_weights_in_funnel
from transformers.utils import logging


logging.set_verbosity_info()

def lowercase    (  SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE )			->							Union[str, Any]:


			'''simple docstring'''







			SCREAMING_SNAKE_CASE_								=						FunnelConfig.from_json_file(SCREAMING_SNAKE_CASE )
			print(F'Building PyTorch model from configuration: {config}' )
			SCREAMING_SNAKE_CASE_								=						FunnelBaseModel(SCREAMING_SNAKE_CASE ) if base_model else FunnelModel(SCREAMING_SNAKE_CASE )

			# Load weights from tf checkpoint
			load_tf_weights_in_funnel(SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE )

			# Save pytorch-model
			print(F'Save PyTorch model to {pytorch_dump_path}' )
			torch.save(model.state_dict()       ,    SCREAMING_SNAKE_CASE )


if __name__ == "__main__":
				SCREAMING_SNAKE_CASE__     :     Union[str, 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(
				    "--config_file",
				    default=None,
				    type=str,
				    required=True,
				    help="The config json file corresponding to the pre-trained model. \nThis 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(
				    "--base_model", action="store_true", help="Whether you want just the base model (no decoder) or not."
				)
				SCREAMING_SNAKE_CASE__     :     List[Any]		    =       parser.parse_args()
				convert_tf_checkpoint_to_pytorch(
				    args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.base_model
				)
