
    wi/                         d Z ddlZddlZddlZddlmZmZ ddlmZ ddl	Z	ddl
Z
ddl	mZ ddlmZ ddlmZ d	d
lmZ defdZ G d de          ZdS )zd
Usage example:
    diffusers-cli fp16_safetensors --ckpt_id=openai/shap-e --fp16 --use_safetensors
    N)ArgumentParser	Namespace)import_module)hf_hub_download)version   )logging   )BaseDiffusersCLICommandargsc                 x    | j         rt          j        d           t          | j        | j        | j                  S )NzThe `--use_auth_token` flag is deprecated and will be removed in a future version. Authentication is now handled automatically if user is logged in.)use_auth_tokenwarningswarnFP16SafetensorsCommandckpt_idfp16use_safetensors)r   s    s/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/diffusers/commands/fp16_safetensors.pyconversion_command_factoryr   #   sA     
;	
 	
 	
 "$,	4;OPPP    c                   D    e Zd Zedefd            ZdededefdZd Z	dS )	r   parserc                 0   |                      d          }|                    dt          d           |                    ddd           |                    d	dd
           |                    ddd           |                    t                     d S )Nfp16_safetensorsz	--ckpt_idzTRepo id of the checkpoints on which to run the conversion. Example: 'openai/shap-e'.)typehelpz--fp16
store_truez/If serializing the variables in FP16 precision.)actionr   z--use_safetensorsz)If serializing in the safetensors format.z--use_auth_tokenzvWhen working with checkpoints having private visibility. When used `huggingface-cli login` needs to be run beforehand.)func)
add_parseradd_argumentstrset_defaultsr   )r   conversion_parsers     r   register_subcommandz*FP16SafetensorsCommand.register_subcommand-   s    "--.@AA&&g 	' 	
 	
 	

 	&&\0a 	' 	
 	
 	
 	&&;f 	' 	
 	
 	
 	&& J 	' 	
 	
 	

 	&&,F&GGGGGr   r   r   r   c                     t          j        d          | _        || _        d| | _        || _        || _        | j        s| j        st          d          d S d S )Nzdiffusers-cli/fp16_safetensorsz/tmp/zQWhen `use_safetensors` and `fp16` both are False, then this command is of no use.)r	   
get_loggerloggerr   local_ckpt_dirr   r   NotImplementedError)selfr   r   r   s       r   __init__zFP16SafetensorsCommand.__init__B   sx    ()IJJ/g//	.# 	DI 	%c  	 	 	 	r   c           
         t          j        t          j                  t          j        d          k     rt	          d          ddlm} ddlm} t          | j	        d          }t          |d          5 }t          j        |          d	         }d d d            n# 1 swxY w Y   t          t          d
          |          }| j                            d| d           |                    | j	        | j        rt&          j        nt&          j                  }|                    | j        | j        rdnd| j        rdnd            | j                            d| j         d           | j        rt3          j        | j         d          }n#| j        rt3          j        | j         d          }d| j         d| j         d}	g }
|D ]P}|
                     |d                    |                    d          dd                    |                     Qd} || j	        |
|	|dd          j        }| j                            d| d           d S )Nz0.9.0zrThe huggingface_hub version must be >= 0.9.0 to use this command. Please update your huggingface_hub installation.r   )create_commit)CommitOperationAddzmodel_index.json)repo_idfilenamer_class_name	diffuserszPipeline class imported: .)torch_dtypeTFr   )safe_serializationvariantzPipeline locally saved to z/*/*.fp16.*z/*/*.safetensorszSerialize variables with FP16: z and safetensors: /   )path_in_repopath_or_fileobjzVariables converted by the [`diffusers`' `fp16_safetensors` CLI](https://github.com/huggingface/diffusers/blob/main/src/diffusers/commands/fp16_safetensors.py).model)r1   
operationscommit_messagecommit_description	repo_type	create_przPR created here: )r   parsehuggingface_hub__version__ImportErrorr/   huggingface_hub._commit_apir0   r   r   openjsonloadgetattrr   r)   infofrom_pretrainedr   torchfloat16float32save_pretrainedr*   r   globappendjoinsplitpr_url)r,   r/   r0   model_indexfpipeline_class_namepipeline_classpipelinemodified_pathsr@   r?   pathrA   
hub_pr_urls                 r   runzFP16SafetensorsCommand.runO   s   =455g8N8NNN!  
 655555FFFFFF%dlEWXXX+s## 	>q"&)A,,}"=	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> {!;!;=PQQK5HKKKLLL "11Lty&Semmem 2 
 
 	  '+';Ftt"i1FFT 	! 	
 	
 	

 	Ld6ILLLMMM 9 	Q!Y$*='J'J'JKKNN! 	Q!Y$*='O'O'OPPN p49ooX\Xlooo
" 	t 	tD00chhtzzRUWXWYWYGZ>[>[mqrrrsssst 	 #]L!)1
 
 
  	 	:Z:::;;;;;s   6BB!$B!N)
__name__
__module____qualname__staticmethodr   r&   r#   boolr-   r`    r   r   r   r   ,   sv        HN H H H \H( 4 $    5< 5< 5< 5< 5<r   r   )__doc__rS   rJ   r   argparser   r   	importlibr   rE   rO   r   	packagingr   utilsr	    r   r   r   rf   r   r   <module>rm      s   
    . . . . . . . . # # # # # #      + + + + + +             % % % % % %QY Q Q Q QX< X< X< X< X<4 X< X< X< X< X<r   