

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 							__SCREAMING_SNAKE_CASE     (   a__    :   Any			,a__    :   Optional[Any]       )					->				Union[str, Any]:
	# Load checkpoint
	__A :			Union[str, Any]		    =			torch.load(a__			,map_location="""cpu"""       )

	__A :			Optional[Any]		    =			chkpt["""model"""]

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

	__A :			Optional[Any]		    =			chkpt["""params"""]
	__A :			Tuple		    =			{n: v for n, v in config.items() if not isinstance(a__			,(torch.FloatTensor, numpy.ndarray)       )}

	__A :			List[Any]		    =			chkpt["""dico_word2id"""]
	__A :			Tuple		    =			{s + """</w>""" if s.find("""@@"""       ) == -1 and i > 13 else s.replace("""@@"""			,""""""       ): i for s, i in vocab.items()}

	# Save pytorch-model
	__A :			Any		    =			pytorch_dump_folder_path + """/""" + WEIGHTS_NAME
	__A :			Union[str, Any]		    =			pytorch_dump_folder_path + """/""" + CONFIG_NAME
	__A :			Optional[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__":
			UpperCAmelCase_							:					List[Any]		 =   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.'''
			)
			UpperCAmelCase_							:					int		 =   parser.parse_args()
			convert_xlm_checkpoint_to_pytorch(args.xlm_checkpoint_path, args.pytorch_dump_folder_path)









from . import (
    albert,
    align,
    altclip,
    audio_spectrogram_transformer,
    auto,
    autoformer,
    bark,
    bart,
    barthez,
    bartpho,
    beit,
    bert,
    bert_generation,
    bert_japanese,
    bertweet,
    big_bird,
    bigbird_pegasus,
    biogpt,
    bit,
    blenderbot,
    blenderbot_small,
    blip,
    blip_a,
    bloom,
    bridgetower,
    byta,
    camembert,
    canine,
    chinese_clip,
    clap,
    clip,
    clipseg,
    codegen,
    conditional_detr,
    convbert,
    convnext,
    convnextva,
    cpm,
    cpmant,
    ctrl,
    cvt,
    dataavec,
    deberta,
    deberta_va,
    decision_transformer,
    deformable_detr,
    deit,
    deprecated,
    deta,
    detr,
    dialogpt,
    dinat,
    distilbert,
    dit,
    donut,
    dpr,
    dpt,
    efficientformer,
    efficientnet,
    electra,
    encodec,
    encoder_decoder,
    ernie,
    ernie_m,
    esm,
    falcon,
    flaubert,
    flava,
    fnet,
    focalnet,
    fsmt,
    funnel,
    git,
    glpn,
    gpta,
    gpt_bigcode,
    gpt_neo,
    gpt_neox,
    gpt_neox_japanese,
    gpt_swa,
    gptj,
    gptsan_japanese,
    graphormer,
    groupvit,
    herbert,
    hubert,
    ibert,
    imagegpt,
    informer,
    instructblip,
    jukebox,
    layoutlm,
    layoutlmva,
    layoutlmva,
    layoutxlm,
    led,
    levit,
    lilt,
    llama,
    longformer,
    longta,
    luke,
    lxmert,
    mam_aaa,
    marian,
    markuplm,
    maskaformer,
    maskformer,
    mbart,
    mbartaa,
    mega,
    megatron_bert,
    megatron_gpta,
    mgp_str,
    mluke,
    mobilebert,
    mobilenet_va,
    mobilenet_va,
    mobilevit,
    mobilevitva,
    mpnet,
    mra,
    mta,
    musicgen,
    mvp,
    nat,
    nezha,
    nllb,
    nllb_moe,
    nystromformer,
    oneformer,
    open_llama,
    openai,
    opt,
    owlvit,
    pegasus,
    pegasus_x,
    perceiver,
    phobert,
    pixastruct,
    plbart,
    poolformer,
    prophetnet,
    qdqbert,
    rag,
    realm,
    reformer,
    regnet,
    rembert,
    resnet,
    roberta,
    roberta_prelayernorm,
    roc_bert,
    roformer,
    rwkv,
    sam,
    segformer,
    sew,
    sew_d,
    speech_encoder_decoder,
    speech_to_text,
    speech_to_text_a,
    speechta,
    splinter,
    squeezebert,
    swiftformer,
    swin,
    swinasr,
    swinva,
    switch_transformers,
    ta,
    table_transformer,
    tapas,
    time_series_transformer,
    timesformer,
    timm_backbone,
    transfo_xl,
    trocr,
    tvlt,
    umta,
    unispeech,
    unispeech_sat,
    upernet,
    videomae,
    vilt,
    vision_encoder_decoder,
    vision_text_dual_encoder,
    visual_bert,
    vit,
    vit_hybrid,
    vit_mae,
    vit_msn,
    vivit,
    wavaveca,
    wavaveca_conformer,
    wavaveca_phoneme,
    wavaveca_with_lm,
    wavlm,
    whisper,
    x_clip,
    xglm,
    xlm,
    xlm_prophetnet,
    xlm_roberta,
    xlm_roberta_xl,
    xlnet,
    xmod,
    yolos,
    yoso,
)





