🚀 HYPER-ONNX
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,
)
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,
)
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. 💡
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hyperonnx-2.0.1.tar.gz.
File metadata
- Download URL: hyperonnx-2.0.1.tar.gz
- Upload date:
- Size: 88.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3256a61f64c5e0e139c3758853e8f0e3775f1077698ad669665297886fec8449
|
|
| MD5 |
2a9c3e0fc3929429b4d17f138cf545f7
|
|
| BLAKE2b-256 |
cf7cbacfc7c39fb62c62c50ff8639d30a4b5efa1257dec6e9ed2df5dae4fb487
|
Provenance
The following attestation bundles were made for hyperonnx-2.0.1.tar.gz:
Publisher:
publish.yml on LoSealL/HyperONNX
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyperonnx-2.0.1.tar.gz -
Subject digest:
3256a61f64c5e0e139c3758853e8f0e3775f1077698ad669665297886fec8449 - Sigstore transparency entry: 2594792118
- Sigstore integration time:
-
Permalink:
LoSealL/HyperONNX@b7b86327adf426634758f8ba59e45928569d86b7 -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/LoSealL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b7b86327adf426634758f8ba59e45928569d86b7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hyperonnx-2.0.1-py3-none-any.whl.
File metadata
- Download URL: hyperonnx-2.0.1-py3-none-any.whl
- Upload date:
- Size: 111.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbb064d835ee52a266958220b60766f4490e12cec89f079e7c53a1f0bdb87037
|
|
| MD5 |
9294e34613d7bb33e7a9a184e3d751f8
|
|
| BLAKE2b-256 |
2d63b3522ade33c82be9705c5dcc43060597798911a1aa6d698daf85fe4f7663
|
Provenance
The following attestation bundles were made for hyperonnx-2.0.1-py3-none-any.whl:
Publisher:
publish.yml on LoSealL/HyperONNX
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyperonnx-2.0.1-py3-none-any.whl -
Subject digest:
dbb064d835ee52a266958220b60766f4490e12cec89f079e7c53a1f0bdb87037 - Sigstore transparency entry: 2594792131
- Sigstore integration time:
-
Permalink:
LoSealL/HyperONNX@b7b86327adf426634758f8ba59e45928569d86b7 -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/LoSealL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b7b86327adf426634758f8ba59e45928569d86b7 -
Trigger Event:
push
-
Statement type: