





"""simple docstring"""





import argparse

import torch

from transformers import OpenAIGPTConfig, OpenAIGPTModel, load_tf_weights_in_openai_gpt
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()


def       a__					(					_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE    ):




		"""simple docstring"""


		if openai_config_file == "":
				UpperCamelCase   =	OpenAIGPTConfig()
		else:
				UpperCamelCase   =	OpenAIGPTConfig.from_json_file(_SCREAMING_SNAKE_CASE    )
		UpperCamelCase   =	OpenAIGPTModel(_SCREAMING_SNAKE_CASE    )

		# Load weights from numpy
		load_tf_weights_in_openai_gpt(_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE  ,	_SCREAMING_SNAKE_CASE    )

		# Save pytorch-model
		UpperCamelCase   =	pytorch_dump_folder_path + "/" + WEIGHTS_NAME
		UpperCamelCase   =	pytorch_dump_folder_path + "/" + CONFIG_NAME
		print(F"Save PyTorch model to {pytorch_weights_dump_path}"    )
		torch.save(model.state_dict()  ,	_SCREAMING_SNAKE_CASE    )
		print(F"Save configuration file to {pytorch_config_dump_path}"    )
		with open(_SCREAMING_SNAKE_CASE  ,	"w"  ,	encoding="utf-8"    ) as f:
				f.write(config.to_json_string()    )


if __name__ == "__main__":
						lowerCAmelCase__     			=			argparse.ArgumentParser()
						# Required parameters
						parser.add_argument(
						    '''--openai_checkpoint_folder_path''',
						    default=None,
						    type=str,
						    required=True,
						    help='''Path to the TensorFlow checkpoint path.''',
						)
						parser.add_argument(
						    '''--pytorch_dump_folder_path''', default=None, type=str, required=True, help='''Path to the output PyTorch model.'''
						)
						parser.add_argument(
						    '''--openai_config_file''',
						    default='''''',
						    type=str,
						    help=(
						        '''An optional config json file corresponding to the pre-trained OpenAI model. \n'''
						        '''This specifies the model architecture.'''
						    ),
						)
						lowerCAmelCase__     			=			parser.parse_args()
						convert_openai_checkpoint_to_pytorch(
						    args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
						)









"""simple docstring"""





import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


lowerCAmelCase__     			=			logging.get_logger(__name__)





class        _lowerCamelCase      (       _lowercase ):
						UpperCAmelCase_ =			"upernet"


						def __init__(self   ,							__a=None   ,							__a=5_12   ,							__a=0.02   ,							__a=[1, 2, 3, 6]   ,							__a=True   ,							__a=0.4   ,							__a=3_84   ,							__a=2_56   ,							__a=1   ,							__a=False   ,							__a=2_55   ,							**__a   ,							) ->   Tuple:
								super().__init__(**__a		)

								if backbone_config is None:
										logger.info("`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."		)
										UpperCamelCase   =	CONFIG_MAPPING["resnet"](out_features=["stage1", "stage2", "stage3", "stage4"]		)
								elif isinstance(__a   ,							__a		):
										UpperCamelCase   =	backbone_config.get("model_type"		)
										UpperCamelCase   =	CONFIG_MAPPING[backbone_model_type]
										UpperCamelCase   =	config_class.from_dict(__a		)

								UpperCamelCase   =	backbone_config
								UpperCamelCase   =	hidden_size
								UpperCamelCase   =	initializer_range
								UpperCamelCase   =	pool_scales
								UpperCamelCase   =	use_auxiliary_head
								UpperCamelCase   =	auxiliary_loss_weight
								UpperCamelCase   =	auxiliary_in_channels
								UpperCamelCase   =	auxiliary_channels
								UpperCamelCase   =	auxiliary_num_convs
								UpperCamelCase   =	auxiliary_concat_input
								UpperCamelCase   =	loss_ignore_index




						def     snake_case_   (self		) ->   Optional[int]:
								UpperCamelCase   =	copy.deepcopy(self.__dict__		)
								UpperCamelCase   =	self.backbone_config.to_dict()
								UpperCamelCase   =	self.__class__.model_type
								return output






