+
    åûjv(  ã                  óŽ   € R t ^ RIHt ^ RIt^ RIHtHtHt ^ RIH	t	 ^ RIH
t ^ RIHtHt RR.t ! R	 R]]4      tR
R/R R lltR# )a³  Run one ONNX model with ONNX Runtime, given as a ``ModelProto``, a file, a URL or an ``hf://`` name.

Which function or class to use:

- One model with the default CPU session and cache: :func:`~kornia.onnx.load`.
- One model with chosen execution providers, session options, cache directory or IR/opset conversion:
  :class:`ONNXModule`.
- Several models run in sequence as one graph: :class:`~kornia.onnx.sequential.ONNXSequential`.
)ÚannotationsN)ÚAnyÚOptionalÚUnion)Úonnx)Úonnxruntime)Ú	ONNXMixinÚONNXRuntimeMixinÚ
ONNXModuleÚloadc                  óv   a € ] tR t^(tRtRRR/R R llltRR V 3R llltR V 3R	 lltRR
 V 3R llltRt	V ;t
# )r
   a  Run one ONNX model with ONNX Runtime and return its outputs as numpy arrays.

``module = ONNXModule(op)`` loads ``op`` and opens an ONNX Runtime session on it. ``outputs = module(*inputs)``
takes one numpy array or CPU torch tensor per graph input, in the order of ``get_session().get_inputs()``, and
returns a list of numpy arrays. The session runs on the CPU unless ``providers`` or an ``as_*()`` method such as
``as_cuda()`` selects another provider; the inputs stay in host memory either way.

Args:
    op: One ONNX model: an ONNX ModelProto object, or a file path as ``str`` or :class:`os.PathLike` (a path
        object always names a local file). A ``str`` can also be an HTTP(S) URL or an ``hf://<folder>/<name>``
        name of the `kornia/ONNX_models <https://huggingface.co/kornia/ONNX_models>`_ repository, such as
        ``"hf://operators/kornia.color.gray.RgbToGrayscale"``: ``hf://`` and a repository file path without
        ``.onnx``, as :meth:`~kornia.onnx.utils.ONNXLoader.list_operators` and
        :meth:`~kornia.onnx.utils.ONNXLoader.list_models` print the paths.
    providers: A list of execution providers for ONNXRuntime
        (e.g., ['CUDAExecutionProvider', 'CPUExecutionProvider']). A provider that the installed onnxruntime
        build does not offer is skipped with onnxruntime's ``UserWarning``; the session runs on the CPU if none
        is left. If None, the CPU.
    session_options: ONNX Runtime ``SessionOptions``, used as given. If None, the session uses
        ``ORT_ENABLE_EXTENDED`` graph optimizations.
    cache_dir: The directory where downloaded ONNX models (``hf://`` names and URLs) are cached, as
        :meth:`~kornia.onnx.utils.ONNXLoader.load_model` lays it out. If None,
        ``kornia.config.kornia_config.hub_onnx_dir`` (``.kornia_hub/onnx_models`` under the working directory).
    target_ir_version: The IR version to convert the model to. If None, the model keeps its IR version.
    target_opset_version: The OPSET version to convert the model to. If None, the model keeps its OPSET version.
    force_download: If True, an ``hf://`` name or a URL is downloaded again, and replaces the cached file, even
        when it is cached. By default a cached file is used as it is, however old, and one that does not load
        fails every time until it is deleted. It has no effect on a model object or a path to a local file.

Raises:
    TypeError: If ``op`` is not a ModelProto, a ``str`` or an :class:`os.PathLike`; ``bytes`` raise it too. On a
        call, if an input is a torch tensor of a dtype numpy has not, such as bfloat16 or float8.
    ValueError: If ``op`` names a local file that does not exist. On a call, if an input is a torch tensor on
        another device than the CPU.

Note:
    Given an ``onnx.ModelProto``, the module holds that object itself, not a copy, unless a target version
    converts it: with no target, or with a target the model already has, ``module.op is op``. Whatever edits the
    wrapped graph in place, such as :meth:`add_metadata`, then changes the caller's model too. Pass a copy
    (``copy.deepcopy(op)``) to keep the original unchanged.

See Also:
    - :func:`~kornia.onnx.load`: the same module from one argument, with the default CPU session and cache.
    - :class:`~kornia.onnx.sequential.ONNXSequential`: several models merged into one graph and one session.
    - :class:`~kornia.onnx.utils.ONNXLoader`: the ``onnx.ModelProto`` alone, without a session.

Example:
    >>> import numpy as np
    >>> from onnx import TensorProto, helper
    >>> from kornia.onnx import ONNXModule
    >>> graph = helper.make_graph(
    ...     [helper.make_node("Relu", ["input"], ["output"])], "relu",
    ...     [helper.make_tensor_value_info("input", TensorProto.FLOAT, [None, 3])],
    ...     [helper.make_tensor_value_info("output", TensorProto.FLOAT, [None, 3])])
    >>> model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 17)], ir_version=8)
    >>> module = ONNXModule(model)
    >>> module(np.array([[-1.0, 2.0, -3.0]], dtype=np.float32))
    [array([[0., 2., 0.]], dtype=float32)]

