
    g                     b    d dl Z d dlmZmZ ddlmZ ddlmZ dZdefd	Z	 G d
 de          Z
dS )    N)ArgumentParser	Namespace   )logging   )BaseTransformersCLICommandg-C6
?argsc           
      ~    t          | j        | j        | j        | j        | j        | j        | j        | j                  S )z~
    Factory function used to convert a model PyTorch checkpoint in a TensorFlow 2 checkpoint.

    Returns: ServeCommand
    )	PTtoTFCommand
model_name	local_dir	max_errornew_weightsno_prpushextra_commit_descriptionoverride_model_class)r	   s    Z/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/commands/pt_to_tf.pyconvert_command_factoryr      sA     
	%!	 	 	    c                   X    e Zd Zedefd            Zdedededededed	ed
efdZ	d Z
dS )r   parserc                 B   |                      dd          }|                    dt          dd           |                    dt          d	d
           |                    dt          t          dt           d           |                    ddd           |                    ddd           |                    ddd           |                    dt          d	d           |                    dt          dd           |                    t                     dS )z
        Register this command to argparse so it's available for the transformer-cli

        Args:
            parser: Root parser to register command-specific arguments
        zpt-to-tfzCLI tool to run convert a transformers model from a PyTorch checkpoint to a TensorFlow checkpoint. Can also be used to validate existing weights without opening PRs, with --no-pr.)helpz--model-nameTzAThe model name, including owner/organization, as seen on the hub.)typerequiredr   z--local-dir zOOptional local directory of the model repository. Defaults to /tmp/{model_name})r   defaultr   z--max-errorz%Maximum error tolerance. Defaults to z4. This flag should be avoided, use at your own risk.z--new-weights
store_truezKOptional flag to create new TensorFlow weights, even if they already exist.)actionr   z--no-prz6Optional flag to NOT open a PR with converted weights.z--pushzKOptional flag to push the weights directly to `main` (requires permissions)z--extra-commit-descriptionzXOptional additional commit description to use when opening a PR (e.g. to tag the owner).z--override-model-classNzIf you think you know better than the auto-detector, you can specify the model class here. Can be either an AutoModel class or a specific model class like BertForSequenceClassification.)func)
add_parseradd_argumentstrfloat	MAX_ERRORset_defaultsr   )r   train_parsers     r   register_subcommandz!PTtoTFCommand.register_subcommand,   s    ((d ) 
 
 	!!T	 	" 	
 	
 	
 	!!b	 	" 	
 	
 	
 	!!w	www 	" 	
 	
 	
 	!!^ 	" 	
 	
 	

 	!!l1i 	" 	
 	
 	
 	!!^ 	" 	
 	
 	

 	!!(k	 	" 	
 	
 	
 	!!$m	 	" 	
 	
 	
 	!!'>!?????r   r   r   r   r   r   r   r   r   c	                     t          j        d          | _        || _        |r|nt          j                            d|          | _        || _        || _	        || _
        || _        || _        || _        d S )Nztransformers-cli/pt_to_tfz/tmp)r   
get_logger_logger_model_nameospathjoin
_local_dir
_max_error_new_weights_no_pr_push_extra_commit_description_override_model_class)
selfr   r   r   r   r   r   r   r   r	   s
             r   __init__zPTtoTFCommand.__init__k   sr     )*EFF%'0V))bgll6:6V6V#'
)A&%9"""r   c                      t          d          )Na]  

Converting PyTorch weights to TensorFlow weights was removed in v4.43. Instead, we recommend that you convert PyTorch weights to Safetensors, an improved format that can be loaded by any framework, including TensorFlow. For more information, please see the Safetensors conversion guide: https://huggingface.co/docs/safetensors/en/convert-weights

)NotImplementedError)r8   s    r   runzPTtoTFCommand.run   s    !M
 
 	
r   N)__name__
__module____qualname__staticmethodr   r)   r$   r%   boolr9   r<    r   r   r   r   +   s        <@N <@ <@ <@ \<@|:: : 	:
 : : : #&: ": : : :,
 
 
 
 
r   r   )r.   argparser   r   utilsr   r   r   r&   r   r   rB   r   r   <module>rE      s    
			 . . . . . . . .       ( ( ( ( ( ( 	)    $^
 ^
 ^
 ^
 ^
. ^
 ^
 ^
 ^
 ^
r   