+
    åûj‡3  ã                  óx   € 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.t ! R R]]4      tR# )	a  Chain several ONNX models into one merged graph and run it with one ONNX Runtime session.

Which class to use:

- Models run one after another, the outputs of each feeding the inputs of the next: :class:`ONNXSequential`.
- One model: :class:`~kornia.onnx.module.ONNXModule`.
)ÚannotationsN)ÚAnyÚOptionalÚUnion)Úonnx)Úonnxruntime)Ú	ONNXMixinÚONNXRuntimeMixinÚONNXSequentialc                  óÂ   a € ] tR t^&tRtRRRRRRRRRRR	RR
RRR/R R lltR	RR
R/R V 3R llltRR V 3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<  Chain several ONNX models into one graph and run it with one ONNX Runtime session.

``seq = ONNXSequential(model_a, model_b, ...)`` merges the models into one graph and opens one session on it. Each
joint connects the output named ``"output"`` to the input named ``"input"`` unless ``io_maps`` says otherwise, and
an output that feeds nothing stays a graph output. ``outputs = seq(*inputs)`` takes one input per unconnected
graph input, as :class:`~kornia.onnx.module.ONNXModule` does, and returns a list of numpy arrays. The names of
model ``i`` get the prefix ``K`` and ``i`` in two digits (``K00-input``, ``K01-output``). The models passed in are
not modified.

Args:
    *args: The ONNX models, in the order they run, each as :class:`~kornia.onnx.module.ONNXModule` takes it: an
        ONNX ModelProto object, a file path as ``str`` or :class:`os.PathLike` (a path object always names a
        local file), or a ``str`` HTTP(S) URL or ``hf://<folder>/<name>`` name.
    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.
    io_maps: An optional list with one list of ``(output, input)`` name pairs per joint between consecutive
        models: ``io_maps[0]`` connects outputs of the first model to inputs of the second, ``io_maps[1]`` the
        second to the third, and so on, as in ``[[("out_a", "in_b")], [("out_b", "in_c")]]`` for three models.
        Each entry may be any iterable of pairs (a ``zip``, ``dict.items()``, ...), and ``io_maps`` anything
        indexed by the joint; entries past the last joint are not read.
    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).
    auto_ir_version_conversion: If True, convert the models to one IR version and one OPSET version before
        combining them: IR version 9, and the highest OPSET version among the models, to which the others are
        converted up.
    target_ir_version: The IR version to convert every model to before combining them, whether or not
        `auto_ir_version_conversion` is set. If None, the models keep their IR versions, unless
        `auto_ir_version_conversion` converts them to 9.
    target_opset_version: The OPSET version to convert every model to before combining them, whether or not
        `auto_ir_version_conversion` is set. If None, the models keep their OPSET versions, unless
        `auto_ir_version_conversion` converts them to the highest among them. A conversion that fails raises the
        error of the ONNX version converter, of ``onnx.checker`` or of ONNX Runtime.
    force_download: If True, every ``hf://`` name and 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 a model is not a ModelProto, a ``str`` or an :class:`os.PathLike`.
    ValueError: If no model is given, if a local file does not exist, if a joint, set by ``io_maps`` or by
        default, names an output or input a model does not have, if ``io_maps`` has no entry for a joint or an
        ``io_maps`` entry is not name pairs, or if the models differ in IR version or opset and no conversion makes
        them agree.

Warns:
    UserWarning: If an output and the input it feeds have different tensor element types; declared dimensions are
        not compared.

See Also:
    - :class:`~kornia.onnx.module.ONNXModule`: one model, with its own input and output names.
    - :func:`~kornia.onnx.utils.io_name_conversion`: rename a model's inputs and outputs to ``"input"`` and
      ``"output"``, so that it chains without ``io_maps``.

Example:
    >>> import numpy as np
    >>> from onnx import TensorProto, helper
    >>> from kornia.onnx import ONNXSequential
    >>> def unary(op):
    ...     graph = helper.make_graph(
    ...         [helper.make_node(op, ["input"], ["output"])], op,
    ...         [helper.make_tensor_value_info("input", TensorProto.FLOAT, [None, 3])],
    ...         [helper.make_tensor_value_info("output", TensorProto.FLOAT, [None, 3])])
    ...     return helper.make_model(graph, opset_imports=[helper.make_opsetid("", 17)], ir_version=8)
    >>> seq = ONNXSequential(unary("Neg"), unary("Relu"))
    >>> [i.name for i in seq.get_session().get_inputs()], [o.name for o in seq.get_session().get_outputs()]
    (['K00-input'], ['K01-output'])
    >>> seq(np.array([[-1.0, 2.0, -3.0]], dtype=np.float32))
    [array([[1., 0., 3.]], dtype=float32)]

