Ë
    /æjVM ã                  óx  — d dl mZ d dlZd dlZd dl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mZ d dlZd dlmZ ej$                  rd dlmZ d%d„Z G d„ d	e«      Zd&d
„ZdZdZd'd„Zd(d„Zd)d„Z G d„ d«      Z	 	 	 	 	 	 d*d„Z G d„ d«      Z G d„ de«      Z 	 	 	 	 d+d„Z! G d„ d«      Z" G d„ d«      Z# G d„ d«      Z$d Z%d,d„Z&e&f	 	 	 d-d„Z'd.d/d „Z( G d!„ d"«      Z) G d#„ d$«      Z*ee+e$ejX                  dz  gejX                  dz  f   Z-ee+ejH                  ejX                  dz  gejX                  dz  f   Z.y)0é    )ÚannotationsN)ÚCallableÚSequence)ÚIntEnum)ÚAny)Ú_pybind_statec                ó  — | dk(  rt         j                  j                  «       S | dk(  rt         j                  j                  «       S | dk(  rt         j                  j	                  «       S | dk(  rt         j                  j                  «       S | dk(  rt         j                  j                  «       S | dk(  rt         j                  j                  «       S | dk(  rt         j                  j                  «       S t        d| z   «      ‚)	NÚcudaÚcannÚcpuÚdmlÚwebgpuÚgpuÚnpuzUnsupported device type: )
ÚCÚ	OrtDevicer
   r   r   r   r   r   r   Ú	Exception©Údevice_types    út/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/onnxruntime/capi/onnxruntime_inference_collection.pyÚget_ort_device_typer      sÈ   € Ø�fÒÜ�{‰{×ÑÓ!Ð!Ø	˜Ò	Ü�{‰{×ÑÓ!Ð!Ø	˜Ò	Ü�{‰{�‰Ó Ð Ø	˜Ò	Ü�{‰{�‰Ó Ð Ø	˜Ò	 Ü�{‰{×!Ñ!Ó#Ð#Ø	˜Ò	Ü�{‰{�‰Ó Ð Ø	˜Ò	Ü�{‰{�‰Ó Ð äÐ3°kÑAÓBÐBó    c                  ó0   — e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zy
)ÚOrtDeviceVendorIdz<Vendor IDs aligned with OrtDevice::VendorIds in ortdevice.h.r   i  iÞ  iµ  i  iå  iCQ  i†€  N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚNONEÚAMDÚNVIDIAÚARMÚ	MICROSOFTÚHUAWEIÚQUALCOMMÚINTEL© r   r   r   r   ,   s-   „ ÙFà€DØ
€CØ€FØ
€CØ€IØ€FØ€HØ�Er   r   c                ó¬   — | dk(  rt         j                  S | dk(  rt         j                  S | dk(  rt         j                  S | dk(  rt         j                  S y )Nr
   r   r   r   )r   r!   r#   r$   r   r   s    r   Úget_vendor_id_for_device_typer)   9   sU   € Ø�fÒÜ ×'Ñ'Ð'Ø	˜Ò	Ü ×*Ñ*Ð*Ø	˜Ò	Ü ×'Ñ'Ð'Ø	˜Ò	 Ü ×%Ñ%Ð%àr   Úgpu_graph_idéÿÿÿÿc                ó¸   — | €y	 | j                  t        «      }|sy	 t        |«      S # t        $ r Y yw xY w# t        $ r t	        dt        › d|›d�«      d‚w xY w)zLReturn the effective ``gpu_graph_id`` for a run, defaulting to 0 when unset.Nr   zRun option 'z' must be an integer, got ú.)Úget_run_config_entryÚ_GPU_GRAPH_ID_RUN_CONFIG_KEYÚRuntimeErrorÚintÚ
ValueError)Úrun_optionsÚentrys     r   Ú_graph_annotation_idr5   K   s‚   € àÐØðØ×0Ñ0Ô1MÓNˆñ ØðvÜ�5‹zÐøô ò Ùðûô ò vÜ˜<Ô(DÐ'EÐE_Ð`eÐ_hÐhiÐjÓkÐquÐuðvús   …) ž
8 ©	5´5¸!Ac                ó®   — | j                   �|�| j                   |u ry| j                  xr+ | j                   j                  «       |j                  «       k(  S )zÍWhether ``target_session`` can share ``ortvalue``'s buffer.

    Sessionless values come from a shared allocator. A session-owned WebGPU buffer is
    usable by any session on the same WebGPU context.
    T)Ú_sessionÚ_is_webgpu_bufferÚwebgpu_context_id)ÚortvalueÚtarget_sessions     r   Ú_is_ortvalue_session_compatibler<   [   sU   € ð ×ÑÐ  NÐ$:¸h×>OÑ>OÐSaÑ>aØØ×%Ñ%Òu¨(×*;Ñ*;×*MÑ*MÓ*OÐSa×SsÑSsÓSuÑ*uÐur   c                ó:   — t        | |«      st        d|› d�«      ‚y)z£Reject an OrtValue that the target session cannot share buffers with.

    ``action`` is the verb used in the message, e.g. ``"used with"`` or ``"bound to"``.
    z Session-scoped OrtValue must be z the session that created it.N)r<   r2   )r:   r;   Úactions      r   Ú(_validate_ortvalue_session_compatibilityr?   f   s*   € ô
 +¨8°^ÔDÜÐ;¸F¸8ÐC`ÐaÓbÐbð Er   c                  ól   — e Zd ZdZddd„Zedd„«       Zdd„Zdd„Zdd„Z	dd„Z
dd	„Zdd
„Zdd„Zdd„Zy)ÚAdapterFormatzK
    This class is used to create adapter files from python structures
    Nc                óJ   — |€t        j                  «       | _        y || _        y ©N)r   rA   Ú_adapter)ÚselfÚadapters     r   Ú__init__zAdapterFormat.__init__t   s   € Øˆ?ÜŸO™OÓ-ˆD�Mà#ˆD�Mr   c                óR   — t        t        j                   j                  | «      «      S rC   )rA   r   Úread_adapter)Ú	file_paths    r   rI   zAdapterFormat.read_adapterz   s   € äœQŸ_™_×9Ñ9¸)ÓDÓEÐEr   c                ó:   — | j                   j                  |«       y)zÂ
        This function writes a file at the specified location
        in onnxrunitme adapter format containing Lora parameters.

        :param file_path: absolute path for the adapter
        N)rD   Úexport_adapter)rE   rJ   s     r   rL   zAdapterFormat.export_adapter~   s   € ð 	�‰×$Ñ$ YÕ/r   c                ó.   — | j                   j                  S rC   )rD   Úformat_version©rE   s    r   Úget_format_versionz AdapterFormat.get_format_version‡   s   € Ø�}‰}×+Ñ+Ð+r   c                ó&   — || j                   _        y rC   ©rD   Úadapter_version)rE   rS   s     r   Úset_adapter_versionz!AdapterFormat.set_adapter_versionŠ   s   € Ø(7ˆ�‰Õ%r   c                ó.   — | j                   j                  S rC   rR   rO   s    r   Úget_adapter_versionz!AdapterFormat.get_adapter_version�   s   € Ø�}‰}×,Ñ,Ð,r   c                ó&   — || j                   _        y rC   ©rD   Úmodel_version)rE   rY   s     r   Úset_model_versionzAdapterFormat.set_model_version�   s   € Ø&3ˆ�‰Õ#r   c                ó.   — | j                   j                  S rC   rX   rO   s    r   Úget_model_versionzAdapterFormat.get_model_version“   s   € Ø�}‰}×*Ñ*Ð*r   c                óŠ   — |j                  «       D ��ci c]  \  }}||j                  “Œ c}}| j                  _        yc c}}w )z"Set adapter parameters for export.N)ÚitemsÚ	_ortvaluerD   Ú
parameters)rE   ÚparamsÚkÚvs       r   Úset_parameterszAdapterFormat.set_parameters–   s.   € à?E¿|¹|»~×#N±t°q¸! A q§{¡{¡NÓ#Nˆ�‰Õ ùÓ#Ns   ”?c                ó�   — | j                   j                  j                  «       D ��ci c]  \  }}|t        |«      “Œ c}}S c c}}w )zÝGet adapter parameters as a dict of name -> OrtValue.

        On read instances, the returned OrtValues are zero-copy views; the
        backing memory stays alive as long as any returned OrtValue is referenced.
        )rD   r`   r^   ÚOrtValue)rE   rb   rc   s      r   Úget_parameterszAdapterFormat.get_parametersš   s7   € ð ,0¯=©=×+CÑ+C×+IÑ+IÓ+K×L¡4 1 a�”8˜A“;‘ÓLÐLùÓLs   ¨ArC   ©ÚreturnÚNone)rJ   úos.PathLikeri   rA   )rJ   rk   ©ri   r1   )rS   r1   ri   rj   )rY   r1   ri   rj   )ra   údict[str, OrtValue]ri   rj   )ri   rm   )r   r   r   r   rG   ÚstaticmethodrI   rL   rP   rT   rV   rZ   r\   rd   rg   r'   r   r   rA   rA   o   sL   „ ñô$ð òFó ðFó0ó,ó8ó-ó4ó+óOôMr   rA   c                ó`  ‡‡— | €g g fS t        j                  «       Šˆˆfd„}t        | t         j                  j                  «      st        d«      ‚|�«t        |t         j                  j                  «      st        d«      ‚t        | «      t        |«      k7  rt        d«      ‚t        d„ | D «       «      st        d«      ‚t        d„ |D «       «      st        d«      ‚t        | |d	¬
«      D ]  \  }} |||«       Œ n| D ]z  }t        |t        «      r
 ||i «       Œt        |t        «      rDt        |«      dk(  r6t        |d   t        «      r#t        |d   t        «      r ||d   |d   «       Œqt        d«      ‚ t        ‰j                  «       «      t        ‰j                  «       «      fS )aç  
    Validates the 'providers' and 'provider_options' arguments and returns a
        normalized version.

    :param providers: Optional sequence of providers in order of decreasing
        precedence. Values can either be provider names or tuples of
        (provider name, options dict).
    :param provider_options: Optional sequence of options dicts corresponding
        to the providers listed in 'providers'.
    :param available_provider_names: The available provider names.

    :return: Tuple of (normalized 'providers' sequence, normalized
        'provider_options' sequence).

    'providers' can contain either names or names and options. When any options
        are given in 'providers', 'provider_options' should not be used.

    The normalized result is a tuple of:
    1. Sequence of provider names in the same order as 'providers'.
    2. Sequence of corresponding provider options dicts with string keys and
        values. Unspecified provider options yield empty dicts.
    c                ó2  •— | ‰vr4t        j                  dj                  | dj                  ‰«      «      «       | ‰v rt        j                  d| › d�«       y |j	                  «       D ��ci c]  \  }}t        |«      t        |«      “Œ }}}|‰| <   y c c}}w )NzTSpecified provider '{}' is not in available provider names.Available providers: '{}'ú, zDuplicate provider 'z' encountered, ignoring.)ÚwarningsÚwarnÚformatÚjoinr^   Ústr)ÚnameÚoptionsÚkeyÚvalueÚnormalized_optionsÚavailable_provider_namesÚprovider_name_to_optionss        €€r   Úset_provider_optionsz?check_and_normalize_provider_args.<locals>.set_provider_optionsÃ   s–   ø€ ØÐ/Ñ/Ü�M‰MØf×mÑmØ˜$Ÿ)™)Ð$<Ó=óôð Ð+Ñ+Ü�M‰MÐ0°°Ð6NÐOÔPØàELÇ]Á]Ã_×U±z°s¸Eœc #›h¬¨E«
