Ë
    cQêj;S  ã                   ó  — 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Zd dl	Z	d dl
mZ d dlmZmZ eeeee   z  f   Z ej(                  e«      Z G d„ d«      Z G d	„ d
«      Z G d„ d«      Z G d„ de«      Z G d„ d«      Zy)é    N)ÚOrderedDict)ÚMapping)ÚAny)ÚTensorProto)ÚInferenceSessionÚ
RunOptionsc                   ón  — e Zd Zedededefd„«       Zededefd„«       Zedefd„«       Zedefd„«       Z	edede
eef   fd	„«       Zedefd
„«       Zedej                  fd„«       Zedej                  fd„«       Zedede
eej                  f   fd„«       Zedede
eej                  f   fd„«       Zy)Ú
TypeHelperÚort_sessionÚnameÚreturnc                 óœ   — t        | j                  «       «      D ]"  \  }}|j                  |k(  sŒ|j                  c S  t	        d|› d�«      ‚)Nzinput name ú
 not found)Ú	enumerateÚ
get_inputsr   ÚtypeÚ
ValueError)r   r   Ú_iÚinputs       úo/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/onnxruntime/transformers/io_binding_helper.pyÚget_input_typezTypeHelper.get_input_type   sO   € ä" ;×#9Ñ#9Ó#;Ó<ò 	"‰IˆB�Ø�z‰z˜TÓ!Ø—z‘zÒ!ð	"ô ˜; t f¨JÐ7Ó8Ð8ó    c                 óœ   — t        | j                  «       «      D ]"  \  }}|j                  |k(  sŒ|j                  c S  t	        d|› d�«      ‚)Nzoutput name r   )r   Úget_outputsr   r   r   )r   r   r   Úoutputs       r   Úget_output_typezTypeHelper.get_output_type   sO   € ä# K×$;Ñ$;Ó$=Ó>ò 	#‰JˆB�Ø�{‰{˜dÓ"Ø—{‘{Ò"ð	#ô ˜<¨ v¨ZÐ8Ó9Ð9r   Úort_typec                 óÆ  — t         j                  t         j                  t         j                  t         j                  t
        t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  dœ}| |vrt        | › d�«      ‚||    S )N)útensor(int64)útensor(int32)útensor(float)útensor(float16)útensor(bool)útensor(uint8)útensor(int8)útensor(double)útensor(int16)útensor(uint16)útensor(uint32)útensor(uint64)útensor(complex64)útensor(complex128)ú not found in map)ÚnumpyÚint64Úint32Úfloat32Úfloat16ÚboolÚuint8Úint8Úfloat64Úint16Úuint16Úuint32Úuint64Ú	complex64Ú
complex128r   )r   Úort_type_to_numpy_type_maps     r   Úort_type_to_numpy_typez!TypeHelper.ort_type_to_numpy_type#   s•   € ô #Ÿ[™[Ü"Ÿ[™[Ü"Ÿ]™]Ü$Ÿ}™}Ü Ü"Ÿ[™[Ü!ŸJ™JÜ#Ÿm™mÜ"Ÿ[™[Ü#Ÿl™lÜ#Ÿl™lÜ#Ÿl™lÜ!&§¡Ü"'×"2Ñ"2ñ&
Ð"ð  Ð5Ñ5Ü ˜zÐ):Ð;Ó<Ð<à)¨(Ñ3Ð3r   c                 óô  — i dt         j                  “dt         j                  “dt         j                  “dt         j                  “dt         j
                  “dt         j                  “dt         j                  “dt         j                  “d	t         j                  “d
t         j                  “dt         j                  “dt         j                  “dt         j                  “dt         j                  “dt         j                  “dt         j                   “dt         j"                  “t         j$                  t         j&                  t         j(                  t         j*                  dœ¥}| |vrt-        | › d�«      ‚||    S )Nr   r    r!   r"   útensor(bfloat16)r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   útensor(float8e4m3fn)útensor(float8e4m3fnuz))útensor(float8e5m2)útensor(float8e5m2fnuz)útensor(int4)útensor(uint4)r-   )Útorchr/   r0   r1   r2   Úbfloat16r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   Úfloat8_e4m3fnÚfloat8_e4m3fnuzÚfloat8_e5m2Úfloat8_e5m2fnuzÚint4Úuint4r   )r   Úort_type_to_torch_type_maps     r   Úort_type_to_torch_typez!TypeHelper.ort_type_to_torch_type:   sl  € ð&
ØœUŸ[™[ð&
àœUŸ[™[ð&
ð œUŸ]™]ð&
ð œuŸ}™}ð	&
ð
 ¤§¡ð&
