
    
3j "                       S SK Jr  S SKrS SKrS SKJr  S SKrS SKJ	r	  S SK
Jr  SSKJrJrJrJr  \" 5       (       a  S SKr\R&                  " \5      r\R,                  \R.                  \R0                  \R2                  \R4                  \R6                  \R8                  \R:                  \R<                  \R>                  \R@                  \RB                  S.r" " S	 S
5      r#g)    )annotationsN)Path)hf_hub_download)validate_hf_hub_args   )ONNX_EXTERNAL_WEIGHTS_NAMEONNX_WEIGHTS_NAMEis_onnx_availablelogging)ztensor(bool)ztensor(int8)ztensor(uint8)ztensor(int16)ztensor(uint16)ztensor(int32)ztensor(uint32)ztensor(int64)ztensor(uint64)ztensor(float16)ztensor(float)ztensor(double)c                      \ rS rSrSS jrS r\SSS jj5       rSSS jjr  SS jr	\
\       S               SS jj5       5       r\
\   S       SS	 jj5       5       rS
rg)OnnxRuntimeModel4   Nc                    [         R                  S5        Xl        UR                  SS 5      U l        UR                  S[
        5      U l        g )NzL`diffusers.OnnxRuntimeModel` is experimental and might change in the future.model_save_dirlatest_model_name)loggerinfomodelgetr   r	   r   )selfr   kwargss      X/home/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/pipelines/onnx_utils.py__init__OnnxRuntimeModel.__init__5   s=    bc
$jj)94@!',?AR!S    c                    UR                  5        VVs0 s H  u  p#U[        R                  " U5      _M     nnnU R                  R	                  S U5      $ s  snnf N)itemsnparrayr   run)r   r   kvinputss        r   __call__OnnxRuntimeModel.__call__;   sD    -3\\^<^TQ!RXXa[.^<zz~~dF++ =s   #Ac                    Uc  [         R                  S5        SnUc  / nO[        U[        5      (       d  U/n[        R
                  " X/X#S9$ )a=  
Loads an ONNX Inference session with an ExecutionProvider. Default provider is `CPUExecutionProvider`

Arguments:
    path (`str` or `Path`):
        Directory from which to load
    provider(`str`, *optional*):
        Onnxruntime execution provider to use for loading the model, defaults to `CPUExecutionProvider`
z=No onnxruntime provider specified, using CPUExecutionProviderCPUExecutionProvider)	providerssess_optionsprovider_options)r   r   
isinstancelistortInferenceSession)pathproviderr*   r+   s       r   
load_modelOnnxRuntimeModel.load_model?   sY     KKWX-H#!,d33 01##J\
 	
r   c                   Ub  UO[         nU R                  R                  U R                  5      n[	        U5      R                  U5      n [
        R                  " XV5        U R                  R                  [        5      nUR                  5       (       a6  [	        U5      R                  [        5      n [
        R                  " XV5        gg! [
        R                   a     Nf = f! [
        R                   a     gf = f)a  
Save a model and its configuration file to a directory, so that it can be re-loaded using the
[`~optimum.onnxruntime.modeling_ort.ORTModel.from_pretrained`] class method. It will always save the
latest_model_name.

Arguments:
    save_directory (`str` or `Path`):
        Directory where to save the model file.
    file_name(`str`, *optional*):
        Overwrites the default model file name from `"model.onnx"` to `file_name`. This allows you to save the
        model with a different name.
N)
r	   r   joinpathr   r   shutilcopyfileSameFileErrorr   exists)r   save_directory	file_namer   model_file_namesrc_pathdst_paths          r   _save_pretrained!OnnxRuntimeModel._save_pretrainedW   s     (1'<)BS&&//0F0FG'00A	OOH/
 &&//0JK??N+445OPH3  ## 		 '' s$   C 5C' C$#C$'C>=C>c                    [         R                  R                  U5      (       a  [        R	                  SU S35        g[         R
                  " USS9  U R                  " U40 UD6  g)z
Save a model to a directory, so that it can be re-loaded using the [`~OnnxModel.from_pretrained`] class
method.:

Arguments:
    save_directory (`str` or `os.PathLike`):
        Directory to which to save. Will be created if it doesn't exist.
zProvided path (z#) should be a directory, not a fileNT)exist_ok)osr0   isfiler   errormakedirsr?   )r   r:   r   s      r   save_pretrained OnnxRuntimeModel.save_pretrainedv   sT     77>>.))LL?>*::]^_
NT2 	n77r   c	           	        Ub  UO[         n
[        R                  R                  U5      (       aK  [        R                  [        X5      R                  5       UUU	R                  S5      S9n[        U5      U	S'   Oc[        UU
UUUUS9n[        U5      R                  U	S'   [        U5      R                  U	S'   [        R                  UUUU	R                  S5      S9nU " SSU0U	D6$ )a  
Load a model from a directory or the HF Hub.

Arguments:
    model_id (`str` or `Path`):
        Directory from which to load
    token (`str` or `bool`):
        Is needed to load models from a private or gated repository
    revision (`str`):
        Revision is the specific model version to use. It can be a branch name, a tag name, or a commit id
    cache_dir (`str | Path`, *optional*):
        Path to a directory in which a downloaded pretrained model configuration should be cached if the
        standard cache should not be used.
    force_download (`bool`, *optional*, defaults to `False`):
        Whether or not to force the (re-)download of the model weights and configuration files, overriding the
        cached versions if they exist.
    file_name(`str`):
        Overwrites the default model file name from `"model.onnx"` to `file_name`. This allows you to load
        different model files from the same repository or directory.
    provider(`str`):
        The ONNX runtime provider, e.g. `CPUExecutionProvider` or `CUDAExecutionProvider`.
    kwargs (`Dict`, *optional*):
        kwargs will be passed to the model during initialization
r+   )r1   r*   r+   r   )repo_idfilenametokenrevision	cache_dirforce_downloadr   r    )r	   rC   r0   isdirr   r2   r   as_posixpopr   parentname)clsmodel_idrL   rM   rO   rN   r;   r1   r*   r   r<   r   model_cache_paths                r   _from_pretrained!OnnxRuntimeModel._from_pretrained   s    L (1'<)BS77==""$//X/88:!)!',>!?	 0 E (,H~F#$  / (!#-  (,,<'='D'DF#$*./?*@*E*EF&'$// !)!',>!?	 0 E ))&))r   c           	         S n[        [        U5      R                  S5      5      S:X  a  UR                  S5      u  pU R                  " SUUUUUS.UD6$ )N@r   )rW   rM   rN   rO   rL   rP   )lenstrsplitrY   )rV   rW   rO   rL   rN   model_kwargsrM   s          r   from_pretrained OnnxRuntimeModel.from_pretrained   sg     s8}""3'(A-!)!4H## 
)
 
 	
r   )r   r   r   r   )NNN)r0   
str | Path)r:   rc   r;   
str | None)r:   zstr | os.PathLike)NNFNNNN)rW   rc   rL   zbool | str | None | NonerM   zstr | None | NonerO   boolrN   rd   r;   rd   r1   rd   r*   z'ort.SessionOptions' | None)TNN)rW   rc   rO   re   rL   rd   rN   rd   )__name__
__module____qualname____firstlineno__r   r%   staticmethodr2   r?   rG   classmethodr   rY   ra   __static_attributes__rP   r   r   r   r   4   s   T, 
 
.>8)8,  +/&*$ $ $#48A*A* (A* $	A*
 A* A* A* A* 2A*  A*F   $  $

 
 	

 
  
r   r   )$
__future__r   rC   r6   pathlibr   numpyr   huggingface_hubr   huggingface_hub.utilsr   utilsr   r	   r
   r   onnxruntimer.   
get_loggerrf   r   bool_int8uint8int16uint16int32uint32int64uint64float16float32float64ORT_TO_NP_TYPEr   rP   r   r   <module>r      s   " # 	    + 6 ] ]  
		H	% HHGGXXXXiiXXiiXXiizzZZjj r
 r
r   