Ñ2ÐUÐÑUØ);Ð  Ò&ùó Vs   Á+Bz!'providers' should be a sequence.z('provider_options' should be a sequence.zO'providers' and 'provider_options' should be the same length if both are given.c              3  ó<   K  — | ]  }t        |t        «      –— Œ y ­wrC   )Ú
isinstancerv   ©Ú.0Úproviders     r   ú	<genexpr>z4check_and_normalize_provider_args.<locals>.<genexpr>Ü   s   è ø€ ÒG°”:˜h¬×,ÑGùó   ‚zPOnly string values for 'providers' are supported if 'provider_options' is given.c              3  ó<   K  — | ]  }t        |t        «      –— Œ y ­wrC   )r€   Údict)r‚   Úoptions_for_providers     r   r„   z4check_and_normalize_provider_args.<locals>.<genexpr>ß   s   è ø€ ÒgÐ>R”:Ð2´D×9Ñgùr…   z('provider_options' values must be dicts.F)Ústricté   r   é   zC'providers' values must be either strings or (string, dict) tuples.)ÚcollectionsÚOrderedDictr€   Úabcr   r2   ÚlenÚallÚziprv   Útupler‡   ÚlistÚkeysÚvalues)Ú	providersÚprovider_optionsr|   r~   rw   rx   rƒ   r}   s     `    @r   Ú!check_and_normalize_provider_argsr˜   £   s�  ù€ ð6 ÐØ�2ˆvˆä*×6Ñ6Ó8Ðõ<ô �i¤§¡×!9Ñ!9Ô:ÜÐ<Ó=Ð=àÐ#ÜÐ*¬K¯O©O×,DÑ,DÔEÜÐGÓHÐHäˆy‹>œSÐ!1Ó2Ò2ÜÐnÓoÐoäÑG¸YÔGÔGÜÐoÓpÐpäÑgÐVfÔgÔgÜÐGÓHÐHä  Ð,<ÀUÔKò 	0‰MˆD�'Ù   wÕ/ñ	0ð "ò 	hˆHÜ˜(¤CÔ(Ù$ X¨rÕ2ä˜8¤UÔ+Ü˜“M QÒ&Ü˜x¨™{¬CÔ0Ü˜x¨™{¬DÔ1á$ X¨a¡[°(¸1±+Õ>ä Ð!fÓgÐgð	hô Ð(×-Ñ-Ó/Ó0´$Ð7O×7VÑ7VÓ7XÓ2YÐYÐYr   c                  ó   — e Zd ZdZd$d%d„Zd&d„Zd'd„Zd'd„Zd'd„Zd(d„Z	d)d„Z
d)d	„Zd*d
„Zd+d„Zd„ Zd,d„Zd-d.d„Zd.d„Zd.d„Zd„ Zd„ Zd/d„Zd/d0d„Zd/d„Zd/d1d„Zd„ Zd„ Zd2d„Z	 	 d3	 	 	 	 	 	 	 	 	 d4d„Zd5d6d„Zd/d„Zd7d„Zd„ Z d d!œd"„Z!d#„ Z"y)8ÚSessionú5
    This is the main class used to run a model.
    c                ó.   — d | _         || _        i | _        y rC   )Ú_sessÚ_enable_fallbackÚ_captured_graph_bindings)rE   Úenable_fallbacks     r   rG   zSession.__init__û   s   € àˆŒ
Ø /ˆÔàNPˆÕ%r   c                ó   — | j                   S )zDReturn the session options. See :class:`onnxruntime.SessionOptions`.)Ú_sess_optionsrO   s    r   Úget_session_optionszSession.get_session_options  ó   € à×!Ñ!Ð!r   c                ó   — | j                   S )zEReturn the inputs metadata as a list of :class:`onnxruntime.NodeArg`.)Ú_inputs_metarO   s    r   Ú
get_inputszSession.get_inputs  s   € à× Ñ Ð r   c                ó   — | j                   S )zFReturn the outputs metadata as a list of :class:`onnxruntime.NodeArg`.)Ú_outputs_metarO   s    r   Úget_outputszSession.get_outputs
  r¤   r   c                ó   — | j                   S )z^Return the inputs (including initializers) metadata as a list of :class:`onnxruntime.NodeArg`.)Ú_overridable_initializersrO   s    r   Úget_overridable_initializersz$Session.get_overridable_initializers  s   € à×-Ñ-Ð-r   c                ó   — | j                   S )z<Return the metadata. See :class:`onnxruntime.ModelMetadata`.)Ú_model_metarO   s    r   Úget_modelmetazSession.get_modelmeta  s   € à×ÑÐr   c                ó   — | j                   S )z&Return the memory info for the inputs.)Ú_input_meminfosrO   s    r   Úget_input_memory_infoszSession.get_input_memory_infos  s   € à×#Ñ#Ð#r   c                ó   — | j                   S )z'Return the memory info for the outputs.)Ú_output_meminfosrO   s    r   Úget_output_memory_infoszSession.get_output_memory_infos  ó   € à×$Ñ$Ð$r   c                ó   — | j                   S )z.Return the execution providers for the inputs.)Ú_input_epdevicesrO   s    r   Úget_input_epdeviceszSession.get_input_epdevices  r·   r   c                ó   — | j                   S )z.Return list of registered execution providers.)Ú
_providersrO   s    r   Úget_providerszSession.get_providers"  s   € à�‰Ðr   c                ó   — | j                   S )z6Return registered execution providers' configurations.)Ú_provider_optionsrO   s    r   Úget_provider_optionszSession.get_provider_options&  s   € à×%Ñ%Ð%r   c                ó6   — | j                   j                  «       S )a)  
        Get information about the subgraphs assigned to each execution provider and the nodes within.

        Application must enable the recording of graph assignment information by setting the session configuration
        for the key "session.record_ep_graph_assignment_info" to "1".
        )r�   Ú"get_provider_graph_assignment_inforO   s    r   rÂ   z*Session.get_provider_graph_assignment_info*  s   € ð �z‰z×<Ñ<Ó>Ð>r   Nc                ó(   — | j                  ||«       y)a¬  
        Register the input list of execution providers. The underlying session is re-created.

        :param providers: Optional sequence of providers in order of decreasing
            precedence. Values can either be provider names or tuples of
            (provider name, options dict). If not provided, then all available
            providers are used with the default precedence.
        :param provider_options: Optional sequence of options dicts corresponding
            to the providers listed in 'providers'.

        'providers' can contain either names or names and options. When any options
        are given in 'providers', 'provider_options' should not be used.

        The list of providers is ordered by precedence. For example
        `['CUDAExecutionProvider', 'CPUExecutionProvider']`
        means execute a node using CUDAExecutionProvider if capable,
        otherwise execute using CPUExecutionProvider.
        N)Ú_reset_session©rE   r–   r—   s      r   Úset_providerszSession.set_providers3  s   € ð( 	×Ñ˜IÐ'7Õ8r   c                ó   — d| _         y)z;
        Disable session.run() fallback mechanism.
        FN©rž   rO   s    r   Údisable_fallbackzSession.disable_fallbackI  s   € ð !&ˆÕr   c                ó   — d| _         y)a4  
        Enable session.Run() fallback mechanism. If session.Run() fails due to an internal Execution Provider failure,
        reset the Execution Providers enabled for this session.
        If GPU is enabled, fall back to CUDAExecutionProvider.
        otherwise fall back to CPUExecutionProvider.
        TNrÈ   rO   s    r   r    zSession.enable_fallbackO  s   € ð !%ˆÕr   c                óÞ   — g }| j                   D ]H  }|j                  |vsŒ|j                  j                  d«      rŒ.|j	                  |j                  «       ŒJ |rt        d|› d|› d�«      ‚y )NÚoptionalzRequired inputs (z) are missing from input feed (z).)r¦   rw   ÚtypeÚ
startswithÚappendr2   )rE   Úfeed_input_namesÚmissing_input_namesÚinputs       r   Ú_validate_inputzSession._validate_inputX  s}   € Ø ÐØ×&Ñ&ò 	7ˆEØ�z‰zÐ!1Ò1¸%¿*¹*×:OÑ:OÐPZÕ:[Ø#×*Ñ*¨5¯:©:Õ6ð	7ñ ÜØ#Ð$7Ð#8Ð8WÐXhÐWiÐikÐlóð ð r   c                ób   — |D ]*  }t        |t        «      sŒt        || j                  d«       Œ, y )Nz	used with)r€   rf   r?   r�   )rE   r•   rz   s      r   Ú_validate_ortvalue_ownershipz$Session._validate_ortvalue_ownershipb  s0   € Øò 	UˆEÜ˜e¤XÔ.ØÜ4°U¸D¿J¹JÈÕTñ	Ur   c                ó’   — | j                   j                  «       sy t        |«      t        k(  ry t	        dt
        › dt        › d�«      ‚)NzVWebGPU graph capture requires fixed device OrtValues and run_with_iobinding. Set the 'ú' run option to z$ to opt a single run out of capture.)r�   Úis_webgpu_graph_capture_enabledr5   Ú_GRAPH_ANNOTATION_SKIPr2   r/   )rE   r3   s     r   Ú_validate_graph_capture_run_apiz'Session._validate_graph_capture_run_apih  sP   € Ø�z‰z×9Ñ9Ô;ØÜ Ó,Ô0FÒFàÜðÜ4Ð5Ð5EÜ%Ð&Ð&JðLó
ð 	
r   c                óÒ  — | j                  |«       | j                  t        |j                  «       «      «       | j	                  |j                  «       «       |s#| j                  D �cg c]  }|j                  ‘Œ }}	 | j                  j                  |||«      S c c}w # t        j                  $ r²}| j                  r t        d|›d| j                  › �«       t        d| j                  › d�«       | j!                  | j                  «       | j#                  «        | j	                  |j                  «       «       | j                  j                  |||«      cY d}~S ‚ d}~ww xY w)aD  
        Compute the predictions.

        WebGPU graph capture requires fixed device OrtValues bound with
        :meth:`run_with_iobinding`; do not use this convenience API for captured replay.

        :param output_names: name of the outputs
        :param input_feed: dictionary ``{ input_name: input_value }``
        :param run_options: See :class:`onnxruntime.RunOptions`.
        :return: list of results, every result is either a numpy array,
            a sparse tensor, a list or a dictionary.

        ::

            sess.run([output_name], {input_name: x})
        ú
EP Error: ú using úFalling back to ú and retrying.N)rÚ   rÓ   r“   r”   rÕ   r•   r©   rw   r�   Úrunr   ÚEPFailrž   Úprintr¼   Ú_fallback_providersrÆ   rÉ   )rE   Úoutput_namesÚ
input_feedr3   ÚoutputÚerrs         r   rà   zSession.runt  s(  € ð" 	×,Ñ,¨[Ô9Ø×ÑœT *§/¡/Ó"3Ó4Ô5Ø×)Ñ)¨*×*;Ñ*;Ó*=Ô>ÙØ6:×6HÑ6HÖI¨F˜FŸK›KÐIˆLÐIð	Ø—:‘:—>‘> ,°
¸KÓHÐHùò Jøô �x‰xò 		Ø×$Ò$Ü˜
 3 '¨°·±Ð0AÐBÔCÜÐ(¨×)AÑ)AÐ(BÀ.ÐQÔRØ×"Ñ" 4×#;Ñ#;Ô<à×%Ñ%Ô'Ø×1Ñ1°*×2CÑ2CÓ2EÔFØ—z‘z—~‘~ l°JÀÓLÕLØûð		ús+   Á)BÁ?B! Â!E&Â4B&E!ÅE&Å E!Å!E&c                óD  — | j                  |«       | j                  t        |j                  «       «      «       | j	                  |j                  «       «       |s#| j                  D �cg c]  }|j                  ‘Œ }}| j                  j                  |||||«      S c c}w )a¡  
        Compute the predictions asynchronously in a separate cxx thread from ort intra-op threadpool.

        :param output_names: name of the outputs
        :param input_feed: dictionary ``{ input_name: input_value }``
        :param callback: python function that accept array of results, and a status string on error.
            The callback will be invoked by a cxx thread from ort intra-op threadpool.
        :param run_options: See :class:`onnxruntime.RunOptions`.

        ::
            class MyData:
                def __init__(self):
                    # ...
                def save_results(self, results):
                    # ...

            def callback(results: np.ndarray, user_data: MyData, err: str) -> None:
              if err:
                 print (err)
              else:
                # save results to user_data

            sess.run_async([output_name], {input_name: x}, callback)
        )
rÚ   rÓ   r“   r”   rÕ   r•   r©   rw   r�   Ú	run_async)rE   rä   rå   ÚcallbackÚ	user_datar3   ræ   s          r   ré   zSession.run_async—  s‡   € ð2 	×,Ñ,¨[Ô9Ø×ÑœT *§/¡/Ó"3Ó4Ô5Ø×)Ñ)¨*×*;Ñ*;Ó*=Ô>ÙØ6:×6HÑ6HÖI¨F˜FŸK›KÐIˆLÐIØ�z‰z×#Ñ# L°*¸hÈ	ÐS^Ó_Ð_ùò Js   Á)Bc                ó¸  — d„ }| j                  |«       | j                  t        |j                  «       «      «       | j	                  |j                  «       «       |s#| j                  D �cg c]  }|j                  ‘Œ }}	  || j                  |||«      S c c}w # t        j                  $ rª}| j                  r˜t        d|›d| j                  › �«       t        d| j                  › d�«       | j                  | j                  «       | j!                  «        | j	                  |j                  «       «        || j                  |||«      cY d}~S ‚ d}~ww xY w)aÇ  
        Compute the predictions.

        :param output_names: name of the outputs
        :param input_dict_ort_values: dictionary ``{ input_name: input_ort_value }``
            See ``OrtValue`` class how to create `OrtValue`
            from numpy array or `SparseTensor`
        :param run_options: See :class:`onnxruntime.RunOptions`.
        :return: an array of `OrtValue`

        ::

            sess.run([output_name], {input_name: x})
        c                ó
  — i }|j                  «       D ]  \  }}|j                  «       ||<   Œ | j                  |||«      }t        |t        j
                  «      st        d«      ‚|D �cg c]  }t        |«      ‘Œ }}|S c c}w )NzFrun_with_ort_values() must return a instance of type 'OrtValueVector'.)r^   Ú_get_c_valueÚrun_with_ort_valuesr€   r   ÚOrtValueVectorÚ	TypeErrorrf   )	Úsessrä   Úinput_dict_ort_valuesr3   Ú
input_dictÚnrc   ÚresultÚ
ort_valuess	            r   Úinvokez+Session.run_with_ort_values.<locals>.invokeÇ  s…   € ØˆJØ-×3Ñ3Ó5ò 1‘��1Ø !§¡Ó 0�
˜1’ð1à×-Ñ-¨j¸,ÈÓTˆFÜ˜f¤a×&6Ñ&6Ô7ÜÐ hÓiÐiØ/5Ö6¨!œ( 1�+Ð6ˆJÐ6ØÐùò 7s   Á*B rÜ   rÝ   rÞ   rß   N)rÚ   rÓ   r“   r”   rÕ   r•   r©   rw   r�   r   rá   rž   râ   r¼   rã   rÆ   rÉ   )rE   rä   ró   r3   rø   ræ   rç   s          r   rï   zSession.run_with_ort_values·  s0  € ò 	ð 	×,Ñ,¨[Ô9Ø×ÑœTÐ"7×"<Ñ"<Ó">Ó?Ô@Ø×)Ñ)Ð*?×*FÑ*FÓ*HÔIÙØ6:×6HÑ6HÖI¨F˜FŸK›KÐIˆLÐIð	Ù˜$Ÿ*™* lÐ4IÈ;ÓWÐWùò Jøô �x‰xò 		Ø×$Ò$Ü˜
 3 '¨°·±Ð0AÐBÔCÜÐ(¨×)AÑ)AÐ(BÀ.ÐQÔRØ×"Ñ" 4×#;Ñ#;Ô<à×%Ñ%Ô'Ø×1Ñ1Ð2G×2NÑ2NÓ2PÔQÙ˜dŸj™j¨,Ð8MÈ{Ó[Õ[Øûð		ús+   Á,BÂB ÂEÂ/BEÅEÅEÅEc                ó6   — | j                   j                  «       S )z¶
        End profiling and return results in a file.

        The results are stored in a filename if the option
        :meth:`onnxruntime.SessionOptions.enable_profiling`.
        )r�   Úend_profilingrO   s    r   rú   zSession.end_profilingã  s   € ð �z‰z×'Ñ'Ó)Ð)r   c                ó.   — | j                   j                  S )a  
        Return the nanoseconds of profiling's start time
        Comparable to time.monotonic_ns() after Python 3.3
        On some platforms, this timer may not be as precise as nanoseconds
        For instance, on Windows and MacOS, the precision will be ~100ns
        )r�   Úget_profiling_start_time_nsrO   s    r   rü   z#Session.get_profiling_start_time_nsì  s   € ð �z‰z×5Ñ5Ð5r   c                ó   — t        | «      S )z(Return an onnxruntime.IOBinding object`.)Ú	IOBindingrO   s    r   Ú
