
    +hj"                        S SK r S SKrS SKJr  S SKJr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.                  \R0                  \R2                  \R4                  \R6                  \R8                  \R:                  \R<                  \R>                  \R@                  \RB                  \RD                  S.r# " S	 S
5      r$g)    N)Path)OptionalUnion)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\\\	4   4S jj5       r
SS\\\	4   S\\   4S	 jjrS\\\R                  4   4S
 jr\\       SS\\\	4   S\\\\S4      S\\\S4      S\S\\   S\\   S\\   S\S   4S jj5       5       r\\   SS\\\	4   S\S\\   S\\   4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/james-whalen/.local/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pathc                     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)r(   providerr,   r-   s       r   
load_modelOnnxRuntimeModel.load_model?   sY     KKWX-H#!,d33 01##J\
 	
r   save_directory	file_namec                    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   r5   r6   r   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)osr(   isfiler   errormakedirsr@   )r   r5   r   s      r   save_pretrained OnnxRuntimeModel.save_pretrainedv   sT     77>>.))LL?>*::]^_
NT2 	n77r   model_idtokenrevisionforce_download	cache_dirr2   r,   zort.SessionOptionsc	           	         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 (`Union[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-   )r2   r,   r-   r   )repo_idfilenamerK   rL   rN   rM   r   r    )r
   rD   r(   isdirr   r3   r   as_posixpopr   parentname)clsrJ   rK   rL   rM   rN   r6   r2   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   )rJ   rL   rN   rM   rK   rR   )lenstrsplitrZ   )rX   rJ   rM   rK   rN   model_kwargsrL   s          r   from_pretrained OnnxRuntimeModel.from_pretrained   sg     s8}""3'(A-!)!4H## 
)
 
 	
r   )r   r   r   r   )NNN)NNFNNNN)TNN)__name__
__module____qualname____firstlineno__r   r&   staticmethodr   r_   r   r3   r   r@   rD   PathLikerH   classmethodr   boolrZ   rb   __static_attributes__rR   r   r   r   r   4   s   T, 
sDy) 
 
.uS$Y/? HUXM >8c2;;./8,  37/3$#'#'"&7;A*T	"A* dCo./A* 5d+,	A*
 A* C=A* C=A* 3-A* 34A*  A*F   $##'
T	"
 
 }	

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