Úforce_downloadFc               ó8   € V ^8„  d   QhRRRRRRRRR	R
RR
RRRR/# )é   Úopú(Union[onnx.ModelProto, str, os.PathLike]Ú	providerszOptional[list[str]]Úsession_optionszOptional[ort.SessionOptions]Ú	cache_dirzOptional[str]Útarget_ir_versionzOptional[int]Útarget_opset_versionr   ÚboolÚreturnÚNone© )Úformats   "ÚNC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\onnx\module.pyÚ__annotate__ÚONNXModule.__annotate__f   sZ   € ÷ *ñ *à4ð*ð 'ð*ð 6ð	*ð
 !ð*ð )ð*ð ,ð*ð ð*ð 
ñ*ó    c               	óÒ   € V P                  WVR 7      V n        Vf   Ve#   V P                  V P                  WVR7      V n        V P                  W#R7      pV P	                  VR7       R# )©r   N)r   r   )r   r   )Úsession)Ú_load_opr   Ú_onnx_version_conversionÚcreate_sessionÚset_session)	Úselfr   r   r   r   r   r   r   r"   s	   &&&&&&&$ r   Ú__init__ÚONNXModule.__init__f   sk   € ð —-‘- ¸n�-ÓMˆŒØÒ(Ð,@Ò,LØ×3Ñ3Ø—‘Ð+<ð 4ó ˆDŒGð ×%Ñ%°	Ð%Ó[ˆØ×Ñ ÐÖ)r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   zlist[str] | Noner   z
Any | Noner   zort.InferenceSessionr   )r   s   "r   r   r   y   s)   € ÷ Lñ LØ)ðLØCMðLà	ñLr   c                ó8   <€ \         SV `  V P                  W4      # )a¨  Create an ONNX Runtime session for the wrapped model graph, without making it the module's session.

Pass the result to ``set_session`` to run the module on it.

Args:
    providers: Ordered list of ONNX Runtime execution providers, such as ``"CUDAExecutionProvider"`` followed
        by ``"CPUExecutionProvider"``. A provider the installed onnxruntime build does not offer is skipped
        with onnxruntime's ``UserWarning``. If None, the CPU.
    session_options: ONNX Runtime ``SessionOptions``, used as given. If None, ``ORT_ENABLE_EXTENDED`` graph
        optimizations.

Returns:
    ONNX Runtime inference session bound to ``self.op``, the wrapped
    ONNX model graph.
)ÚsuperÚ_create_sessionr   )r'   r   r   Ú	__class__s   &&&€r   r%   ÚONNXModule.create_sessiony   s   ø€ ô$ ‰wÑ& t§w¡w°	ÓKÐKr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Ú	file_pathÚstrÚkwargsr   r   r   r   )r   s   "r   r   r   �   s!   € ÷ =ñ = ð =¨sð =°tñ =r   c                ó<   <€ \         SV `  ! V P                  V3/ VB # )zÝSave the wrapped ONNX model graph to an ``.onnx`` file with ``onnx.save``.