ð œEŸJ™Jð&
ð œUŸ[™[ð&
ð œEŸJ™Jð&
ð œeŸm™mð&
ð œUŸ[™[ð&
ð œeŸl™lð&
ð œeŸl™lð&
ð œeŸl™lð&
ð  ¤§¡ð&
ð !¤%×"2Ñ"2ð&
ð  #¤E×$7Ñ$7ð!&
ð" %¤e×&;Ñ&;ð#&
ô$ #(×"3Ñ"3Ü&+×&;Ñ&;Ü!ŸJ™JÜ"Ÿ[™[ò+&
Ð"ð. Ð5Ñ5Ü ˜zÐ):Ð;Ó<Ð<à)¨(Ñ3Ð3r   c                 ó  — i }| j                  «       D ].  }t        j                  |j                  «      ||j                  <   Œ0 | j                  «       D ].  }t        j                  |j                  «      ||j                  <   Œ0 |S )z9Create a mapping from input/output name to onnx data type)r   r
   Úort_type_to_onnx_typer   r   r   )r   Úname_to_onnx_typer   r   s       r   Úget_io_onnx_type_mapzTypeHelper.get_io_onnx_type_mapX   s‚   € ð ÐØ ×+Ñ+Ó-ò 	YˆEÜ,6×,LÑ,LÈUÏZÉZÓ,XÐ˜eŸj™jÒ)ð	Yð "×-Ñ-Ó/ò 	[ˆFÜ-7×-MÑ-MÈfÏkÉkÓ-ZÐ˜fŸk™kÒ*ð	[à Ð r   c                 ó0  — i dt         j                  “dt         j                  “dt         j                  “dt         j                  “dt         j
                  “dt         j                  “dt         j                  “dt         j                  “d	t         j                  “d
t         j                  “dt         j                  “dt         j                  “dt         j                  “dt         j                  “dt         j                  “dt         j                   “dt         j"                  “t         j$                  t         j&                  t         j(                  t         j*                  t         j,                  t         j.                  dœ¥}| |vrt1        | › d�«      ‚||    S )Nr   r    r!   r"   r@   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   rA   rB   )rC   rD   ztensor(float4e2m1)rE   rF   ztensor(string)r-   )r   ÚINT64ÚINT32ÚFLOATÚFLOAT16ÚBFLOAT16ÚBOOLÚUINT8ÚINT8ÚDOUBLEÚINT16ÚUINT16ÚUINT32ÚUINT64Ú	COMPLEX64Ú
COMPLEX128ÚFLOAT8E4M3FNÚFLOAT8E4M3FNUZÚ
FLOAT8E5M2ÚFLOAT8E5M2FNUZÚ
FLOAT4E2M1ÚINT4ÚUINT4ÚSTRINGr   )r   Úort_type_to_onnx_type_maps     r   rR   z TypeHelper.ort_type_to_onnx_typec   sž  € ð%
Øœ[×.Ñ.ð%
àœ[×.Ñ.ð%
ð œ[×.Ñ.ð%
ð œ{×2Ñ2ð	%
ð
 ¤× 4Ñ 4ð%
ð œK×,Ñ,ð%
ð œ[×.Ñ.ð%
ð œK×,Ñ,ð%
ð œk×0Ñ0ð%
ð œ[×.Ñ.ð%
ð œk×0Ñ0ð%
ð œk×0Ñ0ð%
ð œk×0Ñ0ð%
ð  ¤×!6Ñ!6ð%
ð !¤+×"8Ñ"8ð%
ð  #¤K×$<Ñ$<ð!%
ð" %¤k×&@Ñ&@ð#%
ô$ #.×"8Ñ"8Ü&1×&@Ñ&@Ü"-×"8Ñ"8Ü'×,Ñ,Ü(×.Ñ.Ü)×0Ñ0ò/%
Ð!ð2 Ð4Ñ4Ü ˜zÐ):Ð;Ó<Ð<à(¨Ñ2Ð2r   Ú
numpy_typec                 óh  — t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j
                  t        j
                  t        t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  i}| |vrt!        | › d�«      ‚||    S ©Nr-   )r.   r/   rG   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r   )rn   Únumpy_type_to_torch_type_maps     r   Únumpy_type_to_torch_typez#TypeHelper.numpy_type_to_torch_typeƒ   së   € ô �K‰KœŸ™Ü�K‰KœŸ™Ü�M‰Mœ5Ÿ=™=Ü�M‰Mœ5Ÿ=™=Ü”%—*‘*Ü�K‰KœŸ™Ü�J‰JœŸ
™
Ü�M‰Mœ5Ÿ=™=Ü�K‰KœŸ™Ü�L‰Lœ%Ÿ,™,Ü�L‰Lœ%Ÿ,™,Ü�L‰Lœ%Ÿ,™,Ü�O‰OœUŸ_™_Ü×Ñœe×.Ñ.ð(
Ð$ð" Ð9Ñ9Ü 
˜|Ð+<Ð=Ó>Ð>à+¨JÑ7Ð7r   Ú
torch_typec                 óh  — t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j
                  t        j
                  t         j                  t        t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  t         j                  t        j                  i}| |vrt!        | › d�«      ‚||    S rp   )rG   r/   r.   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r   )rs   Útorch_type_to_numpy_type_maps     r   Útorch_type_to_numpy_typez#TypeHelper.torch_type_to_numpy_type›   së   € ô �K‰KœŸ™Ü�K‰KœŸ™Ü�M‰Mœ5Ÿ=™=Ü�M‰Mœ5Ÿ=™=Ü�J‰JœÜ�K‰KœŸ™Ü�J‰JœŸ
™
Ü�M‰Mœ5Ÿ=™=Ü�K‰KœŸ™Ü�L‰Lœ%Ÿ,™,Ü�L‰Lœ%Ÿ,™,Ü�L‰Lœ%Ÿ,™,Ü�O‰OœUŸ_™_Ü×Ñœe×.Ñ.ð(
Ð$ð" Ð9Ñ9Ü 
˜|Ð+<Ð=Ó>Ð>à+¨JÑ7Ð7r   c                 ó  — i }| j                  «       D ].  }t        j                  |j                  «      ||j                  <   Œ0 | j                  «       D ].  }t        j                  |j                  «      ||j                  <   Œ0 |S )z:Create a mapping from input/output name to numpy data type)r   r
   r>   r   r   r   )r   Úname_to_numpy_typer   r   s       r   Úget_io_numpy_type_mapz TypeHelper.get_io_numpy_type_map³   ó…   € ð  ÐØ ×+Ñ+Ó-ò 	[ˆEÜ-7×-NÑ-NÈuÏzÉzÓ-ZÐ˜uŸz™zÒ*ð	[ð "×-Ñ-Ó/ò 	]ˆFÜ.8×.OÑ.OÐPV×P[ÑP[Ó.\Ð˜vŸ{™{Ò+ð	]à!Ð!r   c                 ó  — i }| j                  «       D ].  }t        j                  |j                  «      ||j                  <   Œ0 | j                  «       D ].  }t        j                  |j                  «      ||j                  <   Œ0 |S )z:Create a mapping from input/output name to torch data type)r   r
   rP   r   r   r   )r   Úname_to_torch_typer   r   s       r   Úget_io_torch_type_mapz TypeHelper.get_io_torch_type_map¾   rz   r   N)Ú__name__Ú
