
    +h'                         S r SSKrSSKrSSKrSSKJrJr  SSKJr  SSK	r	SSK
r
SSK	Jr  SSKJr  SSKJr  S	S
KJr  S\4S jr " S S\5      rg)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                     U R                   (       a  [        R                  " S5        [        U R                  U R
                  U R                  5      $ )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    ]/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/commands/fp16_safetensors.pyconversion_command_factoryr   #   s;    ;	
 "$,,		4;O;OPP    c                   H    \ rS rSr\S\4S j5       rS\S\S\4S jr	S r
S	rg
)r   ,   parserc                     U R                  S5      nUR                  S[        SS9  UR                  SSSS9  UR                  S	SS
S9  UR                  SSSS9  UR                  [        S9  g )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_tokenznWhen working with checkpoints having private visibility. When used `hf auth login` needs to be run beforehand.)func)
add_parseradd_argumentstrset_defaultsr   )r   conversion_parsers     r   register_subcommand*FP16SafetensorsCommand.register_subcommand-   s    "--.@A&&g 	' 	

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

 	&&,F&Gr   r   r   r   c                     [         R                  " S5      U l        Xl        SU 3U l        X l        X0l        U R                  (       d  U R
                  (       d  [        S5      eg g )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__FP16SafetensorsCommand.__init__B   s[    (()IJ %gY/	.##DII%c  -6#r   c           
      0   [         R                  " [        R                  5      [         R                  " S5      :  a  [	        S5      eSSKJn  SSKJn  [        U R                  SS9n[        US5       n[        R                  " U5      S	   nS S S 5        [        [        S
5      W5      nU R                  R!                  SU S35        UR#                  U R                  U R$                  (       a  [&        R(                  O[&        R*                  S9nUR-                  U R.                  U R0                  (       a  SOSU R$                  (       a  SOS S9  U R                  R!                  SU R.                   S35        U R$                  (       a$  [2        R2                  " U R.                   S35      nO4U R0                  (       a#  [2        R2                  " U R.                   S35      nSU R$                   SU R0                   S3n	/ n
W H:  nU
R5                  U" SR7                  UR9                  S5      SS  5      US95        M<     SnU" U R                  U
U	USSS9R:                  nU R                  R!                  SU S35        g ! , (       d  f       GN= f)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)r4   
operationscommit_messagecommit_description	repo_type	create_przPR created here: )r   parsehuggingface_hub__version__ImportErrorr2   huggingface_hub._commit_apir3   r   r   openjsonloadgetattrr   r+   infofrom_pretrainedr   torchfloat16float32save_pretrainedr,   r   globappendjoinsplitpr_url)r.   r2   r3   model_indexfpipeline_class_namepipeline_classpipelinemodified_pathsrC   rB   pathrD   
hub_pr_urls                 r   runFP16SafetensorsCommand.runO   s;   ==445g8NN! 
 6F%dllEWX+s#q"&))A,}"= $ {!;=PQ45H4IKL "11LLtyyemmemm 2 
 	  '+';';t"iiFT 	! 	

 	5d6I6I5J!LM 99!YY$*=*=)>k'JKN!!!YY$*=*=)>>N'OPN ;499+EWX\XlXlWmmno
"D0chhtzzRUWXWYGZ>[mqrs #
t 	 #LL!)1
 & 	 	,ZL:;U $#s   4J
J)r   r   r,   r+   r   N)__name__
__module____qualname____firstlineno__staticmethodr   r'   r$   boolr/   rc   __static_attributes__ r   r   r   r   ,   s=    HN H H( 4 $ 5<r   r   )__doc__rV   rM   r   argparser   r   	importlibr   rH   rR   r   	packagingr   utilsr	    r   r   r   rl   r   r   <module>rs      sJ   
    . #   +   %QY QX<4 X<r   