






import argparse
import json

import numpy
import torch

from transformers.models.xlm.tokenization_xlm import VOCAB_FILES_NAMES
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()






def 							A     (       a_							,a_					)     ->						Optional[Any]:
					# Load checkpoint
					__UpperCamelCase      :					int       		=torch.load(a_							,map_location='cpu'					)

					__UpperCamelCase      :					List[Any]       		=chkpt['model']

					# We have the base model one level deeper than the original XLM repository
					__UpperCamelCase      :					str       		={}
					for k, v in state_dict.items():
										if "pred_layer" in k:
															__UpperCamelCase      :					Optional[Any]       		=v
										else:
															__UpperCamelCase      :					Optional[Any]       		=v

					__UpperCamelCase      :					List[Any]       		=chkpt['params']
					__UpperCamelCase      :					str       		={n: v for n, v in config.items() if not isinstance(a_							,(torch.FloatTensor, numpy.ndarray)					)}

					__UpperCamelCase      :					str       		=chkpt['dico_word2id']
					__UpperCamelCase      :					Dict       		={s + '</w>' if s.find('@@'					) == -1 and i > 13 else s.replace('@@'							,''					): i for s, i in vocab.items()}

					# Save pytorch-model
					__UpperCamelCase      :					List[Any]       		=pytorch_dump_folder_path + '/' + WEIGHTS_NAME
					__UpperCamelCase      :					Tuple       		=pytorch_dump_folder_path + '/' + CONFIG_NAME
					__UpperCamelCase      :					Any       		=pytorch_dump_folder_path + '/' + VOCAB_FILES_NAMES['vocab_file']

					print(F'Save PyTorch model to {pytorch_weights_dump_path}'					)
					torch.save(a_							,a_					)

					print(F'Save configuration file to {pytorch_config_dump_path}'					)
					with open(a_							,'w'							,encoding='utf-8'					) as f:
										f.write(json.dumps(a_							,indent=2					) + '\n'					)

					print(F'Save vocab file to {pytorch_config_dump_path}'					)
					with open(a_							,'w'							,encoding='utf-8'					) as f:
										f.write(json.dumps(a_							,indent=2					) + '\n'					)


if __name__ == "__main__":
							A_       :str       =						argparse.ArgumentParser()
							# Required parameters
							parser.add_argument(
							    '''--xlm_checkpoint_path''', default=None, type=str, required=True, help='''Path the official PyTorch dump.'''
							)
							parser.add_argument(
							    '''--pytorch_dump_folder_path''', default=None, type=str, required=True, help='''Path to the output PyTorch model.'''
							)
							A_       :List[Any]       =						parser.parse_args()
							convert_xlm_checkpoint_to_pytorch(args.xlm_checkpoint_path, args.pytorch_dump_folder_path)



import warnings

from ...utils import logging
from .image_processing_chinese_clip import ChineseCLIPImageProcessor


_lowerCamelCase       :				Dict       =			logging.get_logger(__name__)




class    SCREAMING_SNAKE_CASE__     (	UpperCAmelCase					):





	'''simple docstring'''



	def __init__(  self	:    Tuple			,  *lowercase	:    Optional[int]			,  **lowercase	:    Any	):


				'''simple docstring'''


				warnings.warn(
				    'The class ChineseCLIPFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'
				    ' Please use ChineseCLIPImageProcessor instead.'			,  lowercase			,  )
				super().__init__(*lowercase			,  **lowercase	)