__module__Ú__qualname__Ústaticmethodr   Ústrr   r   r>   rP   ÚdictÚintrT   rR   r.   Údtyperr   rG   rv   ry   r}   © r   r   r
   r
      sh  „ Øð9Ð$4ð 9¸Cð 9ÀCò 9ó ð9ð ð:¨3ð :°3ò :ó ð:ð ð4¨ò 4ó ð4ð, ð4¨ò 4ó ð4ð: ð!Ð*:ð !¸tÀCÈÀH¹~ò !ó ð!ð ð3¨ò 3ó ð3ð> ð8¨U¯[©[ò 8ó ð8ð. ð8¨U¯[©[ò 8ó ð8ð. ð"Ð+;ð "ÀÀSÈ%Ï+É+ÐEUÑ@Vò "ó ð"ð ð"Ð+;ð "ÀÀSÈ%Ï+É+ÐEUÑ@Vò "ó ñ"r   r
   c            
       ó¬   — e Zd Zedefd„«       Zedej                  dej                  dej                  deej                     fd„«       Z	ed
d„«       Z
y	)ÚIOBindingHelperr   c                 óì   — i }|j                  «       D ]^  \  }}t        j                  | |«      }t        j                  |«      }t	        j
                  t        j                  |«      ||¬«      ||<   Œ` |S )zpReturns a dictionary of output name as key, and 1D tensor as value. The tensor has enough space for given shape.)r…   Údevice)Úitemsr
   r   rP   rG   Úemptyr.   Úprod)r   Úoutput_shapesrŠ   Úoutput_buffersr   Úshaper   rs   s           r   Úget_output_buffersz"IOBindingHelper.get_output_buffersË   sr   € ð ˆØ(×.Ñ.Ó0ò 	c‰KˆD�%Ü!×1Ñ1°+¸tÓDˆHÜ#×:Ñ:¸8ÓDˆJÜ#(§;¡;¬u¯z©z¸%Ó/@È
Ð[aÔ#bˆN˜4Ò ð	cð Ðr   Ú	input_idsÚposition_idsÚattention_maskÚpastc                 ó4  — t         j                  | «      }| j                  «       }|j                  «       sJ ‚|j	                  d|j
                  j                  d|d   t        |j                  «       «      |j                  «       «       |�”t        |«      D ]†  \  }	}
|
j                  «       sJ ‚|
j                  «       }|dk(  r|j                  «       }|j	                  d|	› �|
j
                  j                  d|d|	› �   t        |
j                  «       «      |«       Œˆ |�d|j                  «       sJ ‚|j	                  d|j
                  j                  d|d   t        |j                  «       «      |j                  «       «       |�d|j                  «       sJ ‚|j	                  d|j
                  j                  d|d   t        |j                  «       «      |j                  «       «       | j                  «       D ]™  }|j                  }||   }t        j                  |› d|j
                  j                  › dt        |j                  «       «      › �«       |j                  ||j
                  j                  d||   ||   |j                  «       «       Œ› |S )zdIO binding for a session: bind inputs (input_ids, position_ids, attention_mask, past_*) and outputs.r’   r   Úpast_r”   r“   z device type=z shape=)r
   rT   Ú
io_bindingÚis_contiguousÚ
bind_inputrŠ   r   ÚlistÚsizeÚdata_ptrr   r   r   ÚloggerÚdebugÚbind_output)r   r’   r“   r”   r•   r�   rŽ   rS   r˜   ÚiÚpast_ir�   r   Úoutput_nameÚoutput_buffers                  r   Úprepare_io_bindingz"IOBindingHelper.prepare_io_bindingÕ   sŽ  € ô '×;Ñ;¸KÓHÐð !×+Ñ+Ó-ˆ
ð ×&Ñ&Ô(Ð(Ð(Ø×ÑØØ×Ñ×!Ñ!ØØ˜kÑ*Ü�—‘Ó!Ó"Ø×ÑÓ ô	
ð ÐÜ& t›_ò ‘	��6Ø×+Ñ+Ô-Ð-Ð-à!Ÿ?™?Ó,�Ø˜q’=ð  )×1Ñ1Ó3�Hà×%Ñ%Ø˜A˜3�KØ—M‘M×&Ñ&ØØ%¨¨a¨S kÑ2Ü˜Ÿ™›Ó'Øõðð$ Ð%Ø!×/Ñ/Ô1Ð1Ð1Ø×!Ñ!Ø Ø×%Ñ%×*Ñ*ØØ!Ð"2Ñ3Ü�^×(Ñ(Ó*Ó+Ø×'Ñ'Ó)ôð Ð#Ø×-Ñ-Ô/Ð/Ð/Ø×!Ñ!ØØ×#Ñ#×(Ñ(ØØ! .Ñ1Ü�\×&Ñ&Ó(Ó)Ø×%Ñ%Ó'ôð "×-Ñ-Ó/ò 	ˆFØ Ÿ+™+ˆKØ*¨;Ñ7ˆMÜ�L‰L˜K˜=¨°m×6JÑ6J×6OÑ6OÐ5PÐPWÔX\Ð]j×]oÑ]oÓ]qÓXrÐWsÐtÔuØ×"Ñ"ØØ×$Ñ$×)Ñ)ØØ! +Ñ.Ø˜kÑ*Ø×&Ñ&Ó(õð		ð Ðr   c                 óh  — g }| j                  «       D ]œ  }|j                  }||   }||   }|dt        j                  |«       j	                  |«      j                  «       j                  «       }	|r.|j                  |	j                  «       j                  «       «       ŒŒ|j                  |	«       Œž |S )z3Copy results to cpu. Returns a list of numpy array.r   )	r   r   r.   r�   ÚreshapeÚcloneÚdetachÚappendÚcpu)
r   r�   rŽ   Úreturn_numpyÚort_outputsr   r£   Úbufferr�   Úcopy_tensors
             r   Ú"get_outputs_from_io_binding_bufferz2IOBindingHelper.get_outputs_from_io_binding_buffer*  s§   € ð ˆØ!×-Ñ-Ó/ò 	0ˆFØ Ÿ+™+ˆKØ# KÑ0ˆFØ! +Ñ.ˆEØ  ¤U§Z¡Z°Ó%6Ð7×?Ñ?ÀÓF×LÑLÓN×UÑUÓWˆKÙØ×"Ñ" ;§?¡?Ó#4×#:Ñ#:Ó#<Õ=à×"Ñ" ;Õ/ð	0ð Ðr   N)T)r~   r   r€   r�   r   r‘   rG   ÚTensorr›   r¥   r°   r†   r   r   rˆ   rˆ   Ê   s†   „ ØðÐ(8ò ó ðð ðRà—<‘<ðRð —l‘lðRð Ÿ™ð	Rð
 �5—<‘<Ñ òRó ðRðh òó ñr   rˆ   c                   óÞ   — e Zd ZdZddedej                  fd„Zdedefd„Z	d„ Z
d	ed
ej                  fd„Zdefd„Zddeeej                  f   dedefd„Zeddedededeeef   fd„«       Zy)ÚCudaSessionzLInference Session with IO Binding for ONNX Runtime CUDA or TensorRT providerr   rŠ   c                 ó6  — || _         | j                   j                  «       D �cg c]  }|j                  ‘Œ c}| _        | j                   j	                  «       D �cg c]  }|j                  ‘Œ c}| _        t        j                  | j                   «      | _        t        j                  | j                   «      | _
        | j                   j                  «       | _        || _        t        «       | _        t        «       | _        || _        i | _        y c c}w c c}w ©N)r   r   r   Úinput_namesr   Úoutput_namesr
   rT   Úio_name_to_onnx_typer}   Úio_name_to_torch_typer˜   Úenable_cuda_graphr   Úinput_tensorsÚoutput_tensorsrŠ   Úbuffer_sharing)Úselfr   rŠ   rº   r   r   s         r   Ú__init__zCudaSession.__init__=  sÔ   € Ø&ˆÔØ48×4DÑ4D×4OÑ4OÓ4QÖR¨5˜EŸJ›JÒRˆÔØ7;×7GÑ7G×7SÑ7SÓ7UÖV¨V˜VŸ[›[ÒVˆÔÜ$.×$CÑ$CÀD×DTÑDTÓ$UˆÔ!Ü%/×%EÑ%EÀd×FVÑFVÓ%WˆÔ"Ø×*Ñ*×5Ñ5Ó7ˆŒØ!2ˆÔä(›]ˆÔÜ)›mˆÔØˆŒð /1ˆÕùò SùÚVs   ¤DÁDÚ
input_namer£   c                 ó€   — || j                   v sJ ‚|| j                  v sJ ‚|| j                  |<   || j                  |<   y rµ   )r¶   r·   r½   )r¾   rÀ   r£   s      r   Úset_buffer_sharingzCudaSession.set_buffer_sharingM  sJ   € Ø˜T×-Ñ-Ñ-Ð-Ð-Ø˜d×/Ñ/Ñ/Ð/Ð/Ø*5ˆ×Ñ˜JÑ'Ø+5ˆ×Ñ˜KÒ(r   c                 ó   — | ` | `| `y rµ   )r»   r¼   r˜   )r¾   s    r   Ú__del__zCudaSession.__del__S  s   € ØÐØÐØ‰Or   r   Útensorc           	      ól  — |j                   j                  �|j                   j                  nd}t        |j                  «      dk(  rdgnt	        |j                  «      }| j
                  j                  ||j                   j                  || j                  |   ||j                  «       «       || j                  v ry| j
                  j                  | j                  |   |j                   j                  || j                  |   ||j                  «       «       || j                  | j                  |   <   y y )Nr   é   )rŠ   ÚindexÚlenr�   r›   r˜   rš   r   r¸   r�   r½   r    r¼   )r¾   r   rÅ   Ú	device_idÚtensor_shapes        r   Úbind_input_and_buffer_sharingz)CudaSession.bind_input_and_buffer_sharingX  s  € Ø+1¯=©=×+>Ñ+>Ð+J�F—M‘M×'Ò'ÐPQˆ	Ü! &§,¡,Ó/°1Ò4˜‘s¼$¸v¿|¹|Ó:Lˆà�‰×"Ñ"ØØ�M‰M×ÑØØ×%Ñ% dÑ+ØØ�O‰OÓô	