io_bindingzSession.io_bindingõ  s   € ä˜‹Ðr   c                ó  — t         j                  |||«      j                  «       }t        |t        «      r| j
                  j                  |||«      }n| j
                  j                  |||«      }t        || j
                  ¬«      S )zÕCreate an OrtValue using this session's allocator.

        The value retains this session and may only be updated or bound through it.
        A matching allocator and a numeric tensor type are required.
        ©Úsession)	r   ÚmakeÚ_get_c_devicer€   r1   r�   Ú(create_ortvalue_from_shape_and_onnx_typeÚ#create_ortvalue_from_shape_and_typerf   )rE   ÚshapeÚelement_typer   Ú	device_idÚ	vendor_idÚdevicer:   s           r   r  z+Session.create_ortvalue_from_shape_and_typeù  sm   € ô —‘ ¨Y¸	ÓB×PÑPÓRˆÜ�l¤CÔ(Ø—z‘z×JÑJÈ5ÐR^Ð`fÓg‰Hà—z‘z×EÑEÀeÈ\Ð[aÓbˆHÜ˜¨$¯*©*Ô5Ð5r   c                óÈ   — | j                   j                  |«       | j                  j                  |d«      }|�) |d   «       }|�|j                  j                  |«       yyy)zâRelease a captured graph and unpin its IOBinding.

        ``graph_annotation_id`` matches the capture's ``gpu_graph_id`` and defaults to zero.
        EPs without captured-graph release support treat this as a no-op.
        Nr   )r�   Úrelease_captured_graphrŸ   ÚpopÚ_pinned_graph_idsÚdiscard)rE   Úgraph_annotation_idÚpinnedÚ	iobindings       r   r  zSession.release_captured_graph  sh   € ð 	�
‰
×)Ñ)Ð*=Ô>Ø×.Ñ.×2Ñ2Ð3FÈÓMˆØÐØ!˜˜q™	›ˆIØÐ$Ø×+Ñ+×3Ñ3Ð4GÕHð %ð r   c                óŽ  — |j                   | j                  urt        d«      ‚t        |«      }| j                  j	                  «       xr	 |t
        k7  }|ry|j                  «        |j                  «       }| j                  j                  |«      }|�< |d   «       |d   }}||urt        d|› d|› d�«      ‚||k7  rt        d|› d|› d�«      ‚| j                  j                  |j                  |«       |rO|| j                  vr@t        j                  |«      f| j                  |<   |j                  j                  |«       yyy)	ai  
        Compute the predictions.

        :param iobinding: the iobinding object that has graph inputs/outputs bind.
        :param run_options: See :class:`onnxruntime.RunOptions`.

        WebGPU capture requires static shapes, disabled memory patterns, fixed WebGPU OrtValues
        (session-owned or shared), and no CPU compute nodes other than shape-only nodes. Each
        ``gpu_graph_id`` pins one IOBinding and its buffers until :meth:`release_captured_graph`.
        Update inputs in place and use :meth:`IOBinding.copy_outputs_to_cpu` for readback;
        ``gpu_graph_id=-1`` disables capture.
        z8IOBinding must be used with the session that created it.Nr   r‹   zWebGPU graph zÀ was captured with a different IOBinding. Replay re-issues the buffers recorded at capture and would silently ignore this binding. Reuse the original IOBinding, or call release_captured_graph(z) first.z× was captured with different I/O buffers. Replay writes to the buffers recorded at capture, so the rebound values would never be read or written. Update the original buffers in place, or call release_captured_graph()r7   r�   r2   r5   rØ   rÙ   Ú_validate_capture_bindingsÚ_capture_signaturerŸ   ÚgetÚrun_with_iobindingÚ
_iobindingÚweakrefÚrefr  Úadd)	rE   r  r3   r  Ú	capturingÚ	signaturer  Úpinned_iobindingÚpinned_signatures	            r   r  zSession.run_with_iobinding  sp  € ð ×Ñ T§Z¡ZÑ/ÜÐWÓXÐXä2°;Ó?ÐØ—J‘J×>Ñ>Ó@ÒrÐEXÔ\rÑErˆ	ÙØ×0Ñ0Ô2Ø!×4Ñ4Ó6ˆIØ×2Ñ2×6Ñ6Ð7JÓKˆFØÐ!Ø5>°V¸A±Y³[À&ÈÁ)Ð"2Ð Ø#¨9Ñ4Ü$Ø'Ð(;Ð'<ð =2ð 3FÐ1FÀhðPóð ð $ yÒ0Ü$Ø'Ð(;Ð'<ð =2ð 3FÐ1FÀhð	Póð ð 	�
‰
×%Ñ% i×&:Ñ&:¸KÔHáÐ,°D×4QÑ4QÑQÜBIÇ+Á+ÈiÓBXÐZcÐAdˆD×)Ñ)Ð*=Ñ>Ø×'Ñ'×+Ñ+Ð,?Õ@ð Rˆ9r   c                ó:   — | j                   j                  |«       y)a'  
        Set dynamic options for execution providers.

        :param options: Dictionary of key-value pairs where both keys and values are strings.
                        These options will be passed to the execution providers to modify
                        their runtime behavior.
        N)r�   Úset_ep_dynamic_options)rE   rx   s     r   r"  zSession.set_ep_dynamic_optionsH  s   € ð 	�
‰
×)Ñ)¨'Õ2r   c                ó6   — | j                   j                  «       S rC   )r�   Úget_tuning_resultsrO   s    r   r$  zSession.get_tuning_resultsR  s   € Ø�z‰z×,Ñ,Ó.Ð.r   F)Úerror_on_invalidc               ó:   — | j                   j                  ||«      S rC   )r�   Úset_tuning_results)rE   Úresultsr%  s      r   r'  zSession.set_tuning_resultsU  s   € Ø�z‰z×,Ñ,¨WÐ6FÓGÐGr   c                óf   — | j                  |«       | j                  j                  ||||||«       y)a´  
        Compute the predictions similar to other run_*() methods but with minimal C++/Python conversion overhead.

        :param run_options: See :class:`onnxruntime.RunOptions`.
        :param feed_names: list of input names.
        :param feeds: list of input OrtValue.
        :param fetch_names: list of output names.
        :param fetches: list of output OrtValue.
        :param fetch_devices: list of output devices.
        N)rÚ   r�   Úrun_with_ortvaluevector)rE   r3   Ú
feed_namesÚfeedsÚfetch_namesÚfetchesÚfetch_devicess          r   r*  zSession.run_with_ortvaluevectorX  s0   € ð 	×,Ñ,¨[Ô9Ø�
‰
×*Ñ*¨;¸
ÀEÈ;ÐX_ÐanÕor   )T)r    Úbool)ri   úC.SessionOptions)ri   zSequence[C.NodeArg])ri   zC.ModelMetadata)ri   zSequence[C.OrtMemoryInfo])ri   zSequence[C.OrtEpDevice])ri   úSequence[str])ri   z!Sequence[C.OrtEpAssignedSubgraph]©NNrh   rC   )ri   z1Sequence[np.ndarray | SparseTensor | list | dict])ri   úSequence[OrtValue])ri   rþ   )r   r+   )
r  úSequence[int]r   rv   r	  r1   r
  úint | OrtDeviceVendorIdri   rf   )r   )r  r1   ri   rj   )rx   zdict[str, str])#r   r   r   r   rG   r£   r§   rª   r­   r°   r³   r¶   rº   r½   rÀ   rÂ   rÆ   rÉ   r    rÓ   rÕ   rÚ   rà   ré   rï   rú   rü   rÿ   r  r  r  r"  r$  r'  r*  r'   r   r   rš   rš   ö   së   „ ñôQó"ó!ó"ó.ó ó$ó%ó%óò&ó?ô9ó,&ó%òòUó

