Skip to main content

🚀 HYPER-ONNX

中文|EN

Hyper-ONNX can export pytorch models (nn.Module) in a hierarchical manner. It can keep the module hier information and make a nested onnx graph. ✨

📦 Install

Simply install from pypi:

pip install hyperonnx

Or you may install from source:

git clone https://github.com/LoSealL/hyperonnx.git
pip install -e hyperonnx[test]

🧪 Usage Example

1) Export nn.Module with specified hier info

import torch
import torchvision as tv
from torchvision.models.resnet import BasicBlock, Bottleneck, ResNet

from hyperonnx import export_hyper_onnx

model = tv.models.resnet18()
export_hyper_onnx(
    resnet,
    (torch.randn(1, 3, 224, 224),),
    "hyper-resnet18.onnx",
    input_names=["img"],
    output_names=["features"],
    hiera=[ResNet, BasicBlock, Bottleneck],
    do_optimization=False,
    dynamo=False,
)

r18-sample

2) Export any call to a model by auto tracing

from hyperonnx import auto_trace_method
from hyperonnx.transformers import patch_transformers
from transformers import (
    GenerationConfig,
    Qwen2_5OmniThinkerForConditionalGeneration,
)
from transformers.models.qwen2_5_omni.modeling_qwen2_5_omni import (
    Qwen2_5_VisionPatchEmbed,
    Qwen2_5_VisionRotaryEmbedding,
    Qwen2_5OmniAudioEncoderLayer,
    Qwen2_5OmniDecoderLayer,
    Qwen2_5OmniPatchMerger,
    Qwen2_5OmniVisionBlock,
)

thinker = Qwen2_5OmniThinkerForConditionalGeneration.from_pretrained(
    "Qwen/Qwen2.5-Omni-3B",
    dtype="float16",
    device_map="cuda",
)
with (
    patch_transformers(),
    auto_trace_method(thinker.model.forward) as text_tracer,
    auto_trace_method(thinker.visual.forward) as visual_tracer,
    auto_trace_method(thinker.audio_tower.forward) as audio_tracer,
):
    try:
        outputs = thinker.generate(
            **inputs,  # your any input data
            max_new_tokens=2048,
            generation_config=GenerationConfig(use_cache=False),
        )
    except StopIteration:
        pass
    text_tracer.export(
        "qwen-omni-2.5-3b-text.onnx",
        input_names=["input_ids"],
        output_names=["hidden_states"],
        hiera=[
            Qwen2_5OmniDecoderLayer,
        ],
        external_data=True,
        external_directory="qwen25_omni/text",
        do_optimization=True,
    )
    visual_tracer.export(
        "qwen-omni-2.5-3b-vision.onnx",
        input_names=["hidden_states"],
        output_names=["last_hidden_state"],
        hiera=[
            Qwen2_5_VisionPatchEmbed,
            Qwen2_5_VisionRotaryEmbedding,
            Qwen2_5OmniVisionBlock,
            Qwen2_5OmniPatchMerger,
        ],
        external_data=True,
        external_directory="qwen25_omni/vision",
        do_optimization=True,
    )
    audio_tracer.export(
        "qwen-omni-2.5-3b-audio.onnx",
        input_names=["hidden_states"],
        output_names=["last_hidden_state"],
        hiera=[
            Qwen2_5OmniAudioEncoderLayer,
        ],
        external_data=True,
        external_directory="qwen25_omni/audio",
        do_optimization=True,
    )

qwen2

3) Export compiled modules with CUDA kernel bundle

Mark specific modules with compile= to torch.compile them during export. A <TypeName>.kernels/ sidecar directory is written next to each compiled module's ONNX function, containing the cubin files and a manifest.json.

export_hyper_onnx(
    model,
    (torch.randn(8, 768),),
    "model.onnx",
    hiera=[DecoderLayer, Attention],
    compile=[Attention],  # Attention gets a kernel bundle
    compile_static_grid=False,  # set True to skip grid AST extraction
    dynamo=True,
    external_data=True,
    external_directory="out/",
)

The ONNX function body remains the portable fallback. The kernel bundle is a pure sidecar — deleting it makes the model behave as if compile=None.

Note: torch.compile is cached per Python process by dynamo. If you call export_hyper_onnx(..., compile=...) twice on the same model in the same process, call torch._dynamo.reset() between calls so the compile capture fires again.

If you run into issues or want to contribute, feel free to open an Issue or PR. 💡

Metadata

Release files for hyperonnx 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hyperonnx 2.1.0
File Size Uploaded Provenance Actions
hyperonnx-2.1.0.tar.gz 94.3 kB With provenance Details for hyperonnx-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hyperonnx 2.1.0
File Interpreter ABI Platform Actions
hyperonnx-2.1.0-py3-none-any.whl Python 3 none any Details for hyperonnx-2.1.0-py3-none-any.whl

Total release size: 212.0 kB

Release files / hyperonnx-2.1.0.tar.gz

Download URL hyperonnx-2.1.0.tar.gz
Size 94.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c809c3420bc0a63f4a5a0ec0dacc925dafdc04ad54b3c6dba549a0816ca21d25
BLAKE2b-256 checksum
How to use checksums
b9f15916503aac80b63dfab3bd7fca70477c026272b85504977a786b9817c91f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / hyperonnx-2.1.0-py3-none-any.whl

Download URL hyperonnx-2.1.0-py3-none-any.whl
Size 117.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0fccf6ee1f364fb296ff11f1c20729f3afde614fa69b53104b9a4cd861e7daf
BLAKE2b-256 checksum
How to use checksums
241e348989631a0e495186c279e28ba3e10b659133c39ef50a0cd0534c58d664
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for hyperonnx 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hyperonnx-2.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page