ð �4×&Ñ&Ñ&Ø�O‰O×'Ñ'Ø×#Ñ# DÑ)Ø—‘×"Ñ"ØØ×)Ñ)¨$Ñ/ØØ—‘Ó!ôð >DˆD×Ñ × 3Ñ 3°DÑ 9Ò:ð 'r   Ú
shape_dictc                 óŒ  — | j                   rÙ|j                  «       D ]Æ  \  }}|| j                  v sŒ|| j                  v r:t	        | j                  |   j
                  «      t	        |«      k(  rŒRt        d«      ‚| j                  |   }t        j                  t	        |«      |¬«      j                  | j                  ¬«      }|| j                  |<   | j                  ||«       ŒÈ |j                  «       D �]K  \  }}|| j                  v sŒ|| j                  v r/t	        | j                  |   j
                  «      t	        |«      k(  rŒS|| j                  v rŒb| j                  |   }t        j                  t	        |«      |¬«      j                  | j                  ¬«      }|| j                  |<   | j                   j#                  ||j                  j$                  |j                  j&                  �|j                  j&                  nd| j(                  |   t+        |j-                  «       «      |j/                  «       «       �ŒN y)z Allocate tensors for I/O Bindingz(Expect static input shape for cuda graph)r…   )rŠ   Nr   )rº   r‹   r¶   r»   Útupler�   ÚRuntimeErrorr¹   rG   rŒ   ÚtorŠ   rÌ   r·   r¼   r½   r˜   r    r   rÈ   r¸   r›   rœ   r�   )r¾   rÍ   r   r�   Útorch_dtyperÅ   s         r   Úallocate_bufferszCudaSession.allocate_buffersp  sñ  € à×!Ò!Ø)×/Ñ/Ó1ò E‘��eØ˜4×+Ñ+Ò+à˜t×1Ñ1Ñ1Ü  ×!3Ñ!3°DÑ!9×!?Ñ!?Ó@ÄEÈ%ÃLÒPØ$Ü*Ð+UÓVÐVà"&×"<Ñ"<¸TÑ"B�KÜ"Ÿ[™[¬¨u«¸[ÔI×LÑLÐTX×T_ÑT_ÐLÓ`�FØ/5�D×&Ñ& tÑ,Ø×6Ñ6°t¸VÕDðEð &×+Ñ+Ó-ó 	‰KˆD�%Ø�t×(Ñ(Ò(à˜4×.Ñ.Ñ.´5¸×9LÑ9LÈTÑ9R×9XÑ9XÓ3YÔ]bÐchÓ]iÒ3iØà˜4×.Ñ.Ñ.Øà"×8Ñ8¸Ñ>�ÜŸ™¤U¨5£\¸ÔE×HÑHÐPT×P[ÑP[ÐHÓ\�Ø,2�×#Ñ# DÑ)à—‘×+Ñ+ØØ—M‘M×&Ñ&Ø+1¯=©=×+>Ñ+>Ð+J�F—M‘M×'Ò'ÐPQØ×-Ñ-¨dÑ3Ü˜Ÿ™›Ó'Ø—O‘OÓ%öñ	r   NÚ	feed_dictÚrun_optionsÚsynchronizec                 ó<  — |j                  «       D ]ð  \  }}t        |t        j                  «      r|j	                  «       sJ ‚|| j
                  v sŒA| j                  r’| j                  |   j                  «       |j                  «       k(  sJ ‚| j                  |   j                  |j                  k(  sJ ‚|j                  j                  dk(  sJ ‚| j                  |   j                  |«       Œß| j                  ||«       Œò |rf| j                  j                  «        | j                   j#                  | j                  |«       | j                  j%                  «        | j&                  S | j                   j#                  | j                  |«       | j&                  S )z$Bind input tensors and run inferenceÚcuda)r‹   Ú
isinstancerG   r±   r™   r¶   rº   r»   Únelementr…   rŠ   r   Úcopy_rÌ   r˜   Úsynchronize_inputsr   Úrun_with_iobindingÚsynchronize_outputsr¼   )r¾   rÔ   rÕ   rÖ   r   rÅ   s         r   ÚinferzCudaSession.infer–  sV  € à%ŸO™OÓ-ò 		E‰LˆD�&Ü˜f¤e§l¡lÔ3¸×8LÑ8LÔ8NÐNÐNØ�t×'Ñ'Ò'Ø×)Ò)Ø×-Ñ-¨dÑ3×<Ñ<Ó>À&Ç/Á/ÓBSÒSÐSÐSØ×-Ñ-¨dÑ3×9Ñ9¸V¿\¹\ÒIÐIÐIØ!Ÿ=™=×-Ñ-°Ò7Ð7Ð7Ø×&Ñ& tÑ,×2Ñ2°6Õ:à×6Ñ6°t¸VÕDð		Eñ Ø�O‰O×.Ñ.Ô0Ø×Ñ×/Ñ/°·±ÀÔMØ�O‰O×/Ñ/Ô1ð ×"Ñ"Ð"ð ×Ñ×/Ñ/°·±ÀÔMà×"Ñ"Ð"r   rÊ   rº   Ústreamr   c                 ó8   — | d|dœ}|dk7  rt        |«      |d<   |S )NÚkSameAsRequested)rÊ   Úarena_extend_strategyrº   r   Úuser_compute_stream)r‚   )rÊ   rº   rà   Úoptionss       r   Úget_cuda_provider_optionsz%CudaSession.get_cuda_provider_options¬  s1   € ð #Ø%7Ø!2ñ
ˆð �QŠ;Ü-0°«[ˆGÐ)Ñ*àˆr   ©F)NT)r   )r~   r   r€   Ú__doc__r   rG   rŠ   r¿   r‚   rÂ   rÄ   r±   rÌ   Ú	ShapeDictrÓ   rƒ   r   r3   rß   r�   r„   r   ræ   r†   r   r   r³   r³   :  sÃ   „ ÙVñ1Ð$4ð 1¸e¿l¹ló 1ð 6¨Sð 6¸só 6òð
D°#ð D¸u¿|¹|ó Dð0$¨9ó $ñL#˜t C¨¯©Ð$5Ñ6ð #ÀZð #Ðeió #ð, ñ¨Sð ÀTð ÐSVð Ð_cÐdgÐilÐdlÑ_mò ó ñr   r³   c                   ó°   ‡ — e Zd Z	 	 	 	 ddedej
                  dedededede	e