ô!óF`ô@*òX*ò6óð Ø-/ð6àð6ð ð	6ð
 ð6ð +ð6ð 
ó6ô(Ió,Aó\3ò/ð ?Dô Hópr   rš   c                  ó\   ‡ — e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 	 	 dˆ fd„Zd	d„Zd
d„Zd
d„Zd„ Zˆ xZ	S )ÚInferenceSessionr›   c                ó�  •— t         ‰	| �  t        |j                  dd«      «      dk(  ¬«       t	        |t
        t        j                  f«      r"t        j                  |«      | _	        d| _
        n7t	        |t        «      rd| _	        || _
        nt        dt        |«      › d�«      ‚|| _        || _        d|v rt        |d   «      dk(  | _        n't        j"                  j                  d«      d	k(  | _        |j                  d
«      }	 | j%                  |||«       y# t&        t(        f$ r™}| j*                  r†	 t-        d«       t-        d|› d|› �«       t-        d| j.                  › d�«       t-        d«       | j%                  | j.                  d«       | j1                  «        Y d}~y# t2        $ r}||‚d}~ww xY w|‚d}~ww xY w)a¸  
        :param path_or_bytes: Filename or serialized ONNX or ORT format model in a byte string.
        :param sess_options: Session options.
        :param providers: Optional sequence of providers in order of decreasing
            precedence. Values can either be provider names or tuples of
            (provider name, options dict). If not provided, then all available
            providers are used with the default precedence.
        :param provider_options: Optional sequence of options dicts corresponding
            to the providers listed in 'providers'.

        The model type will be inferred unless explicitly set in the SessionOptions.
        To explicitly set:

        ::

            so = onnxruntime.SessionOptions()
            # so.add_session_config_entry('session.load_model_format', 'ONNX') or
            so.add_session_config_entry('session.load_model_format', 'ORT')

        A file extension of '.ort' will be inferred as an ORT format model.
        All other filenames are assumed to be ONNX format models.

        'providers' can contain either names or names and options. When any options
        are given in 'providers', 'provider_options' should not be used.

        The list of providers is ordered by precedence. For example
        `['CUDAExecutionProvider', 'CPUExecutionProvider']`
        means execute a node using `CUDAExecutionProvider`
        if capable, otherwise execute using `CPUExecutionProvider`.
        r    r‹   )r    NúUnable to load from type 'ú'Úread_config_from_modelÚORT_LOAD_CONFIG_FROM_MODELÚ1Údisabled_optimizersz(*************** EP Error ***************z	EP Error z when using rÞ   rß   z(****************************************)ÚsuperrG   r1   r  r€   rv   ÚosÚPathLikeÚfspathÚ_model_pathÚ_model_bytesÚbytesrñ   rÍ   r¢   Ú_sess_options_initialÚ_read_config_from_modelÚenvironÚ_create_inference_sessionr2   r0   rž   râ   rã   rÉ   r   )
rE   Úpath_or_bytesÚsess_optionsr–   r—   Úkwargsr?  ÚeÚfallback_errorÚ	__class__s
            €r   rG   zInferenceSession.__init__o  s­  ø€ ôL 	‰Ñ¬¨V¯Z©ZÐ8IÈ1Ó-MÓ)NÐRSÑ)SÐÔTä�m¤c¬2¯;©;Ð%7Ô8Ü!Ÿy™y¨Ó7ˆDÔØ $ˆDÕÜ˜¤uÔ-Ø#ˆDÔØ -ˆDÕäÐ8¼¸mÓ9LÐ8MÈQÐOÓPÐPà)ˆÔØ%1ˆÔ"Ø# vÑ-Ü+.¨vÐ6NÑ/OÓ+PÐTUÑ+UˆDÕ(ä+-¯:©:¯>©>Ð:VÓ+WÐ[^Ñ+^ˆDÔ(ð %Ÿj™jÐ)>Ó?Ðð	Ø×*Ñ*¨9Ð6FÐH[Õ\øÜœLÐ)ò 	Ø×$Ò$ð
0ÜÐDÔEÜ˜I a S¨°Y°KÐ@ÔAÜÐ,¨T×-EÑ-EÐ,FÀnÐUÔVÜÐDÔEØ×2Ñ2°4×3KÑ3KÈTÔRà×)Ñ)Ô+ÜøÜ ò 0Ø(¨aÐ/ûð0úð ˆGûð	ús7   Ä	D ÄGÄ,G Ä9A,F*Æ*	F;Æ3F6Æ6F;Æ;G Ç Gc                óh  — t        j                  «       }|r3t        d„ |D «       «      }t        d„ |D «       «      }|r|rt        d«      ‚d|v r9|r.t        d„ |D «       «      rt        d„ |D «       «      r
ddg| _        nNdg| _        nEd	|v r9|r.t        d
„ |D «       «      rt        d„ |D «       «      r
ddg| _        ndg| _        ndg| _        t        |||«      \  }}| j                  �3|s|r/| j                  j                  «       rt        j                  d«       | j                  r| j                  nt        j                  «       }| j                  ||||«       | j                  r-t        j                  || j                  d| j                  «      }n,t        j                  || j                  d| j                  «      }|€t!        «       }nt#        |t         «      st!        |«      }|j%                  |||«       || _        | j&                  j(                  | _        | j&                  j*                  | _        | j&                  j.                  | _        | j&                  j2                  | _        | j&                  j6                  | _        | j&                  j:                  | _        | j&                  j>                  | _         | j&                  jB                  | _"        | j&                  jG                  «       | _$        | j&                  jK                  «       | _&        | j&                  jN                  | _(        y )Nc              3  ó^   K  — | ]%  }|d k(  xs t        |t        «      xr |d   d k(  –— Œ' y­w©ÚTensorrtExecutionProviderr   N©r€   r’   r�   s     r   r„   z=InferenceSession._create_inference_session.<locals>.<genexpr>Á  sE   è ø€ ò ð ð Ð7Ñ7ò `Ü˜x¬Ó/Ò^°H¸Q±KÐC^Ñ4^ó`ñùó   ‚+-c              3  ó^   K  — | ]%  }|d k(  xs t        |t        «      xr |d   d k(  –— Œ' y­w©ÚNvTensorRTRTXExecutionProviderr   NrU  r�   s     r   r„   z=InferenceSession._create_inference_session.<locals>.<genexpr>Æ  sE   è ø€ ò #ð ð Ð<Ñ<ò eÜ˜x¬Ó/Òc°H¸Q±KÐCcÑ4cóeñ#ùrV  zhCannot enable both 'TensorrtExecutionProvider' and 'NvTensorRTRTXExecutionProvider' in the same session.rY  c              3  ó^   K  — | ]%  }|d k(  xs t        |t        «      xr |d   d k(  –— Œ' y­w©ÚCUDAExecutionProviderr   NrU  r�   s     r   r„   z=InferenceSession._create_inference_session.<locals>.<genexpr>Ô  óE   è ø€ ò ð !ð Ð 7Ñ7ò `Ü" 8¬UÓ3Ò^¸À¹ÐG^Ñ8^ó`ñùrV  c              3  ó^   K  — | ]%  }|d k(  xs t        |t        «      xr |d   d k(  –— Œ' y­wrX  rU  r�   s     r   r„   z=InferenceSession._create_inference_session.<locals>.<genexpr>Ù  sE   è ø€ ò ð !ð Ð @Ñ@ò iÜ" 8¬UÓ3Òg¸À¹ÐGgÑ8góiñùrV  r\  ÚCPUExecutionProviderrT  c              3  ó^   K  — | ]%  }|d k(  xs t        |t        «      xr |d   d k(  –— Œ' y­wr[  rU  r�   s     r   r„   z=InferenceSession._create_inference_session.<locals>.<genexpr>å  r]  rV  c              3  ó^   K  — | ]%  }|d k(  xs t        |t        «      xr |d   d k(  –— Œ' y­wrS  rU  r�   s     r   r„   z=InferenceSession._create_inference_session.<locals>.<genexpr>ê  sE   è ø€ ò ð !ð Ð ;Ñ;ò dÜ" 8¬UÓ3Òb¸À¹ÐGbÑ8bódñùrV  zÑSpecified 'providers'/'provider_options' when creating InferenceSession but SessionOptions has already been configured with providers. InferenceSession will only use the providers passed to InferenceSession().TF))r   Úget_available_providersÚanyr2   rã   r˜   r¢   Úhas_providersrr   rs   Úget_default_session_optionsÚ_register_ep_custom_opsrD  r8  rH  rE  Úsetr€   Úinitialize_sessionr�   Úsession_optionsÚinputs_metar¦   Úoutputs_metar©   Úoverridable_initializersr¬   Úinput_meminfosr²   Úoutput_meminfosrµ   Úinput_epdevicesr¹   Ú
model_metar¯   r½   r¼   rÀ   r¿   rü   Ú_profiling_start_time_ns)	rE   r–   r—   r?  Úavailable_providersÚhas_tensorrtÚhas_tensorrt_rtxri  rò   s	            r   rJ  z*InferenceSession._create_inference_session¼  s  € Ü×7Ñ7Ó9Ðñ Üñ ð !*ôó ˆLô
  #ñ #ð !*ô#ó  Ðñ
 Ñ 0Ü ð+óð ð
 ,Ð/BÑBáÜñ ð %.ôô ô
 ñ ð %.ôô ð -DÐE[Ð+\�Õ(à,BÐ+C�Õ(Ø(Ð,?Ñ?áÜñ ð %.ôô ô
 ñ ð %.ôô ð -DÐE[Ð+\�Õ(à,BÐ+C�Õ(à(>Ð'?ˆDÔ$ô 'HØÐ'Ð)<ó'
Ñ#ˆ	Ð#ð ×ÑÐ)©yÑ<LÐRV×RdÑRd×RrÑRrÔRtÜ�M‰Mð0ôð 15×0BÒ0B˜$×,Ò,Ì×HeÑHeÓHgˆà×$Ñ$ _°iÐAQÐSfÔgà×ÒÜ×%Ñ% o°t×7GÑ7GÈÈt×OkÑOkÓl‰Dä×%Ñ% o°t×7HÑ7HÈ%ÐQU×QmÑQmÓnˆDàÐ&Ü"%£%ÑÜÐ/´Ô5ä"%Ð&9Ó":Ðð 	×Ñ 	Ð+;Ð=PÔQàˆŒ
Ø!ŸZ™Z×7Ñ7ˆÔØ ŸJ™J×2Ñ2ˆÔØ!ŸZ™Z×4Ñ4ˆÔØ)-¯©×)LÑ)LˆÔ&Ø#Ÿz™z×8Ñ8ˆÔØ $§
¡
× :Ñ :ˆÔØ $§
¡
× :Ñ :ˆÔØŸ:™:×0Ñ0ˆÔØŸ*™*×2Ñ2Ó4ˆŒØ!%§¡×!@Ñ!@Ó!BˆÔØ(,¯
©
×(NÑ(NˆÕ%r   c                óZ   — t        | j                  «      D ]  }| j                  |«       Œ y)aÇ  Release every graph captured by the current session handle and unpin its IOBinding.

        A captured graph belongs to the ``C.InferenceSession`` that captured it, so it must be
        released before that handle is replaced. Otherwise the stale bookkeeping would reject an
        IOBinding created by the replacement session and a later ``release_captured_graph`` would
        act on the replacement session while unpinning the old binding.
        N)ÚsortedrŸ   r  )rE   r  s     r   Ú_release_captured_graphsz)InferenceSession._release_captured_graphs$  s.   € ô $*¨$×*GÑ*GÓ#Hò 	=ÐØ×'Ñ'Ð(;Õ<ñ	=r   c                ó  — | j                  «        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _	        d| _
        d| _        d| _        | j                  | _        | j                  ||«       y)z"release underlying session object.N)rw  r¢   r¦   r©   r¬   r²   rµ   r¹   r¯   r¼   r¿   rq  r�   rG  rJ  rÅ   s      r   rÄ   zInferenceSession._reset_session/  s‘   € ð 	×%Ñ%Ô'ð "ˆÔØ ˆÔØ!ˆÔØ)-ˆÔ&Ø#ˆÔØ $ˆÔØ $ˆÔØˆÔØˆŒØ!%ˆÔØ(,ˆÔ%ð ˆŒ
Ø!×7Ñ7ˆÔØ×&Ñ& yÐ2BÕCr   c                óð  — t        t        |«      «      D ]ß  }||   |v r"||   dk(  rt        j                  |||   «       nDt	        ||   t
        «      r1||   d   |v r'||   d   dk(  rt        j                  |||   d   «       ||   |v r"||   dk(  rt        j                  |||   «       Œ™t	        ||   t
        «      sŒ­||   d   |v sŒ¸||   d   dk(  sŒÄt        j                  |||   d   «       Œá y )NrT  r   r‹   rY  ÚNvTensorrtRTXExecutionProvider)Úranger�   r   Ú'register_tensorrt_plugins_as_custom_opsr€   r’   Ú.register_nv_tensorrt_rtx_plugins_as_custom_ops)rE   ri  r–   r—   rr  Úis         r   rf  z(InferenceSession._register_ep_custom_opsH  s  € Ü”s˜9“~Ó&ò 	cˆAØ˜‰|Ð2Ñ2°yÀ±|ÐGbÒ7bÜ×9Ñ9¸/ÐK[Ð\]ÑK^Õ_ä˜9 Q™<¬Ô/Ø˜a‘L ‘OÐ':Ñ:Ø˜a‘L ‘OÐ'BÒBä×9Ñ9¸/È9ÐUVÉ<ÐXYÉ?Ô[à˜‰|Ð2Ñ2°yÀ±|ÐGgÒ7gÜ×@Ñ@ÀÐRbÐcdÑReÕfä˜9 Q™<¬Õ/Ø˜a‘L ‘OÐ':Ò:Ø˜a‘L ‘OÐ'GÓGä×@Ñ@ÀÐR[Ð\]ÑR^Ð_`ÑRaÕbñ#	cr   )NNN)
rK  zstr | bytes | os.PathLikerL  zC.SessionOptions | Noner–   ú1Sequence[str | tuple[str, dict[Any, Any]]] | Noner—   úSequence[dict[Any, Any]] | Noneri   rj   rC   rh   )
r   r   r   r   rG   rJ  rw  rÄ   rf  Ú__classcell__)rP  s   @r   r8  r8  j  si   ø„ ñð 15ØGKØ<@ðKà0ðKð .ðKð Eð	Kð
 :ðKð 
õKóZfOóP	=óDö2cr   r8  c                ó$   ‡ — 	 	 	 	 	 	 	 	 dˆ fd„}|S )a³  
    Wraps a user's "get initializer location" function. The returned wrapper function adheres to the
    signature expected by ORT.

    Need this wrapper to:
      - Convert the `initializer_value` parameter from `C.OrtValue` to `onnxruntime.OrtValue`, which is more
        convenient for the user's function to use.
      - Allow the user's function to return the original `external_info` parameter (this wrapper makes a copy)
    c                ó¦   •—  ‰| t        |«      |«      }|�:||k(  r5t        j                  |j                  |j                  |j
                  «      }|S rC   )rf   r   ÚOrtExternalInitializerInfoÚfilepathÚfile_offsetÚ	byte_size)Úinitializer_nameÚinitializer_valueÚexternal_infoÚret_valÚget_initializer_location_funcs       €r   Ú%get_initializer_location_func_wrapperzYmake_get_initializer_location_func_wrapper.<locals>.get_initializer_location_func_wrapperj  sZ   ø€ ñ
 8UØœhÐ'8Ó9¸=ó8
ˆð Ð 7¨mÒ#;ô ×2Ñ2°7×3CÑ3CÀW×EXÑEXÐZa×ZkÑZkÓlˆGØˆr   )rˆ  rv   r‰  ú
C.OrtValuerŠ  ú#C.OrtExternalInitializerInfo | Noneri   r�  r'   )rŒ  r�  s   ` r   Ú*make_get_initializer_location_func_wrapperr�  ]  s4   ø€ ðØðà%ðð ;ðð 
-õ	ð 1Ð0r   c                  ó¾   — e Zd ZdZdddej
                  j                  ej                  j                  df	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z	ddd„Z
dd„Zdd„Zdd	„Zdd
„Zy)ÚModelCompilerag  
    This class is used to compile an ONNX model. A compiled ONNX model has EPContext nodes that each
    encapsulates a subgraph compiled/optimized for a specific execution provider.

    Refer to the EPContext design document for more information about EPContext models:
    https://onnxruntime.ai/docs/execution-providers/EP-Context-Design.html

        ::

            sess_options = onnxruntime.SessionOptions()
            sess_options.add_provider("SomeExecutionProvider", {"option1": "value1"})
            # Alternatively, allow ONNX Runtime to select the provider automatically given a policy:
            # sess_options.set_provider_selection_policy(onnxrt.OrtExecutionProviderDevicePolicy.PREFER_NPU)

            model_compiler = onnxruntime.ModelCompiler(sess_options, "input_model.onnx")
            model_compiler.compile_to_file("output_model.onnx")
    FNi   c	                óÆ  — d}	d}
