
    sg                     R    d dl mZmZ ddlmZ ddlmZ defdZdZ G d	 d
e      Z	y)    )ArgumentParser	Namespace   )logging   )BaseTransformersCLICommandargsc                     t        | 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_checkpointpytorch_dump_outputconfigfinetuning_task_name)r	   s    P/var/www/html/venv/lib/python3.12/site-packages/transformers/commands/convert.pyconvert_command_factoryr      s7     ++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            
       D    e Zd Zedefd       Zdededededef
dZd	 Zy
)r   parserc                 P   | j                  dd      }|j                  dt        dd       |j                  dt        dd	       |j                  d
t        dd       |j                  dt        dd       |j                  dt        dd       |j                  t               y)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.)typerequiredr   z--tf_checkpointz%TensorFlow checkpoint path or folder.z--pytorch_dump_outputz'Path to the PyTorch saved model output.z--config z"Configuration file path or folder.)r   defaultr   z--finetuning_task_nameNzEOptional fine-tuning task name if the TF model was a finetuned model.)func)
add_parseradd_argumentstrset_defaultsr   )r   train_parsers     r   register_subcommandz"ConvertCommand.register_subcommand'   s     ((v ) 
 	!!.sTP_!`!!C$=d 	" 	
 	!!##Cl 	" 	
 	!!*3Im!n!!$X	 	" 	
 	!!'>!?r   r   r   r   r   r   c                     t        j                  d      | _        | j                  j                  d|        || _        || _        || _        || _        || _        y )Nztransformers-cli/convertingzLoading model )	r   
get_logger_loggerinfo_model_type_tf_checkpoint_pytorch_dump_output_config_finetuning_task_name)selfr   r   r   r   r   r	   s          r   __init__zConvertCommand.__init__C   sW     ))*GHN:,78%+$7!%9"r   c                 6   | j                   dk(  r0	 ddlm}  || j
                  | j                  | j                         y | j                   dk(  r0	 ddlm}  || j
                  | j                  | j                         y | j                   dk(  r0	 ddl	m}  || j
                  | j                  | j                         y | j                   dk(  r0	 ddl
m}  || j
                  | j                  | j                         y | j                   dk(  r/ddlm}  || j
                  | j                  | j                         y | j                   d	k(  r0	 dd
lm}  || j
                  | j                  | j                         y | j                   dk(  r;	 ddlm}  || j
                  | j                  | j                  | j"                         y | j                   dk(  r$ddlm}  || j
                  | j                         y | j                   dk(  r$ddlm}  || j
                  | j                         y | j                   dk(  r/ddlm}  || j
                  | j                  | j                         y t1        d      # t        $ r t        t              w xY w# t        $ r t        t              w xY w# t        $ r t        t              w xY w# t        $ r t        t              w xY w# t        $ r t        t              w xY w# t        $ r t        t              w xY w)Nalbertr   ) convert_tf_checkpoint_to_pytorchbertfunnelt5gpt)$convert_openai_checkpoint_to_pytorchgpt2)"convert_gpt2_checkpoint_to_pytorchxlnet)#convert_xlnet_checkpoint_to_pytorchxlm)!convert_xlm_checkpoint_to_pytorchlxmert)$convert_lxmert_checkpoint_to_pytorchrembert)(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   ImportErrorIMPORT_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_pytorchr8   <models.xlnet.convert_xlnet_original_tf_checkpoint_to_pytorchr:   r,   =models.xlm.convert_xlm_original_pytorch_checkpoint_to_pytorchr<   >models.lxmert.convert_lxmert_original_tf_checkpoint_to_pytorchr>   7models.rembert.convert_rembert_tf_checkpoint_to_pytorchr@   
ValueError)r-   r1   r6   r8   r:   r<   r>   r@   s           r   runzConvertCommand.runU   s   x'8 -T-@-@$,,PTPiPij'8 -T-@-@$,,PTPiPij)8 -T-@-@$,,PTPiPij%8u -T-@-@$,,PTPiPij& 11D1DdllTXTmTmn'8 /t/B/BDLLRVRkRkl(8 0##T\\43L3LdNhNh & .d.A.A4C\C\]) 11D1DdF_F_`* 5T5H5H$,,X\XqXqrtuuU  8!"6778  8!"6778  8!"6778  8!"6778  8!"6778  8!"6778sG   I3 J J+ K K# 
K? 3JJ(+KK #K<?LN)	__name__
__module____qualname__staticmethodr   r#   r    r.   rN    r   r   r   r   &   sZ    @N @ @6:: : !	:
 : ":$Pvr   r   N)
argparser   r   utilsr   r   r   r   rC   r   rS   r   r   <module>rV      s5    /  ()  v/ vr   