Args:
    file_path: Destination path for the ``.onnx`` file.
    kwargs: Keyword arguments of ``onnx.save``, such as ``save_as_external_data``.
)r,   Ú_exportr   )r'   r1   r3   r.   s   &&,€r   ÚexportÚONNXModule.export�   s   ø€ ô ‰wŠ˜tŸw™w¨	Ñ<°VÑ<Ð<r   c               ó    € V ^8„  d   QhRRRR/# )r   Úadditional_metadatazOptional[list[tuple[str, str]]]r   zonnx.ModelProtor   )r   s   "r   r   r   –   s    € ÷ Cñ CÐ0Oð CÐ[jñ Cr   c                ó8   <€ \         SV `  V P                  V4      # )aƒ  Attach metadata entries to the wrapped ONNX model graph.

The metadata is written into the wrapped graph in place, as :func:`~kornia.onnx.utils.add_metadata` writes
it. When the module was built from an ``onnx.ModelProto``, the graph is the caller's own object unless a
target version converted it; see the note of :class:`ONNXModule`. The running session keeps the metadata it
was created with; :meth:`export` saves the new entries.

Args:
    additional_metadata: Optional list of ``(key, value)`` string pairs
        to store in the ONNX model metadata properties.

Returns:
    The wrapped ONNX model graph after metadata has been added.
)r,   Ú_add_metadatar   )r'   r9   r.   s   &&€r   Úadd_metadataÚONNXModule.add_metadata–   s   ø€ ô ‰wÑ$ T§W¡WÐ.AÓBÐBr   )r   )NNNNN)NN)N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r(   r%   r6   r<   Ú__static_attributes__Ú__classcell__)r.   s   @r   r
   r
   (   sE   ø† ñ;ñz*ð  %÷*ð *÷&Lò L÷(=ð =÷C÷ Cð Cr   r   Fc               ó$   € V ^8„  d   QhRRRRRR/# )r   Ú
model_namer   r   r   r   r
   r   )r   s   "r   r   r   ¨   s)   € ÷ Añ AÐ=ð AÐRVð AÐcmñ Ar   c               ó   € \        WR7      # )a¦  Load one ONNX model into an :class:`~kornia.onnx.module.ONNXModule` on a CPU session.

``load(name, force_download=f)`` is ``ONNXModule(name, force_download=f)``: one model on a CPU session with the
default cache.

Args:
    model_name: The model to load, as the ``op`` argument of :class:`~kornia.onnx.module.ONNXModule` takes it: an
        ONNX ModelProto object, a local file path, an HTTP(S) URL or an ``hf://<folder>/<name>`` name.
    force_download: If True, download the model again and replace the cached file, even when it is cached.

Returns:
    The :class:`~kornia.onnx.module.ONNXModule`.

Raises:
    TypeError: If ``model_name`` is not a ModelProto, a ``str`` or an :class:`os.PathLike`.
    ValueError: If ``model_name`` names a local file that does not exist.

Note:
    Given an ``onnx.ModelProto``, the module holds that object itself; see the note of
    :class:`~kornia.onnx.module.ONNXModule`.

See Also:
    - :class:`~kornia.onnx.module.ONNXModule`: the same module with execution providers, session options, a cache
      directory and version conversion.
    - :meth:`~kornia.onnx.utils.ONNXLoader.load_model`: the ``onnx.ModelProto`` alone, without a session.

r!   )r
   )rF   r   s   &$r   r   r   ¨   s   € ô8 �jÔ@Ð@r   )rB   Ú
__future__r   ÚosÚtypingr   r   r   Úkornia.core.externalr   r   ÚortÚkornia.core.mixin.onnxr   r	   Ú__all__r
   r   r   r   r   Ú<module>rO      sT   ðñ$õ #ã 	ß 'Ñ 'å %Ý 3ß >à˜Ð
 €ô}C�Ð,ô }Cð@AÐY^÷ Añ Ar   