t        |t        t        j                  f«      r#|st	        d«      ‚t        j
                  |«      }	nDt        |t        «      rt        |«      dk(  rt	        d«      ‚|}
nt        dt        |«      › d�«      ‚|rPt        |t        t        j                  f«      st        |«      }t        d|› d�«      ‚t        j
                  |«      }nd}|�|rt	        d	«      ‚t        |«      | _        nd| _        |	r-t        j                  ||	d
|||||| j                  «	      | _        yt        j                  ||
d|||||| j                  «	      | _        y)a	  
        Creates a ModelCompiler instance.

        :param sess_options: Session options containing the providers for which the model will be compiled.
            Refer to SessionOptions.add_provider() and SessionOptions.set_provider_selection_policy().
        :param input_model_path_or_bytes: The path to the input model file or bytes representing a serialized
            ONNX model.
        :param embed_compiled_data_into_model: Defaults to False. Set to True to embed compiled binary data into
            EPContext nodes in the compiled model.
        :param external_initializers_file_path: Defaults to None. Set to a path for a file that will store the
            initializers for non-compiled nodes.
        :param external_initializers_size_threshold: Defaults to 1024. Ignored if `external_initializers_file_path`
            is None or empty. Initializers larger than this threshold are stored in the external initializers file.
        :param flags: Additional boolean options to enable. Set this parameter to a bitwise OR of
            flags in onnxruntime.OrtCompileApiFlags.
        :param graph_optimization_level: The graph optimization level.
            Defaults to onnxruntime.GraphOptimizationLevel.ORT_DISABLE_ALL.
        :param get_initializer_location_func: Optional function called for every initializer to allow user to specify
            whether an initializer should be stored within the model or externally. Example:
            ```
                def get_initializer_location(
                    initializer_name: str,
                    initializer_value: onnxrt.OrtValue,
                    external_info: onnxrt.OrtExternalInitializerInfo | None,
                ) -> onnxrt.OrtExternalInitializerInfo | None:
                    byte_size = initializer_value.tensor_size_in_bytes()

                    if byte_size < 64:
                        return None  # Store small initializer within compiled model.

                    # Else, write initializer to new external file.
                    value_np = initializer_value.numpy()
                    file_offset = ext_init_file.tell()
                    ext_init_file.write(value_np.tobytes())
                    return onnxrt.OrtExternalInitializerInfo(initializer_file_path, file_offset, byte_size)
            ```
        NzInput model path is emptyr   z Input model bytes array is emptyr:  r;  z<Output external initializer filepath is of unexpected type 'Ú zoCannot initialize ModelCompiler with both `external_initializers_file_path` and `get_initializer_location_func`TF)r€   rv   rA  rB  r2   rC  rF  r�   rñ   rÍ   r�  r�  r   r’  Ú_model_compiler)rE   rL  Úinput_model_path_or_bytesÚembed_compiled_data_into_modelÚexternal_initializers_file_pathÚ$external_initializers_size_thresholdÚflagsÚgraph_optimization_levelrŒ  Úinput_model_pathÚinput_model_bytesÚarg_types               r   rG   zModelCompiler.__init__Ž  s}  € ð` 6:ÐØ*.ÐÜÐ/´#´r·{±{Ð1CÔDÙ,Ü Ð!<Ó=Ð=Ü!Ÿy™yÐ)BÓCÑÜÐ1´5Ô9ÜÐ,Ó-°Ò2Ü Ð!CÓDÐDØ 9ÑäÐ8¼Ð>WÓ9XÐ8YÐYZÐ[Ó\Ð\á*ÜÐ=ÄÄRÇ[Á[Ð?QÔRÜÐ ?Ó@�ÜÐ"^Ð_gÐ^hÐhiÐ jÓkÐkÜ.0¯i©iÐ8WÓ.XÑ+à.0Ð+à(Ð4Ù.Ü ð:óð ô :dØ-ó:ˆDÕ6ð :>ˆDÔ6áÜ#$§?¡?ØØ ØØ.Ø/Ø4ØØ(Ø×:Ñ:ó
$ˆDÕ ô $%§?¡?ØØ!ØØ.Ø/Ø4ØØ(Ø×:Ñ:ó
$ˆDÕ r   c                óØ   — |rMt        |t        t        j                  f«      st	        dt        |«      › d�«      ‚t        j                  |«      }| j                  j                  |«       y)aå  
        Compiles to an output file. If an output file path is not provided,
        the output file path is generated based on the input model path by replacing
        '.onnx' with '_ctx.onnx'. Ex: The generated output file is 'model_ctx.onnx' for
        an input model with path 'model.onnx'.

        Raises an 'InvalidArgument' exception if the compilation options are invalid.

        :param output_model_path: Defaults to None. The path for the output/compiled model.
        z/Output model's filepath is of unexpected type 'r;  N)	r€   rv   rA  rB  rñ   rÍ   rC  r•  Úcompile_to_file)rE   Úoutput_model_paths     r   r   zModelCompiler.compile_to_fileø  s^   € ñ ÜÐ/´#´r·{±{Ð1CÔDÜÐ"QÔRVÐWhÓRiÐQjÐjkÐ lÓmÐmÜ "§	¡	Ð*;Ó <ÐØ×Ñ×,Ñ,Ð->Õ?r   c                ó:   — | j                   j                  |«       y)a™  
        Registers a callback that receives external EPContext data during compilation.

        The ``OrtEpContextData`` view is valid only during the callback. Read large payloads in chunks with
        ``data.read(offset, length)``. ORT may invoke the callback concurrently, so synchronize shared state.

        :param write_func: Callback receiving the logical data name and a bounded data view.
        N)r•  Úset_ep_context_data_write_func)rE   Ú
write_funcs     r   r£  z,ModelCompiler.set_ep_context_data_write_func	  s   € ð 	×Ñ×;Ñ;¸JÕGr   c                ó8   — | j                   j                  «        y)zFClears a previously registered external EPContext data write callback.N)r•  Ú clear_ep_context_data_write_funcrO   s    r   r¦  z.ModelCompiler.clear_ep_context_data_write_func  s   € à×Ñ×=Ñ=Õ?r   c                ó6   — | j                   j                  «       S )zò
        Compiles to bytes representing the serialized compiled ONNX model.

        Raises an 'InvalidArgument' exception if the compilation options are invalid.

        :return: A bytes object representing the compiled ONNX model.
        )r•  Úcompile_to_bytesrO   s    r   r¨  zModelCompiler.compile_to_bytes  s   € ð ×#Ñ#×4Ñ4Ó6Ð6r   c                ó:   — | j                   j                  |«       y)a$  
        Compiles the input model and writes the serialized ONNX bytes to a stream using the provided write function.
        Raises an 'InvalidArgument' exception if the compilation options are invalid.
        :param write_function: A callable that accepts a bytes buffer to write.
        N)r•  Úcompile_to_stream)rE   Úwrite_functions     r   rª  zModelCompiler.compile_to_stream"  s   € ð 	×Ñ×.Ñ.¨~Õ>r   )rL  r1  r–  zstr | os.PathLike | bytesr—  r0  r˜  zstr | os.PathLike | Noner™  r1   rš  r1   r›  zC.GraphOptimizationLevelrŒ  z!GetInitializerLocationFunc | NonerC   )r¡  z
str | None)r¤  z)Callable[[str, C.OrtEpContextData], None]ri   rj   rh   )ri   rF  )r«  zCallable[[bytes], None])r   r   r   r   r   ÚOrtCompileApiFlagsr   ÚGraphOptimizationLevelÚORT_DISABLE_ALLrG   r   r£  r¦  r¨  rª  r'   r   r   r’  r’  {  s®   „ ñð, 05ØDHØ48Ø×)Ñ)×.Ñ.Ø=>×=UÑ=U×=eÑ=eØKOðhà&ðhð $=ðhð )-ð	hð
 *Bðhð /2ðhð ðhð #;ðhð (IóhôT@ó"	Hó@ó7ô?r   r’  c                  ó‚   — e Zd ZdZdd„Zdd„Zd„ Zdd„Zd„ Zd„ Z	d„ Z
d	„ Z	 	 	 	 	 dd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy
)rþ   zW
    This class provides API to bind input/output to a specified device, e.g. GPU.
    c                ó"  — |j                   | _        d|j                  «       v | _        | j                  j	                  «       | _        t        j                  |j                   «      | _        i | _	        i | _
        i | _        t        «       | _        y )NÚWebGpuExecutionProvider)r�   r7   r½   Ú_is_webgpu_sessionrØ   Ú _is_webgpu_graph_capture_enabledr   ÚSessionIOBindingr  Ú_numpy_obj_referencesÚ_bound_inputsÚ_bound_outputsrg  r  )rE   r  s     r   rG   zIOBinding.__init__0  sp   € ØŸ™ˆŒØ";¸w×?TÑ?TÓ?VÐ"VˆÔØ04·±×0]Ñ0]Ó0_ˆÔ-Ü×,Ñ,¨W¯]©]Ó;ˆŒØ%'ˆÔ"à9;ˆÔØ:<ˆÔä+.«5ˆÕr   c                ó–   — | j                   r=dj                  d„ t        | j                   «      D «       «      }t        d|› d|› d�«      ‚y )Nrq   c              3  ó2   K  — | ]  }t        |«      –— Œ y ­wrC   )rv   )r‚   Úgraph_ids     r   r„   z.IOBinding._reject_if_pinned.<locals>.<genexpr>>  s   è ø€ Ò\°œs 8Ÿ}Ñ\ùs   ‚zCannot z! while captured WebGPU graph(s) [zÒ] still reference this IOBinding. Replay re-issues the buffers recorded at capture, so a change here would not affect replay and releasing the buffers could invalidate it. Call release_captured_graph(id) first.)r  ru   rv  r2   )rE   r>   r  s      r   Ú_reject_if_pinnedzIOBinding._reject_if_pinned<  sU   € Ø×!Ò!Ø—Y‘YÑ\¼VÀD×DZÑDZÓ=[Ô\Ó\ˆFÜØ˜&˜Ð!BÀ6À(ð K4ð 4óð ð "r   c                ó¾   — t        t        | j                  j                  «       d„ ¬«      «      t        t        | j                  j                  «       d„ ¬«      «      fS )zSReturn bound OrtValues whose identity and lifetime must remain fixed during replay.c                ó   — | d   S ©Nr   r'   ©Úitems    r   ú<lambda>z.IOBinding._capture_signature.<locals>.<lambda>I  s
   € ÀdÈ1Ág€ r   )ry   c                ó   — | d   S r¾  r'   r¿  s    r   rÁ  z.IOBinding._capture_signature.<locals>.<lambda>J  s
   € ÀtÈAÁw€ r   )r’   rv  r¶  r^   r·  rO   s    r   r  zIOBinding._capture_signatureF  sL   € ô ”&˜×+Ñ+×1Ñ1Ó3Ñ9MÔNÓOÜ”&˜×,Ñ,×2Ñ2Ó4Ñ:NÔOÓPð
ð 	
r   c                óØ   — d| j                   fd| j                  ffD ]K  \  }}|j                  «       D ]3  \  }}|�|j                  rŒt	        d|› d|› dt
        › dt        › d�	«      ‚ ŒM y)	zNEvery binding participating in capture must be a fixed WebGPU device OrtValue.rÒ   ræ   Nz=WebGPU graph capture requires fixed WebGPU device OrtValues; z 'zw' is not one. Bind values created by this session or backed by an environment-registered shared allocator, or set the 'r×   z to run without capture.)r¶  r·  r^   r8   r2   r/   rÙ   )rE   ÚkindÚboundrw   rz   s        r   r  z$IOBinding._validate_capture_bindingsM  s–   € à$ d×&8Ñ&8Ð9¸HÀd×FYÑFYÐ;ZÐ[ò 		‰KˆD�%Ø$Ÿ{™{›}ò ‘��eØ�=¨×(?Ó(?Ü$ØWÐX\ÐW]ð ^Ø ˜6ð "ä8Ð9Ð9IÔJ`ÐIað b2ð2óð ññ		r   c                óš   — | j                  d«       || j                  |<   | j                  j                  ||«       d| j                  |<   y)z�
        bind an input to array on CPU
        :param name: input name
        :param arr_on_cpu: input values as a python array on CPU
        úrebind inputsN)r»  rµ  r  Ú
bind_inputr¶  )rE   rw   Ú
arr_on_cpus      r   Úbind_cpu_inputzIOBinding.bind_cpu_inputZ  sH   € ð 	×Ñ˜Ô/ð
 ,6ˆ×"Ñ" 4Ñ(Ø�‰×"Ñ" 4¨Ô4Ø#'ˆ×Ñ˜4Ò r   c                óÆ   — | j                  d«       | j                  j                  |t        j	                  ||«      j                  «       |||«       d| j                  |<   y)a  
        :param name: input name
        :param device_type: e.g. cpu, cuda, cann
        :param device_id: device id, e.g. 0
        :param element_type: input element type. It can be either numpy type (like numpy.float32) or an integer for onnx type (like onnx.TensorProto.BFLOAT16)
        :param shape: input shape
        :param buffer_ptr: memory pointer to input data
        rÇ  N)r»  r  rÈ  r   r  r  r¶  ©rE   rw   r   r	  r  r  Ú