Ú	providersNÚsession_optionsÚio_mapsÚ	cache_dirÚauto_ir_version_conversionFÚtarget_ir_versionÚtarget_opset_versionÚforce_downloadc               ó@   € V ^8„  d   QhRRRRRRRRR	R
RRRRRRRRRR/
# )é   Úargsz(Union[onnx.ModelProto, str, os.PathLike]r   zOptional[list[str]]r   zOptional[ort.SessionOptions]r   ú%Optional[list[list[tuple[str, str]]]]r   zOptional[str]r   Úboolr   úOptional[int]r   r   ÚreturnÚNone© )Úformats   "ÚRC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\onnx\sequential.pyÚ__annotate__ÚONNXSequential.__annotate__r   sn   € ÷ *ñ *à7ð*ð 'ð*ð 6ð	*ð
 7ð*ð !ð*ð %)ð*ð )ð*ð ,ð*ð ð*ð 
ñ*ó    c          	     	ó„  € V P                   ! V	R VRV/ V n        V'       d%   V P                  ! V P                  RVRV/ V n        M:Vf   Ve3   V P                   U
u. uF  p
V P                  W¦VR7      NK  	  up
V n        V P	                  VR7      V n        V P                  WR7      pV P                  VR7       R# u up
i )	r   r   r   r   N©r   r   )r   )r   r   )Úsession)Ú	_load_opsÚ	operatorsÚ_auto_version_conversionÚ_onnx_version_conversionÚcombineÚ_combined_opÚcreate_sessionÚset_session)Úselfr   r   r   r   r   r   r   r   r   Úopr$   s   &$$$$$$$$*  r   Ú__init__ÚONNXSequential.__init__r   sÖ   € ð Ÿš¨Ðb¸ÐbÐSaÑbˆŒß%Ø!×:Ò:Ø—‘ðØ3DðØ[oñˆD�Nð Ò*Ð.BÒ.Nð Ÿ.š.ó	ñ )�Bð ×-Ñ-ØÐRfð .ö ñ )ñ	ˆDŒNð !ŸL™L°˜LÓ9ˆÔØ×%Ñ%°	Ð%Ó[ˆØ×Ñ ÐÖ)ùòs   ÁB=c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r   úonnx.ModelProtor   r   r   r   zlist[onnx.ModelProto]r   )r   s   "r   r   r    �   s2   € ÷ ñ àðð )ðð ,ð	ð
 
ñr!   c               óþ   <€ Vf   ^	pVf@   \        V P                  V4       Uu. uF
  qDf   K  VNK  	  ppV'       d   \        V4      MRp. pV F%  p\        SV `  WqVR7      pVP                  V4       K'  	  V# u upi )a¿  Automatic conversion of the model's IR/OPSET version to the given target version.

If `target_ir_version` is not provided, the model is converted to 9 by default.
If `target_opset_version` is not provided, the models are converted to the highest OPSET version among
them.

Args:
    args: List of operations to convert.
    target_ir_version: The target IR version to convert to.
    target_opset_version: The target OPSET version to convert to.

Nr#   )ÚmapÚ_opset_versionÚmaxÚsuperr(   Úappend)	r-   r   r   r   ÚversionÚversionsÚop_listr.   Ú	__class__s	   &$$*    €r   r'   Ú'ONNXSequential._auto_version_conversion�   sŽ   ø€ ð$ Ò$Ø !ÐØÒ'Ü/2°4×3FÑ3FÈÔ/MÓeÑ/M GŸ˜Ñ/MˆHÐeß4<¤3 x¤=À$Ð àˆÛˆBÜ‘Ñ1ØÐNbð 2ó ˆBð �N‰N˜2Öñ	 ð
 ˆùò fs
   ¤A:®A:c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   r2   r   )r   s   "r   r   r    ¯   s    € ÷ Bñ BÐDð BÐP_ñ Br!   c                ó8   <€ \         SV `  ! V P                  RV/ # )aS  Merge the stored ONNX models into one graph, without changing the object's session.