e
f   dz  fˆ fd	„Zdd
edefd„Zdde	e
ej                  f   d
efˆ fd„Zˆ xZS )Ú
GpuBindingNr   rŠ   rÍ   Úenable_gpu_graphÚgpu_graph_idrà   r½   c                 ó  •— t         ‰
| �  |||«       |r*|j                  «       D ]  \  }}	| j                  ||	«       Œ | j	                  |«       || _        |rt        j                  |«      nd | _        || _	        d | _
        y rµ   )Úsuperr¿   r‹   rÂ   rÓ   rí   ÚcopyÚdeepcopyrÍ   rà   Úlast_run_gpu_graph_id)r¾   r   rŠ   rÍ   rì   rí   rà   r½   rÀ   r£   Ú	__class__s             €r   r¿   zGpuBinding.__init__¼  s„   ø€ ô 	‰Ñ˜ fÐ.>Ô?ÙØ+9×+?Ñ+?Ó+Aò AÑ'�
˜KØ×'Ñ'¨
°KÕ@ðAð 	×Ñ˜jÔ)Ø(ˆÔá7Gœ$Ÿ-™-¨
Ô3ÈTˆŒØˆŒà%)ˆÕ"r   Údisable_cuda_graph_in_runr   c                 ó~   — t        «       }|rdn| j                  }|j                  dt        |«      «       || _        |S )Néÿÿÿÿrí   )r   rí   Úadd_run_config_entryr‚   rò   )r¾   rô   rå   rí   s       r   Úget_run_optionszGpuBinding.get_run_optionsÓ  s:   € Ü“,ˆá6‘r¸D×<MÑ<Mˆà×$Ñ$ ^´S¸Ó5FÔGà%1ˆÔ"àˆr   rÔ   c                 ó‚   •— | j                  |«      }| j                  r|j                  dd«       t        ‰| �  ||«      S )NÚ'disable_synchronize_execution_providersÚ1)rø   rà   r÷   rï   rß   )r¾   rÔ   rô   rÕ   ró   s       €r   rß   zGpuBinding.inferÞ  s>   ø€ Ø×*Ñ*Ð+DÓEˆà�;Š;Ø×,Ñ,Ð-VÐX[Ô\ä‰w‰}˜Y¨Ó4Ð4r   )Frö   r   Nrç   )r~   r   r€   r   rG   rŠ   ré   r3   r„   rƒ   r‚   r¿   r   rø   r±   rß   Ú__classcell__)ró   s   @r   rë   rë   »  s¥   ø„ ð "'ØØØ04ñ*à%ð*ð —‘ð*ð ð	*ð
 ð*ð ð*ð ð*ð ˜S #˜X™¨Ñ-õ*ñ.	¸ð 	È*ó 	ñ5˜t C¨¯©Ð$5Ñ6ð 5ÐSW÷ 5ñ 5r   rë   c            	       ól   — e Zd ZdZddedej                  dedefd„Z	 	 dde	d	e