buffer_ptrs          r   rÈ  zIOBinding.bind_inputi  sY   € ð 	×Ñ˜Ô/Ø�‰×"Ñ"ØÜ�N‰N˜;¨	Ó2×@Ñ@ÓBØØØô	
ð $(ˆ×Ñ˜4Ò r   c                ó¾   — t        || j                  d«       | j                  d«       | j                  j	                  ||j
                  «       || j                  |<   y)z\
        :param name: input name
        :param ortvalue: OrtValue instance to bind
        úbound torÇ  N)r?   r7   r»  r  Úbind_ortvalue_inputr_   r¶  ©rE   rw   r:   s      r   rÐ  zIOBinding.bind_ortvalue_input|  sL   € ô
 	1°¸4¿=¹=È*ÔUØ×Ñ˜Ô/Ø�‰×+Ñ+¨D°(×2DÑ2DÔEØ#+ˆ×Ñ˜4Ò r   c                ó8   — | j                   j                  «        y rC   )r  Úsynchronize_inputsrO   s    r   rÓ  zIOBinding.synchronize_inputs†  s   € Ø�‰×*Ñ*Õ,r   Nc                óf  — | j                  d«       |€?| j                  j                  |t        j	                  ||«      j                  «       «       nP|�|€t        d«      ‚| j                  j                  |t        j	                  ||«      j                  «       |||«       d| j                  |<   y)a“  
        :param name: output name
        :param device_type: e.g. cpu, cuda, cann, cpu by default
        :param device_id: device id, e.g. 0
        :param element_type: output element type. It can be either numpy type (like numpy.float32) or an integer for onnx type (like onnx.TensorProto.BFLOAT16)
        :param shape: output shape
        :param buffer_ptr: memory pointer to output data
        úrebind outputsNzQ`element_type` and `shape` are to be provided if pre-allocated memory is provided)r»  r  Úbind_outputr   r  r  r2   r·  rÌ  s          r   rÖ  zIOBinding.bind_output‰  s¦   € ð$ 	×ÑÐ/Ô0ð ÐØ�O‰O×'Ñ'ØÜ—‘˜{¨IÓ6×DÑDÓFõð
 Ð# u }Ü Ð!tÓuÐuØ�O‰O×'Ñ'ØÜ—‘˜{¨IÓ6×DÑDÓFØØØôð %)ˆ×Ñ˜DÒ!r   c                ó¾   — t        || j                  d«       | j                  d«       | j                  j	                  ||j
                  «       || j                  |<   y)z]
        :param name: output name
        :param ortvalue: OrtValue instance to bind
        rÏ  rÕ  N)r?   r7   r»  r  Úbind_ortvalue_outputr_   r·  rÑ  s      r   rØ  zIOBinding.bind_ortvalue_output´  sM   € ô
 	1°¸4¿=¹=È*ÔUØ×ÑÐ/Ô0Ø�‰×,Ñ,¨T°8×3EÑ3EÔFØ$,ˆ×Ñ˜DÒ!r   c                ó8   — | j                   j                  «        y rC   )r  Úsynchronize_outputsrO   s    r   rÚ  zIOBinding.synchronize_outputs¾  s   € Ø�‰×+Ñ+Õ-r   c                ó4  — | j                   j                  «       }t        |t        j                  «      st        d«      ‚g }t        t        |«      «      D ]?  }||   }|j                  t        ||j                  «       r| j                  nd¬«      «       ŒA |S )z¤
        Returns the output OrtValues from the Run() that preceded the call.
        The data buffer of the obtained OrtValues may not reside on CPU memory
        z?get_outputs() must return an instance of type 'OrtValueVector'.Nr  )r  rª   r€   r   rð   rñ   r{  r�   rÏ   rf   r8   r7   )rE   Úoutputsrö   Úindexr:   s        r   rª   zIOBinding.get_outputsÁ  sŠ   € ð
 —/‘/×-Ñ-Ó/ˆÜ˜'¤1×#3Ñ#3Ô4ÜÐ]Ó^Ð^ØˆÜœ3˜w›<Ó(ò 	ˆEØ˜u‘~ˆHØ�M‰MÜØØ-5×-GÑ-GÔ-I˜DŸMšMÈtôõð	ð ˆr   c                ó6   — | j                   j                  «       S )a`  Return the raw OrtValueVector of outputs from the Run() that preceded the call.

        The vector is a reference into this IOBinding (pybind ``reference_internal``), so it keeps the
        IOBinding alive, which in turn keeps the session alive. Device-resident outputs are therefore
        safe to hold past the session going out of scope.
        )r  rª   rO   s    r   Úget_outputs_as_ortvaluevectorz'IOBinding.get_outputs_as_ortvaluevectorÔ  s   € ð �‰×*Ñ*Ó,Ð,r   c                ó6   — | j                   j                  «       S )zCopy output contents to CPU.)r  Úcopy_outputs_to_cpurO   s    r   rá  zIOBinding.copy_outputs_to_cpuÝ  s   € à�‰×2Ñ2Ó4Ð4r   c                óŽ   — | j                  d«       | j                  j                  «        | j                  j	                  «        y )Nzclear input bindings)r»  r  Úclear_binding_inputsr¶  ÚclearrO   s    r   rã  zIOBinding.clear_binding_inputsá  s3   € Ø×ÑÐ5Ô6Ø�‰×,Ñ,Ô.Ø×Ñ× Ñ Õ"r   c                óŽ   — | j                  d«       | j                  j                  «        | j                  j	                  «        y )Nzclear output bindings)r»  r  Úclear_binding_outputsr·  rä  rO   s    r   ræ  zIOBinding.clear_binding_outputsæ  s3   € Ø×ÑÐ6Ô7Ø�‰×-Ñ-Ô/Ø×Ñ×!Ñ!Õ#r   )r  rš   )r>   rv   ri   rj   rh   )r   r   NNN)r   r   r   r   rG   r»  r  r  rÊ  rÈ  rÐ  rÓ  rÖ  rØ  rÚ  rª   rß  rá  rã  ræ  r'   r   r   rþ   rþ   +  si   „ ñó
1óò
óò(ò(ò&,ò-ð ØØØØó))òV-ò.òò&-ò5ò#ó
$r   rþ   c                  óP  — e Zd ZdZ	 	 d	 	 	 	 	 dd„Zedd„«       Zdd„Ze	 d 	 	 	 	 	 d!d„«       Z	ed"d„«       Z
e	 	 	 	 d#	 	 	 	 	 	 	 	 	 	 	 d$d„«       Zed%d	„«       Zd&d
„Zd'd„Zd(d„Zd)d„Zd(d„Zd'd„Zd'd„Zdd„Zdd„Zdd„Zdd„Zd*d„Zdd*d„Zddœd„Zd+d„Zed,d„«       Zd-d„Zy).rf   a  
    A data structure that supports all ONNX data formats (tensors and non-tensors) that allows users
    to place the data backing these on a device, for example, on a CUDA supported device.
    This class provides APIs to construct and deal with OrtValues.
    Nc                óx   — t        |t        j                  «      r|| _        || _        || _        y t        d«      ‚)Nz^`Provided ortvalue` needs to be of type `onnxruntime.capi.onnxruntime_pybind11_state.OrtValue`)r€   r   rf   r_   Ú
_numpy_objr7   r2   )rE   r:   Ú	numpy_objr  s       r   rG   zOrtValue.__init__ó  s;   € ô �h¤§
¡
Ô+Ø%ˆDŒNð (ˆDŒOà#ˆD�Mô Øpóð r   c                ó6   — | j                   j                  «       S )a?  Whether this value is backed by a WebGPU buffer.

        Resolved from the native OrtValue on every access and deliberately read-only: graph-capture
        validation and the copy-path checks below refuse host memory, so a settable attribute would
        let a CPU tensor pass itself off as a device tensor.
        )r_   r8   rO   s    r   r8   zOrtValue._is_webgpu_buffer  s   € ð �~‰~×/Ñ/Ó1Ð1r   c                ó   — | j                   S rC   )r_   rO   s    r   rî   zOrtValue._get_c_value  s   € Ø�~‰~Ðr   c          
     óÈ   —  | t         j                  j                  |t        j	                  |||«      j                  «       «      |j                  «       dk(  r|«      S d«      S )a  
        Factory method to construct an OrtValue (which holds a Tensor) from a given Numpy object
        A copy of the data in the Numpy object is held by the OrtValue only if the device is NOT cpu

        :param numpy_obj: The Numpy object to construct the OrtValue from
        :param device_type: e.g. cpu, cuda, cann, cpu by default
        :param device_id: device id, e.g. 0
        :param vendor_id: The device's PCI vendor id as an int or OrtDeviceVendorId. If provided, the device_type should be "gpu" or "npu".
        r   N)r   rf   Úortvalue_from_numpyr   r  r  Úlower)Úclsrê  r   r	  r
  s        r   rî  zOrtValue.ortvalue_from_numpy  sd   € ñ  Ü�J‰J×*Ñ*ØÜ—‘˜{¨I°yÓA×OÑOÓQóð %×*Ñ*Ó,°Ò5ˆIó
ð 	
ð
 <@ó
ð 	
r   c               óP   —  | t         j                  j                  ||«      |«      S )a	  
        This method creates an instance of OrtValue on top of the numpy array.
        No data copy is made and the lifespan of the resulting OrtValue should never
        exceed the lifespan of bytes object. The API attempts to reinterpret
        the data type which is expected to be the same size. This is useful
        when we want to use an ONNX data type that is not supported by numpy.

        :param data: numpy.ndarray.
        :param onnx_element_type: a valid onnx TensorProto::DataType enum value
        )r   rf   Ú"ortvalue_from_numpy_with_onnx_type)rð  ÚdataÚonnx_element_types      r   rò  z+OrtValue.ortvalue_from_numpy_with_onnx_type+  s$   € ñ ”1—:‘:×@Ñ@ÀÐGXÓYÐ[_Ó`Ð`r   c                ó  — |�„|dk7  s
|dk7  s|dk7  rt        j                  dd¬«       t        |t        «      r' | t        j
                  j                  |||«      «      S  | t        j
                  j                  |||«      «      S t        j                  |||«      j                  «       }t        |t        «      r' | t        j
                  j                  |||«      «      S  | t        j
                  j                  |||«      «      S )aß  
        Factory method to construct an OrtValue (which holds a Tensor) from given shape and element_type

        :param shape: List of integers indicating the shape of the OrtValue
        :param element_type: The data type of the elements. It can be either numpy type (like numpy.float32) or an integer for onnx type (like onnx.TensorProto.BFLOAT16).
        :param device_type: e.g. cpu, cuda, cann, cpu by default
        :param device_id: device id, e.g. 0
        :param vendor_id: The device's PCI vendor id as an int or OrtDeviceVendorId. If provided, the device type should be "gpu" or "npu".
        :param memory_info: An OrtMemoryInfo from an OrtEpDevice (e.g. via ep_device.memory_info(OrtDeviceMemoryType.HOST_ACCESSIBLE)). When provided, the allocator matching this memory info is used directly, which allows allocating HOST_ACCESSIBLE memory for zero-copy numpy interop. The device_type, device_id, and vendor_id parameters are ignored when memory_info is provided.
        r   r   r+   zOdevice_type, device_id, and vendor_id are ignored when memory_info is provided.rŠ   )Ú
stacklevel)rr   rs   r€   r1   r   rf   Ú1ortvalue_from_shape_and_onnx_type_for_memory_infoÚ,ortvalue_from_shape_and_type_for_memory_infor   r  r  Ú!ortvalue_from_shape_and_onnx_typeÚortvalue_from_shape_and_type)rð  r  r  r   r	  r
  Úmemory_infor  s           r   rú  z%OrtValue.ortvalue_from_shape_and_type9  s	  € ð* Ð"Ø˜eÒ# y°A¢~¸ÀbºÜ—‘ØeØ õô ˜,¬Ô,ÙÜ—J‘J×PÑPØØ$Ø#óóð ñ Ü—
