
    bi'                         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y)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                     | 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    ^/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/diffusers/commands/fp16_safetensors.pyconversion_command_factoryr   #   s;    ;	
 "$,,		4;O;OPP    c                   <    e Zd Zedefd       ZdededefdZd Z	y)	r   parserc                     | j                  d      }|j                  dt        d       |j                  ddd       |j                  d	dd
       |j                  ddd       |j                  t               y )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_subcommandz*FP16SafetensorsCommand.register_subcommand-   s    "--.@A&&g 	' 	

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

 	&&,F&Gr   r   r   r   c                     t        j                  d      | _        || _        d| | _        || _        || _        | j                  s| j
                  st        d      y y )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   sa    (()IJ %gY/	.##DII%c  -6#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        t        t        d
            }| j                  j!                  d| d       |j#                  | j                  | j$                  rt&        j(                  nt&        j*                        }|j-                  | j.                  | j0                  rdnd| j$                  rdnd        | j                  j!                  d| j.                   d       | j$                  r#t3        j2                  | j.                   d      }n.| j0                  r"t3        j2                  | j.                   d      }d| j$                   d| j0                   d}	g }
D ]<  }|
j5                   |dj7                  |j9                  d      dd        |             > d} || j                  |
|	|dd      j:                  }| j                  j!                  d| d       y # 1 sw Y   xY w)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   sI   ==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
" 	tD0chhtzzRUWXWYGZ>[mqrs	t
t 	 #LL!)1
 & 	 	,ZL:;U	> 	>s   4I44I>N)
__name__
__module____qualname__staticmethodr   r&   r#   boolr-   r`    r   r   r   r   ,   s=    HN H H( 4 $ 5<r   r   )__doc__rS   rJ   r   argparser   r   	importlibr   rE   rO   r   	packagingr   utilsr	    r   r   r   rf   r   r   <module>rm      sJ   
    . #   +   %QY QX<4 X<r   