The constructor calls it once; a call after construction returns a new graph and leaves the running one as
it was.

Args:
    io_maps: Optional list with one list of ``(output, input)`` name pairs per joint between consecutive
        operators: ``io_maps[i]`` connects outputs of ``self.operators[i]`` to inputs of
        ``self.operators[i + 1]``, as in ``[[("out_a", "in_b")], [("out_b", "in_c")]]`` for three
        operators. Each entry may be any iterable of pairs; entries past the last joint are not read. When
        omitted, each joint connects the default ``"output"`` to ``"input"``.

Returns:
    Combined ONNX model graph containing all operators in
    ``self.operators`` connected in sequence, with their metadata merged (the last value of each key).

Raises:
    ValueCheckError: If ``io_maps`` has no entry for a joint, or an entry is not an iterable of name pairs.
        It is a :exc:`ValueError` too.
    ValueError: From ``onnx.compose.merge_models``, if a joint names an output or input that an operator does
        not have, or the operators differ in IR version or opset.

Warns:
    UserWarning: If an output and the input it feeds have different tensor element types: the merged graph
        does not check a later model's declared input types.
r   )r7   Ú_combiner&   )r-   r   r<   s   &&€r   r)   ÚONNXSequential.combine¯   s   ø€ ô6 ‰wÒ §¡ÐA¸ÑAÐAr!   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    Ì   s)   € ÷ Vñ VØ)ðVØCMðVà	ñVr!   c                ó8   <€ \         SV `  V P                  W4      # )aƒ  Create an ONNX Runtime session for the combined graph, without making it the object's session.

Pass the result to ``set_session`` to run the object 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 for the combined graph.
)r7   Ú_create_sessionr*   )r-   r   r   r<   s   &&&€r   r+   ÚONNXSequential.create_sessionÌ   s   ø€ ô" ‰wÑ& t×'8Ñ'8¸)ÓUÐUr!   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&   € ÷ Gñ G ð G¨sð G°tñ Gr!   c                ó<   <€ \         SV `  ! V P                  V3/ VB # )zØSave the combined ONNX 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``.
)r7   Ú_exportr*   )r-   rG   rI   r<   s   &&,€r   ÚexportÚONNXSequential.exportß   s!   ø€ ô ‰wŠ˜t×0Ñ0°)ÑF¸vÑFÐFr!   c               ó    € V ^8„  d   QhRRRR/# )r   Úadditional_metadatazOptional[list[tuple[str, str]]]r   r2   r   )r   s   "r   r   r    è   s    € ÷ Mñ MÐ0Oð MÐ[jñ Mr!   c                ó8   <€ \         SV `  V P                  V4      # )aÏ  Attach metadata entries to the combined ONNX graph.

The metadata is written into the combined graph in place, as :func:`~kornia.onnx.utils.add_metadata` writes
it. The running session keeps the metadata it was created with; :meth:`export` saves the new entries.

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

Returns:
    Combined ONNX model graph after metadata has been attached.
)r7   Ú_add_metadatar*   )r-   rO   r<   s   &&€r   Úadd_metadataÚONNXSequential.add_metadataè   s   ø€ ô ‰wÑ$ T×%6Ñ%6Ð8KÓLÐLr!   )r*   r&   )N)NN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r/   r'   r)   r+   rL   rR   Ú__static_attributes__Ú__classcell__)r<   s   @r   r
   r
   &   s´   ø† ñIðV*ð *.ð*ð 9=ð	*ð
 :>ð*ð $(ð*ð ,1ð*ð ,0ð*ð /3ð*ð  %÷*ð:ð ,0ðð /3÷	ò ÷@Bò B÷:Vò V÷&Gð G÷M÷ Mð Mr!   )rX   Ú
__future__r   ÚosÚtypingr   r   r   Úkornia.core.externalr   r   ÚortÚkornia.core.mixinr   r	   Ú__all__r
   r   r!   r   Ú<module>rb      s<   ðñ$õ #ã 	ß 'Ñ 'å %Ý 3ß 9àÐ
€ôOM�YÐ 0ö OMr!   