‘
×GÑGØØ Øóóð ô —‘ ¨Y¸	ÓB×PÑPÓRˆô �l¤CÔ(ÙÜ—
‘
×<Ñ<ØØ Øóóð ñ Ü�J‰J×3Ñ3ØØØóó
ð 	
r   c                óh   —  | t         j                  j                  |j                  «       «      «      S )z¬
        The function will construct an OrtValue instance from a valid SparseTensor
        The new instance of OrtValue will assume the ownership of sparse_tensor
        )r   rf   Úort_value_from_sparse_tensorÚ_get_c_tensor)rð  Úsparse_tensors     r   rý  z%OrtValue.ort_value_from_sparse_tensory  s'   € ñ ”1—:‘:×:Ñ:¸=×;VÑ;VÓ;XÓYÓZÐZr   c                óH   — t        | j                  j                  «       «      S )zR
        The function will return SparseTensor contained in this OrtValue
        )ÚSparseTensorr_   Úas_sparse_tensorrO   s    r   r  zOrtValue.as_sparse_tensor�  s   € ô ˜DŸN™N×;Ñ;Ó=Ó>Ð>r   c                ó6   — | j                   j                  «       S )z¥
        Returns the address of the first element in the OrtValue's data buffer

        WebGPU buffers are opaque handles and do not expose a data pointer.
        )r_   Údata_ptrrO   s    r   r  zOrtValue.data_ptr‡  s   € ð �~‰~×&Ñ&Ó(Ð(r   c                óR   — | j                   j                  «       j                  «       S )zv
        Returns the name of the device where the OrtValue's data buffer resides e.g. cpu, cuda, cann, webgpu
        )r_   Údevice_namerï  rO   s    r   r  zOrtValue.device_name�  s    € ð �~‰~×)Ñ)Ó+×1Ñ1Ó3Ð3r   c                ó6   — | j                   j                  «       S )z?
        Returns the shape of the data in the OrtValue
        )r_   r  rO   s    r   r  zOrtValue.shape•  s   € ð �~‰~×#Ñ#Ó%Ð%r   c                ó6   — | j                   j                  «       S )zY
        Returns the data type of the data in the OrtValue. E.g. 'tensor(int64)'
        )r_   Ú	data_typerO   s    r   r	  zOrtValue.data_type›  ó   € ð �~‰~×'Ñ'Ó)Ð)r   c                ó6   — | j                   j                  «       S )zi
        Returns the proto type of the data in the OrtValue
        if the OrtValue is a tensor.
        )r_   r  rO   s    r   r  zOrtValue.element_type¡  s   € ð
 �~‰~×*Ñ*Ó,Ð,r   c                ó6   — | j                   j                  «       S )zl
        Returns the size of the data in the OrtValue in bytes
        if the OrtValue is a tensor.
        )r_   Útensor_size_in_bytesrO   s    r   r  zOrtValue.tensor_size_in_bytes¨  s   € ð
 �~‰~×2Ñ2Ó4Ð4r   c                ó6   — | j                   j                  «       S )zz
        Returns True if the OrtValue corresponding to an
        optional type contains data, else returns False
        )r_   Ú	has_valuerO   s    r   r  zOrtValue.has_value¯  s   € ð
 �~‰~×'Ñ'Ó)Ð)r   c                ó6   — | j                   j                  «       S )zT
        Returns True if the OrtValue contains a Tensor, else returns False
        )r_   Ú	is_tensorrO   s    r   r  zOrtValue.is_tensor¶  r
  r   c                ó6   — | j                   j                  «       S )zZ
        Returns True if the OrtValue contains a SparseTensor, else returns False
        )r_   Úis_sparse_tensorrO   s    r   r  zOrtValue.is_sparse_tensor¼  s   € ð �~‰~×.Ñ.Ó0Ð0r   c                ó6   — | j                   j                  «       S )z]
        Returns True if the OrtValue contains a Tensor Sequence, else returns False
        )r_   Úis_tensor_sequencerO   s    r   r  zOrtValue.is_tensor_sequenceÂ  s   € ð �~‰~×0Ñ0Ó2Ð2r   c                ó6   — | j                   j                  «       S )aW  
        Returns a Numpy object from the OrtValue.
        Valid only for OrtValues holding Tensors. Throws for OrtValues holding non-Tensors.
        Use accessors to gain a reference to non-Tensor objects such as SparseTensor
        WebGPU device values require explicit readback with
        :meth:`IOBinding.copy_outputs_to_cpu`.
        )r_   ÚnumpyrO   s    r   r  zOrtValue.numpyÈ  s   € ð �~‰~×#Ñ#Ó%Ð%r   c                ó�   — | j                  «       }|�t        j                  |||¬«      }|S |�t        j                  ||¬«      }|S )a`  
        Supports ``numpy.asarray(ortvalue)`` and ``numpy.array(ortvalue)`` via the
        `numpy __array__ protocol <https://numpy.org/devdocs/user/basics.interoperability.html>`_.

        Valid only for OrtValues holding Tensors on CPU.

        :param dtype: Optional numpy dtype to cast the result to.
        :param copy: Optional bool (numpy >= 2.0). If ``False``, a copy will
            only be made if necessary. If ``True``, a copy is always forced.
            If ``None`` (default), a copy will be made only if needed.
        :return: A numpy array with the same data as the OrtValue.
        )ÚdtypeÚcopy)r  )r  ÚnpÚarrayÚasarray)rE   r  r  Úarrs       r   Ú	__array__zOrtValue.__array__Ò  sO   € ð �j‰j‹lˆàÐô —(‘(˜3 e°$Ô7ˆCð ˆ
ð Ðô —*‘*˜S¨Ô.ˆCàˆ
r   ©Ústreamc               ó:   — | j                   j                  |¬«      S )ar  
        Returns a DLPack capsule representing the tensor (part of the
        `DLPack protocol <https://dmlc.github.io/dlpack/latest/>`_).

        This enables interoperability with other frameworks via
        ``from_dlpack(ortvalue)`` (e.g. ``torch.from_dlpack``,
        ``jax.dlpack.from_dlpack``, ``numpy.from_dlpack``).

        The OrtValue must hold a contiguous tensor. No data is copied;
        the consumer shares memory with this OrtValue, which must remain
        alive while the capsule is in use.
        WebGPU OrtValues cannot be exported through DLPack because their data
        is stored in opaque WebGPU buffers rather than CUDA-addressable memory.

        :param stream: Optional stream on which the tensor data is accessible.
            Currently unused; included for protocol compliance.
        :return: A PyCapsule holding a DLManagedTensor.
        r   )r_   Ú
__dlpack__)rE   r!  s     r   r#  zOrtValue.__dlpack__ì  s   € ð& �~‰~×(Ñ(°Ð(Ó7Ð7r   c                ó6   — | j                   j                  «       S )am  
        Returns ``(device_type, device_id)`` indicating where the tensor data
        resides (part of the `DLPack protocol
        <https://dmlc.github.io/dlpack/latest/>`_).

        WebGPU OrtValues do not expose a DLPack device.

        :return: Tuple of ``(device_type, device_id)`` as ints following DLPack
            ``DLDeviceType`` enum values.
        )r_   Ú__dlpack_device__rO   s    r   r%  zOrtValue.__dlpack_device__  s   € ð �~‰~×/Ñ/Ó1Ð1r   c               ó<  — d}t        |t        «      r|j                  «       dk(  }n2t        |d«      r&|j                  }t        |dt        |«      «      }|dv }t        |d«      r|j                  «       }n|} | t        j                  j                  ||«      «      S )aø  
        Construct an OrtValue from an object that implements the DLPack protocol.

        Accepts either:

        * An object with ``__dlpack__`` / ``__dlpack_device__`` methods
          (e.g. a PyTorch tensor, JAX array, or numpy array).
        * A raw DLPack PyCapsule (legacy path).

        Boolean tensors are automatically detected when the source object
        exposes a ``dtype`` attribute (numpy, PyTorch, etc.) or is an
        ``OrtValue``. For raw DLPack capsules where the original dtype cannot
        be inspected, bool tensors encoded as uint8 by older DLPack versions
        are not distinguishable from true uint8 tensors and will be imported
        as uint8.

        No data is copied; the new OrtValue shares memory with the source.

        :param data: A tensor object supporting the DLPack protocol, or a raw
            DLPack PyCapsule.
        :return: An OrtValue wrapping the tensor data.
        :raises TypeError: If the object does not provide a valid DLPack capsule.
        Fztensor(bool)r  rw   )r0  Úbool_z
torch.boolr#  )
r€   rf   r	  Úhasattrr  Úgetattrrv   r#  r   Úfrom_dlpack)rð  ró  Úis_boolÚ	dtype_objÚ
dtype_nameÚcapsules         r   r*  zOrtValue.from_dlpack  s�   € ð8 ˆÜ�dœHÔ%Ø—n‘nÓ&¨.Ñ8‰GÜ�T˜7Ô#ØŸ
™
ˆIô ! ¨F´C¸	³NÓCˆJØ Ð$CÐCˆGô �4˜Ô&Ø—o‘oÓ'‰GàˆGá”1—:‘:×)Ñ)¨'°7Ó;Ó<Ð<r   c                óÐ  — t        |t        «      rk| j                  |j                  k7  rt        d«      ‚t	        || j
                  «      st        d«      ‚| j                  j                  |j                  «       yt        |t        j                  «      st        d«      ‚|j                  j                  st        j                  |«      }| j                  j                  |«       y)a4  
        Update the OrtValue in place. The source data is copied over to the device
        memory backing the OrtValue. It can be used to update the input values for
        an InferenceSession with CUDA graph enabled or other scenarios where the
        OrtValue needs to be updated while the memory address can not be changed.

        :param data: The source data, which can be a Numpy array or another OrtValue.
            When an OrtValue is provided, data can be copied between devices (e.g.,
            GPU to GPU) without going through the CPU.
        ztWebGPU OrtValue copies require WebGPU source and destination values; use IOBinding.copy_outputs_to_cpu for readback.z>Session-scoped OrtValues must originate from the same session.Nz,data must be a numpy.ndarray or an OrtValue.)r€   rf   r8   r2   r<   r7   r_   Úupdate_inplacer  Úndarrayrñ   rš  Úc_contiguousÚascontiguousarray)rE   ró  s     r   r0  zOrtValue.update_inplace<  sµ   € ô �dœHÔ%Ø×%Ñ%¨×)?Ñ)?Ò?Ü ðFóð ô 3°4¸¿¹ÔGÜ Ð!aÓbÐbà�N‰N×)Ñ)¨$¯.©.Ô9Øä˜$¤§
¡
Ô+ÜÐJÓKÐKð �z‰z×&Ò&Ü×'Ñ'¨Ó-ˆDà�‰×%Ñ% dÕ+r   r3  )r:   rŽ  rê  znp.ndarray | Noner  zC.InferenceSession | None©ri   r0  )ri   rŽ  )r   r   r+   )r
  r6  rê  ú
np.ndarrayri   rf   )rô  r1   ró  r5  ri   rf   )r   r   r+   N)r  r5  r   rv   r	  r1   r
  r6  rû  zC.OrtMemoryInfo | Noneri   rf   )rÿ  r  ri   rf   )ri   r  rl   ©ri   rv   )ri   r5  ©ri   r5  )ri   ztuple[int, int])ri   rf   rh   )r   r   r   r   rG   Úpropertyr8   rî   Úclassmethodrî  rò  rú  rý  r  r  r  r  r	  r  r  r  r  r  r  r  r  r#  r%  r*  r0  r'   r   r   rf   rf   ì  sk  „ ñð (,Ø-1ð	àðð %ðð +ó	ð& ò2ó ð2óð àlnð
ØRið
Ø"ð
à	ò
ó ð
ð. òaó ðað ð
 !ØØ-/Ø.2ð=
àð=
ð ð	=
ð
 ð=
ð +ð=
ð ,ð=
ð 
ò=
ó ð=
ð~ ò[ó ð[ó?ó)ó4ó&ó*ó-ó5ó*ó*ó1ó3ó&ôð4 $(ô 8ó*2ð ò+=ó ð+=ôZ,r   rf   c                ó"   — | j                  «       S )zEReturn a session's WebGPU context id, or -1 when it has no WebGPU EP.)r9   r  s    r   Ú_session_webgpu_context_idr;  `  s   € à×$Ñ$Ó&Ð&r   c                ó|   — | D ]7  }|j                   r|j                  €Œ ||j                  «      dt        fvsŒ7 y y)a…  Whether any value provably belongs to a WebGPU context other than the default one.

    The environment data transfer resolves the default WebGPU context, so copying a buffer that
    belongs to a caller-supplied context would silently run on the wrong device. A value with no
    owning session cannot be attributed to a context and is treated as default-context, as is a
    session with no WebGPU EP.

    TODO: this can only attribute a value that carries session provenance, because every WebGPU
    allocation reports OrtDevice(GPU, VendorIds::NONE, 0) regardless of its context. Supporting a
    custom external WebGPU context requires the shared allocator and its data transfer to retain and
    use that external device instead of resolving WebGpuContextFactory::DefaultContext(), which
    would also let the transfer itself reject the copy instead of relying on this Python-side guard.
    r+   TF)r8   r7   Ú_DEFAULT_WEBGPU_CONTEXT_ID)r•   Úcontext_id_getterrz   s      r   Ú_has_foreign_webgpu_contextr?  e  sG   € ð" ò ˆØ×&Ò&¨%¯.©.Ð*@ØÙ˜UŸ^™^Ó,°RÔ9SÐ4TÒTÙð	ð
 r   c                óî   — t        g | ¢|¢«      rt        d«      ‚| D �cg c]  }|j                  «       ‘Œ }}|D �cg c]  }|j                  «       ‘Œ }}t        j                  |||«       yc c}w c c}w )a1  
    Copy tensor data from source OrtValue sequence to destination OrtValue sequence.

    WebGPU values belonging to the default context are supported in either direction. A value from a
    caller-supplied WebGPU context is not, because the shared data transfer is bound to the default
    context.
    z´copy_tensors cannot copy a WebGPU OrtValue that belongs to a custom WebGPU context because the shared data transfer is bound to the default context; use IOBinding readback instead.N)r?  r2   rî   r   Úcopy_tensors)ÚsrcÚdstr!  ÚsÚ	c_sourcesÚdÚc_dstss          r   rA  rA  ~  st   € ô # < S <¨3 <Ô0Üð ó
