L iRddlmZmZddlmZddlmZdefdZdZGd d eZ y ) )ArgumentParser Namespace)logging)BaseTransformersCLICommandargsct|j|j|j|j|j S)zx Factory function used to convert a model TF 1.0 checkpoint in a PyTorch checkpoint. Returns: ServeCommand )ConvertCommand model_type tf_checkpointpytorch_dump_outputconfigfinetuning_task_name)r s c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/transformers/commands/convert.pyconvert_command_factoryrs7  ++T-E-Et{{TXTmTm z transformers can only be used from the commandline to convert TensorFlow models in PyTorch, In that case, it requires TensorFlow to be installed. Please see https://www.tensorflow.org/install/ for installation instructions. c DeZdZedefdZdededededef dZd Zy ) r parsercP|jdd}|jdtdd|jdtdd |jd tdd |jd td d|jdtdd|jty)z Register this command to argparse so it's available for the transformer-cli Args: parser: Root parser to register command-specific arguments convertzcCLI tool to run convert model from original author checkpoints to Transformers PyTorch checkpoints.)helpz --model_typeTz Model's type.)typerequiredrz--tf_checkpointz%TensorFlow checkpoint path or folder.z--pytorch_dump_outputz'Path to the PyTorch saved model output.z--configz"Configuration file path or folder.)rdefaultrz--finetuning_task_nameNzEOptional fine-tuning task name if the TF model was a finetuned model.)func) add_parser add_argumentstr set_defaultsr)r train_parsers rregister_subcommandz"ConvertCommand.register_subcommand's(( v)  !!.sTP_!`!! C$=d "  !! ##Cl "  !!*3Im!n!! $X " !!'>!?rr r rrrctjd|_|jjd|||_||_||_||_||_y)Nztransformers/convertingzLoading model ) r get_logger_loggerinfo _model_type_tf_checkpoint_pytorch_dump_output_config_finetuning_task_name)selfr r rrrr s r__init__zConvertCommand.__init__CsW))*CD  N:,78%+$7! %9"rc6|jdk(r0 ddlm}||j |j |jy|jdk(r0 ddlm}||j |j |jy|jdk(r0 ddl m}||j |j |jy|jdk(r0 ddl m}||j |j |jy|jdk(r/ddl m }||j |j |jy|jd k(r0 dd l m}||j |j |jy|jd k(r; dd lm}||j |j |j|j"y|jd k(r$ddlm}||j |jy|jdk(r$ddlm}||j |jy|jdk(r/ddlm}||j |j |jyt1d#t$rttwxYw#t$rttwxYw#t$rttwxYw#t$rttwxYw#t$rttwxYw#t$rttwxYw)Nalbertr) convert_tf_checkpoint_to_pytorchbertfunnelt5gpt)$convert_openai_checkpoint_to_pytorchgpt2)"convert_gpt2_checkpoint_to_pytorchxlnet)#convert_xlnet_checkpoint_to_pytorchxlm)!convert_xlm_checkpoint_to_pytorchlxmert)$convert_lxmert_checkpoint_to_pytorchrembert)(convert_rembert_tf_checkpoint_to_pytorchzU--model_type should be selected in the list [bert, gpt, gpt2, t5, xlnet, xlm, lxmert])r(>models.albert.convert_albert_original_tf_checkpoint_to_pytorchr1 ImportErrorIMPORT_ERROR_MESSAGEr)r+r*:models.bert.convert_bert_original_tf_checkpoint_to_pytorch>models.funnel.convert_funnel_original_tf_checkpoint_to_pytorch6models.t5.convert_t5_original_tf_checkpoint_to_pytorch>models.openai.convert_openai_original_tf_checkpoint_to_pytorchr6:models.gpt2.convert_gpt2_original_tf_checkpoint_to_pytorchr8models.lxmert.convert_lxmert_original_tf_checkpoint_to_pytorchr>7models.rembert.convert_rembert_tf_checkpoint_to_pytorchr@ ValueError)r-r1r6r8r:r<r>r@s rrunzConvertCommand.runUs   x ' 8 -T-@-@$,,PTPiPi j    ' 8 -T-@-@$,,PTPiPi j    ) 8 -T-@-@$,,PTPiPi j    % 8u -T-@-@$,,PTPiPi j    &  11D1DdllTXTmTm n    ' 8 /t/B/BDLLRVRkRk l    ( 8 0##T\\43L3LdNhNh    &  .d.A.A4C\C\ ]    )  11D1DdF_F_ `    *  5T5H5H$,,X\XqXq rtu uU 8!"677 8 8!"677 8 8!"677 8 8!"677 8 8!"677 8 8!"677 8sGI3JJ+K K# K?3J J(+KK #K<?LN) __name__ __module__ __qualname__ staticmethodrr#r r.rNrrr r &sZ@N@@6:::! :  : " :$Pvrr N) argparserrutilsrrrrrCr rSrrrVs5/() v/vr