d
eeef   dz  defd„Zy)ÚGpuBindingManagerz­A manager for I/O bindings that support multiple CUDA Graphs.
    One cuda graph is reused for same input shape. Automatically add a new cuda graph for new input shape.
    r   rŠ   rà   Úmax_cuda_graphsc                 óX   — || _         || _        g | _        d | _        || _        || _        y rµ   )r   rŠ   Úgraph_bindingsÚno_graph_bindingrà   rÿ   )r¾   r   rŠ   rà   rÿ   s        r   r¿   zGpuBindingManager.__init__ì  s4   € Ø&ˆÔØˆŒð !ˆÔð !%ˆÔàˆŒà.ˆÕr   NrÍ   Úuse_cuda_graphr½   r   c           	      ó6  — | j                   D ]  }|j                  |k(  sŒ|c S  t        | j                   «      | j                  k\  s|sr| j                  €?t        | j                  | j                  || j                  |¬«      | _        | j                  S | j                  j                  |«       | j                  S t        | j                  | j                  |dt        | j                   «      | j                  |¬«      }| j                   j                  |«       |S )N)rà   r½   T)rì   rí   rà   r½   )r  rÍ   rÉ   rÿ   r  rë   r   rŠ   rà   rÓ   rª   )r¾   rÍ   r  r½   Úgpu_graph_bindings        r   Úget_bindingzGpuBindingManager.get_bindingú  s  € ð "&×!4Ñ!4ò 	)Ðà ×+Ñ+¨zÓ9Ø(Ò(ð	)ô ˆt×"Ñ"Ó# t×';Ñ';Ò;ÁNØ×$Ñ$Ð,Ü(2Ø×$Ñ$ d§k¡k°:ÀdÇkÁkÐbpô)�Ô%ð
 ×(Ñ(Ð(ð ×%Ñ%×6Ñ6°zÔBØ×(Ñ(Ð(ô 'Ø×ÑØ�K‰KØØ!Ü˜T×0Ñ0Ó1Ø—;‘;Ø)ô
Ðð 	×Ñ×"Ñ"Ð#4Ô5Ø Ð r   )r   rÇ   )FN)r~   r   r€   rè   r   rG   rŠ   r„   r¿   ré   r3   rƒ   r‚   rë   r  r†   r   r   rþ   rþ   ç  so   „ ññ/Ð$4ð /¸e¿l¹lð /ÐTWð /Ðnqó /ð"  %Ø04ñ	 !àð !ð ð !ð ˜S #˜X™¨Ñ-ð	 !ð
 
ô !r   rþ   )rð   ÚloggingÚcollectionsr   Úcollections.abcr   Útypingr   r.   rG   Úonnxr   Úonnxruntimer   r   r‚   rÏ   r›   r„   ré   Ú	getLoggerr~   rž   r
   rˆ   r³   rë   rþ   r†   r   r   ú<module>r     sŠ   ðÛ Û Ý #Ý #Ý ã Û Ý ç 4ð �C˜  c¡Ñ*Ð*Ñ+€	à	ˆ×	Ñ	˜8Ó	$€÷t"ñ t"÷nmñ m÷`~ñ ~ôB)5�ô )5÷X3!ò 3!r   