ð 	
ð
 ,/Ö/ a�—‘Õ!Ð/€IÐ/Ø(+Ö, 1ˆa�n‰nÕÐ,€FÐ,Ü‡N�N�9˜f fÕ-ùò 0ùÚ,s
   ŸA-¼A2c                  óH   — e Zd ZdZd„ Zd„ Zed
dd„«       Zd„ Zd„ Z	d„ Z
d„ Zy	)r   zD
    A data structure that exposes the underlying C++ OrtDevice
    c                ó\   — t        |t        j                  «      r|| _        yt	        d«      ‚)ú&
        Internal constructor
        z]`Provided object` needs to be of type `onnxruntime.capi.onnxruntime_pybind11_state.OrtDevice`N)r€   r   r   Ú_ort_devicer2   )rE   Úc_ort_devices     r   rG   zOrtDevice.__init__–  s,   € ô �l¤A§K¡KÔ0Ø+ˆDÕô Øoóð r   c                ó   — | j                   S )z8
        Internal accessor to underlying object
        )rK  rO   s    r   r  zOrtDevice._get_c_device¢  s   € ð ×ÑÐr   c           	     óì  — |dk  r¡t        | «      }|�Ot        t        j                  t        | «      t        j                  j	                  «       t        |«      |«      «      S t        t        j                  t        | «      t        j                  j	                  «       |«      «      S t        t        j                  t        | «      t        j                  j	                  «       t        |«      |«      «      S r¾  )r)   r   r   r   Údefault_memoryr1   )Úort_device_namer	  r
  Úalias_vendor_ids       r   r  zOrtDevice.make¨  sÊ   € à�qŠ=ô
 <¸OÓLˆOØÐ*Ü Ü—K‘KÜ+¨OÓ<ÜŸ™×2Ñ2Ó4Ü˜OÓ,Ø!ó	óð ô Ü—‘Ü'¨Ó8Ü—K‘K×.Ñ.Ó0Øóóð ô Ü—‘Ü'¨Ó8Ü—K‘K×.Ñ.Ó0Ü˜	“NØó	óð r   c                ó6   — | j                   j                  «       S rC   )rK  r	  rO   s    r   r	  zOrtDevice.device_idÎ  ó   € Ø×Ñ×)Ñ)Ó+Ð+r   c                ó6   — | j                   j                  «       S rC   )rK  r   rO   s    r   r   zOrtDevice.device_typeÑ  s   € Ø×Ñ×+Ñ+Ó-Ð-r   c                ó6   — | j                   j                  «       S rC   )rK  r
  rO   s    r   Údevice_vendor_idzOrtDevice.device_vendor_idÔ  rS  r   c                ó6   — | j                   j                  «       S rC   )rK  Úmem_typerO   s    r   Údevice_mem_typezOrtDevice.device_mem_type×  s   € Ø×Ñ×(Ñ(Ó*Ð*r   N)r+   )r
  r6  )r   r   r   r   rG   r  rn   r  r	  r   rV  rY  r'   r   r   r   r   ‘  s:   „ ñò
ò ð ó#ó ð#òJ,ò.ò,ó+r   r   c                  ó®   — e Zd ZdZdd„Zdd„Ze	 	 	 	 	 	 	 	 	 	 dd„«       Ze	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Zdd„Z	d„ Z
d„ Zd	„ Zd
„ Zd„ Zdd„Zdd„Zdd„Zy)r  zÙ
    A data structure that project the C++ SparseTensor object
    The class provides API to work with the object.
    Depending on the format, the class will hold more than one buffer
    depending on the format
    c                ó\   — t        |t        j                  «      r|| _        yt	        d«      ‚)rJ  z``Provided object` needs to be of type `onnxruntime.capi.onnxruntime_pybind11_state.SparseTensor`N)r€   r   r  Ú_tensorr2   )rE   rÿ  s     r   rG   zSparseTensor.__init__ã  s+   € ô �m¤Q§^¡^Ô4Ø(ˆD�Lô Øróð r   c                ó   — | j                   S rC   )r\  rO   s    r   rþ  zSparseTensor._get_c_tensorï  s   € Ø�|‰|Ðr   c           	     ón   —  | t         j                  j                  ||||j                  «       «      «      S )aª  
        Factory method to construct a SparseTensor in COO format from given arguments

        :param dense_shape: 1-D  numpy array(int64) or a python list that contains a dense_shape of the sparse tensor
            must be on cpu memory
        :param values: a homogeneous, contiguous 1-D numpy array that contains non-zero elements of the tensor
            of a type.
        :param coo_indices:  contiguous numpy array(int64) that contains COO indices for the tensor. coo_indices may
            have a 1-D shape when it contains a linear index of non-zero values and its length must be equal to
            that of the values. It can also be of 2-D shape, in which has it contains pairs of coordinates for
            each of the nnz values and its length must be exactly twice of the values length.
        :param ort_device: - describes the backing memory owned by the supplied nummpy arrays. Only CPU memory is
            suppored for non-numeric data types.

        For primitive types, the method will map values and coo_indices arrays into native memory and will use
        them as backing storage. It will increment the reference count for numpy arrays and it will decrement it
        on GC. The buffers may reside in any storage either CPU or GPU.
        For strings and objects, it will create a copy of the arrays in CPU memory as ORT does not support those
        on other devices and their memory can not be mapped.
        )r   r  Úsparse_coo_from_numpyr  )rð  Údense_shaper•   Úcoo_indicesÚ
ort_devices        r   r_  z"SparseTensor.sparse_coo_from_numpyò  s.   € ñ8 ”1—>‘>×7Ñ7¸ÀVÈ[ÐZd×ZrÑZrÓZtÓuÓvÐvr   c           
     óp   —  | t         j                  j                  |||||j                  «       «      «      S )a`  
        Factory method to construct a SparseTensor in CSR format from given arguments

        :param dense_shape: 1-D numpy array(int64) or a python list that contains a dense_shape of the
            sparse tensor (rows, cols) must be on cpu memory
        :param values: a  contiguous, homogeneous 1-D numpy array that contains non-zero elements of the tensor
            of a type.
        :param inner_indices:  contiguous 1-D numpy array(int64) that contains CSR inner indices for the tensor.
            Its length must be equal to that of the values.
        :param outer_indices:  contiguous 1-D numpy array(int64) that contains CSR outer indices for the tensor.
            Its length must be equal to the number of rows + 1.
        :param ort_device: - describes the backing memory owned by the supplied nummpy arrays. Only CPU memory is
            suppored for non-numeric data types.

        For primitive types, the method will map values and indices arrays into native memory and will use them as
        backing storage. It will increment the reference count and it will decrement then count when it is GCed.
        The buffers may reside in any storage either CPU or GPU.
        For strings and objects, it will create a copy of the arrays in CPU memory as ORT does not support those
        on other devices and their memory can not be mapped.
        )r   r  Úsparse_csr_from_numpyr  )rð  r`  r•   Úinner_indicesÚouter_indicesrb  s         r   rd  z"SparseTensor.sparse_csr_from_numpy  s;   € ñ: Ü�N‰N×0Ñ0ØØØØØ×(Ñ(Ó*óó
ð 	
r   c                ó6   — | j                   j                  «       S )zÌ
        The method returns a numpy array that is backed by the native memory
        if the data type is numeric. Otherwise, the returned numpy array that contains
        copies of the strings.
        )r\  r•   rO   s    r   r•   zSparseTensor.values7  s   € ð �|‰|×"Ñ"Ó$Ð$r   c                ó6   — | j                   j                  «       S )a}  
        The method will return coo representation of the sparse tensor which will enable
        querying COO indices. If the instance did not contain COO format, it would throw.
        You can query coo indices as:

        ::

            coo_indices = sparse_tensor.as_coo_view().indices()

        which will return a numpy array that is backed by the native memory.
        )r\  Úget_coo_datarO   s    r   Úas_coo_viewzSparseTensor.as_coo_view?  s   € ð �|‰|×(Ñ(Ó*Ð*r   c                ó6   — | j                   j                  «       S )a±  
        The method will return CSR(C) representation of the sparse tensor which will enable
        querying CRS(C) indices. If the instance dit not contain CSR(C) format, it would throw.
        You can query indices as:

        ::

            inner_ndices = sparse_tensor.as_csrc_view().inner()
            outer_ndices = sparse_tensor.as_csrc_view().outer()

        returning numpy arrays backed by the native memory.
        )r\  Úget_csrc_datarO   s    r   Úas_csrc_viewzSparseTensor.as_csrc_viewM  s   € ð �|‰|×)Ñ)Ó+Ð+r   c                ó6   — | j                   j                  «       S )a�  
        The method will return coo representation of the sparse tensor which will enable
        querying BlockSparse indices. If the instance did not contain BlockSparse format, it would throw.
        You can query coo indices as:

        ::

            block_sparse_indices = sparse_tensor.as_blocksparse_view().indices()

        which will return a numpy array that is backed by the native memory
        )r\  Úget_blocksparse_datarO   s    r   Úas_blocksparse_viewz SparseTensor.as_blocksparse_view\  s   € ð �|‰|×0Ñ0Ó2Ð2r   c                óf   — t        | j                  j                  |j                  «       «      «      S )a†  
        Returns a copy of this instance on the specified cuda device

        :param ort_device: with name 'cuda' and valid gpu device id

        The method will throw if:

        - this instance contains strings
        - this instance is already on GPU. Cross GPU copy is not supported
        - CUDA is not present in this build
        - if the specified device is not valid
        )r  r\  Úto_cudar  )rE   rb  s     r   rr  zSparseTensor.to_cudaj  s'   € ô ˜DŸL™L×0Ñ0°×1IÑ1IÓ1KÓLÓMÐMr   c                ó.   — | j                   j                  S )z7
        Returns a OrtSparseFormat enumeration
        )r\  rt   rO   s    r   rt   zSparseTensor.formaty  s   € ð �|‰|×"Ñ"Ð"r   c                ó6   — | j                   j                  «       S )zZ
        Returns a numpy array(int64) containing a dense shape of a sparse tensor
        )r\  r`  rO   s    r   r`  zSparseTensor.dense_shape  s   € ð �|‰|×'Ñ'Ó)Ð)r   c                ó6   — | j                   j                  «       S )zH
        Returns a string data type of the data in the OrtValue
        )r\  r	  rO   s    r   r	  zSparseTensor.data_type…  s   € ð �|‰|×%Ñ%Ó'Ð'r   c                óR   — | j                   j                  «       j                  «       S )zj
        Returns the name of the device where the SparseTensor data buffers reside e.g. cpu, cuda
        )r\  r  rï  rO   s    r   r  zSparseTensor.device_name‹  s    € ð �|‰|×'Ñ'Ó)×/Ñ/Ó1Ð1r   N)rÿ  úC.SparseTensor)ri   rw  )
r`  únpt.NDArray[np.int64]r•   r5  ra  rx  rb  r   ri   r  )r`  rx  r•   r5  re  rx  rf  rx  rb  r   ri   r  r7  )ri   rx  r6  )r   r   r   r   rG   rþ  r9  r_  rd  r•   rj  rm  rp  rr  rt   r`  r	  r  r'   r   r   r  r  Û  sÙ   „ ñó
óð ðwà*ðwð ðwð +ð	wð
 ðwð 
òwó ðwð: ð$
à*ð$
ð ð$
ð -ð	$
ð
 -ð$
ð ð$
ð 
ò$
ó ð$
óL%ò+ò,ò3òNò#ó*ó(ô2r   r  )r   rv   ri   r1   )r   rv   ri   zOrtDeviceVendorId | Nonerl   r4  rh   )r–   r  r—   r€  r|   r2  )rŒ  ÚGetInitializerLocationFuncri   Ú!GetInitializerLocationWrapperFunc)r  zC.InferenceSessionri   r1   )r•   r4  ri   r0  rC   )rB  r4  rC  r4  ri   rj   )/Ú
__future__r   rŒ   Úcollections.abcrA  Útypingrr   r  r   r   Úenumr   r   r  r  Úonnxruntime.capir   r   ÚTYPE_CHECKINGÚnumpy.typingÚnptr   r   r)   r/   rÙ   r5   r<   r?   rA   r˜   rš   r8  r�  r’  rþ   rf   r=  r;  r?  rA  r   r  rv   r„  ry  rz  r'   r   r   ú<module>rƒ     s±  ðõ
 #ã Û Û 	Û Û Û ß .Ý Ý ã å /à	×ÒÝóCô&
˜ô 
ó
ð  .Ð àÐ óvó vóc÷1Mñ 1MðhPZØ@ðPZà5ðPZð ,óPZ÷fqpñ qpôhpc�wô pcðf1Ø#=ð1à&ó1÷<m?ñ m?÷`~$ñ ~$÷Bn,ñ n,ðb Ð ó'ð 1ðØðð 
óô2.÷&G+ñ G+÷Tt2ñ t2ðp &Øˆ(�A×0Ñ0°4Ñ7Ð8¸!×:VÑ:VÐY]Ñ:]Ð]ñÐ ð
 %-Øˆ!�*‰*�a×2Ñ2°TÑ9Ð:¸A×<XÑ<XÐ[_Ñ<_Ð_ñ%Ñ !r   