hyperonnx 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. hyperonnx-1.0.0/.github/words_bag.txt +0 -0
  2. hyperonnx-1.0.0/.github/workflows/lint.yml +29 -0
  3. hyperonnx-1.0.0/.github/workflows/unittest.yml +26 -0
  4. hyperonnx-1.0.0/.gitignore +16 -0
  5. hyperonnx-1.0.0/.pre-commit-config.yaml +40 -0
  6. hyperonnx-1.0.0/LICENSE +176 -0
  7. hyperonnx-1.0.0/PKG-INFO +154 -0
  8. hyperonnx-1.0.0/README.md +127 -0
  9. hyperonnx-1.0.0/README_CN.md +127 -0
  10. hyperonnx-1.0.0/docs/assets/qwen2_omni_vision.gif +0 -0
  11. hyperonnx-1.0.0/docs/assets/r18-sample.gif +0 -0
  12. hyperonnx-1.0.0/hyperonnx/__init__.py +22 -0
  13. hyperonnx-1.0.0/hyperonnx/auto.py +207 -0
  14. hyperonnx-1.0.0/hyperonnx/exporter/__init__.py +51 -0
  15. hyperonnx-1.0.0/hyperonnx/exporter/dynamo.py +286 -0
  16. hyperonnx-1.0.0/hyperonnx/exporter/torchscript.py +134 -0
  17. hyperonnx-1.0.0/hyperonnx/exporter/utils.py +143 -0
  18. hyperonnx-1.0.0/hyperonnx/function_rewriter.py +544 -0
  19. hyperonnx-1.0.0/hyperonnx/hyper_export.py +474 -0
  20. hyperonnx-1.0.0/hyperonnx/patch.py +66 -0
  21. hyperonnx-1.0.0/hyperonnx/torch_export.py +155 -0
  22. hyperonnx-1.0.0/hyperonnx/typing.py +84 -0
  23. hyperonnx-1.0.0/hyperonnx/utils.py +27 -0
  24. hyperonnx-1.0.0/pyproject.toml +99 -0
  25. hyperonnx-1.0.0/tests/expoter/test_detach_module_outputs.py +40 -0
  26. hyperonnx-1.0.0/tests/expoter/test_dynamo_build_onnxscript.py +235 -0
  27. hyperonnx-1.0.0/tests/expoter/test_dynamo_make_custom_op.py +103 -0
  28. hyperonnx-1.0.0/tests/expoter/test_dynamo_replace_custom_op.py +79 -0
  29. hyperonnx-1.0.0/tests/expoter/test_plain_output_tensors.py +71 -0
  30. hyperonnx-1.0.0/tests/test_auto_trace_method.py +102 -0
  31. hyperonnx-1.0.0/tests/test_compose_nodes_to_functions.py +682 -0
  32. hyperonnx-1.0.0/tests/test_export_functions.py +186 -0
  33. hyperonnx-1.0.0/tests/test_export_hyper_onnx.py +415 -0
  34. hyperonnx-1.0.0/tests/test_fuse_constants_to_function.py +135 -0
File without changes
@@ -0,0 +1,29 @@
1
+ name: check coding styles
2
+ run-name: ${{ github.actor }} lint
3
+ on:
4
+ pull_request:
5
+ paths:
6
+ - 'hyperonnx/**'
7
+ - 'tests/**'
8
+ jobs:
9
+ run-lint-public:
10
+ runs-on: [ubuntu-latest]
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.12"]
14
+ steps:
15
+ - uses: actions/checkout@v5
16
+ with:
17
+ fetch-depth: 2
18
+ - name: Install uv and set the Python version
19
+ uses: astral-sh/setup-uv@v6
20
+ with:
21
+ python-version: ${{ matrix.python-version }}
22
+ - uses: actions/setup-node@v4
23
+ with:
24
+ node-version: lts/Jod
25
+ - name: pyright type check
26
+ run: |
27
+ uv sync --extra=test -U
28
+ uv run pyright hyperonnx
29
+ uv run pre-commit run -s HEAD^ -o HEAD
@@ -0,0 +1,26 @@
1
+ name: Run hyperonnx unit tests
2
+ run-name: ${{ github.actor }} unit tests
3
+ on:
4
+ pull_request:
5
+ paths:
6
+ - '.github/workflows/*.yml'
7
+ - 'hyperonnx/**.py'
8
+ - 'tests/**.py'
9
+ jobs:
10
+ run-public-tests:
11
+ runs-on: [ubuntu-latest]
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.12"]
15
+ steps:
16
+ - uses: actions/checkout@v5
17
+ - name: Install uv and set the Python version
18
+ uses: astral-sh/setup-uv@v6
19
+ with:
20
+ python-version: ${{ matrix.python-version }}
21
+ - name: Install dependencies
22
+ run: |
23
+ uv sync --extra=test -U
24
+ - name: Run pytest and coverage
25
+ run: |
26
+ uv run pytest --cov=hyperonnx tests
@@ -0,0 +1,16 @@
1
+ .*/
2
+ !.github/
3
+ *.egg-info
4
+ __pycache__
5
+ # pdm build tool
6
+ .pdm-python
7
+ __pypackages__/
8
+ # pypa
9
+ dist/
10
+ build/
11
+ tests/models/
12
+ !tests/models/.gitkeep
13
+ !tests/models/model.list
14
+
15
+ uv.lock
16
+ .coverage
@@ -0,0 +1,40 @@
1
+ fail_fast: false
2
+ repos:
3
+ - repo: https://github.com/pre-commit/pre-commit-hooks
4
+ rev: v6.0.0
5
+ hooks:
6
+ - id: trailing-whitespace
7
+ - id: end-of-file-fixer
8
+ - id: check-json
9
+ - id: check-toml
10
+ - id: check-yaml
11
+ - id: check-added-large-files
12
+ - repo: https://github.com/PyCQA/isort
13
+ rev: 6.0.1
14
+ hooks:
15
+ - id: isort
16
+ args: ['--profile=black']
17
+ - repo: https://github.com/psf/black
18
+ rev: 25.1.0
19
+ hooks:
20
+ - id: black
21
+ - repo: https://github.com/codespell-project/codespell
22
+ rev: v2.4.1
23
+ hooks:
24
+ - id: codespell
25
+ args: [-w, -I=.github/words_bag.txt]
26
+ exclude: (\.(txt|diff|patch)$)
27
+ - repo: https://github.com/pycqa/flake8
28
+ rev: 7.3.0
29
+ hooks:
30
+ - id: flake8
31
+ additional_dependencies: [Flake8-pyproject]
32
+ args:
33
+ - '--ignore=W503,E203,E231,E241'
34
+ - repo: https://github.com/pre-commit/mirrors-mypy
35
+ rev: v1.17.1
36
+ hooks:
37
+ - id: mypy
38
+ args:
39
+ - '--ignore-missing-imports'
40
+ - '--exclude=tests.*\.py'
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,154 @@
1
+ Metadata-Version: 2.4
2
+ Name: hyperonnx
3
+ Version: 1.0.0
4
+ Summary: Copyright (C) 2025 The HYPERONNX Authors.
5
+ Author-email: Wenyi Tang <wenyitang@outlook.com>
6
+ Requires-Python: >=3.11
7
+ Description-Content-Type: text/markdown
8
+ Classifier: License :: OSI Approved :: Apache Software License
9
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
10
+ Classifier: Topic :: Software Development
11
+ License-File: LICENSE
12
+ Requires-Dist: onnxifier>=2.0.0
13
+ Requires-Dist: onnxscript
14
+ Requires-Dist: onnx>=1.18.0
15
+ Requires-Dist: torch
16
+ Requires-Dist: mypy ; extra == "test"
17
+ Requires-Dist: onnxruntime ; extra == "test"
18
+ Requires-Dist: pre-commit ; extra == "test"
19
+ Requires-Dist: pyright>=1.1.408 ; extra == "test"
20
+ Requires-Dist: pytest ; extra == "test"
21
+ Requires-Dist: pytest-cov ; extra == "test"
22
+ Requires-Dist: torchvision ; extra == "test"
23
+ Project-URL: Docs, https://loseall.github.io/hyperonnx
24
+ Project-URL: Home, https://github.com/LoSealL/hyperonnx
25
+ Provides-Extra: test
26
+
27
+ # πŸš€ HYPER-ONNX
28
+
29
+ [δΈ­ζ–‡](./README_CN.md)|[EN](./README.md)
30
+
31
+ Hyper-ONNX can export pytorch models (`nn.Module`) in a hierachical manner. It can keep the module hier information and make a nested onnx graph. ✨
32
+
33
+
34
+ ## πŸ“¦ Install
35
+
36
+ Simply install from pypi:
37
+
38
+ ```bash
39
+ pip install hyperonnx
40
+ ```
41
+
42
+ Or you may install from source:
43
+
44
+ ```bash
45
+ git clone https://github.com/LoSealL/hyperonnx.git
46
+ pip install -e hyperonnx[test]
47
+ ```
48
+
49
+ ## πŸ§ͺ Usage Example
50
+
51
+ ### 1) Export `nn.Module` with specified hier info
52
+
53
+ ```python
54
+ import torch
55
+ import torchvision as tv
56
+ from torchvision.models.resnet import BasicBlock, Bottleneck, ResNet
57
+
58
+ from hyperonnx import export_hyper_onnx
59
+
60
+ model = tv.models.resnet18()
61
+ export_hyper_onnx(
62
+ resnet,
63
+ (torch.randn(1, 3, 224, 224),),
64
+ "hyper-resnet18.onnx",
65
+ input_names=["img"],
66
+ output_names=["features"],
67
+ hiera=[ResNet, BasicBlock, Bottleneck],
68
+ do_optimization=False,
69
+ dynamo=False,
70
+ )
71
+ ```
72
+
73
+ ![r18-sample](docs/assets/r18-sample.gif)
74
+
75
+ ### 2) Export any call to a model by auto tracing
76
+
77
+ ```python
78
+ from hyperonnx import auto_trace_method
79
+ from hyperonnx.patch import patch_transformers
80
+ from transformers import (
81
+ GenerationConfig,
82
+ Qwen2_5OmniThinkerForConditionalGeneration,
83
+ )
84
+ from transformers.models.qwen2_5_omni.modeling_qwen2_5_omni import (
85
+ Qwen2_5_VisionPatchEmbed,
86
+ Qwen2_5_VisionRotaryEmbedding,
87
+ Qwen2_5OmniAudioEncoderLayer,
88
+ Qwen2_5OmniDecoderLayer,
89
+ Qwen2_5OmniPatchMerger,
90
+ Qwen2_5OmniVisionBlock,
91
+ )
92
+
93
+ thinker = Qwen2_5OmniThinkerForConditionalGeneration.from_pretrained(
94
+ "Qwen/Qwen2.5-Omni-3B",
95
+ dtype="float16",
96
+ device_map="cuda",
97
+ )
98
+ with (
99
+ patch_transformers(),
100
+ auto_trace_method(thinker.model.forward) as text_tracer,
101
+ auto_trace_method(thinker.visual.forward) as visual_tracer,
102
+ auto_trace_method(thinker.audio_tower.forward) as audio_tracer,
103
+ ):
104
+ try:
105
+ outputs = thinker.generate(
106
+ **inputs, # your any input data
107
+ max_new_tokens=2048,
108
+ generation_config=GenerationConfig(use_cache=False),
109
+ )
110
+ except StopIteration:
111
+ pass
112
+ text_tracer.export(
113
+ "qwen-omni-2.5-3b-text.onnx",
114
+ input_names=["input_ids"],
115
+ output_names=["hidden_states"],
116
+ hiera=[
117
+ Qwen2_5OmniDecoderLayer,
118
+ ],
119
+ external_data=True,
120
+ external_directory="qwen25_omni/text",
121
+ do_optimization=True,
122
+ )
123
+ visual_tracer.export(
124
+ "qwen-omni-2.5-3b-vision.onnx",
125
+ input_names=["hidden_states"],
126
+ output_names=["last_hidden_state"],
127
+ hiera=[
128
+ Qwen2_5_VisionPatchEmbed,
129
+ Qwen2_5_VisionRotaryEmbedding,
130
+ Qwen2_5OmniVisionBlock,
131
+ Qwen2_5OmniPatchMerger,
132
+ ],
133
+ external_data=True,
134
+ external_directory="qwen25_omni/vision",
135
+ do_optimization=True,
136
+ )
137
+ audio_tracer.export(
138
+ "qwen-omni-2.5-3b-audio.onnx",
139
+ input_names=["hidden_states"],
140
+ output_names=["last_hidden_state"],
141
+ hiera=[
142
+ Qwen2_5OmniAudioEncoderLayer,
143
+ ],
144
+ external_data=True,
145
+ external_directory="qwen25_omni/audio",
146
+ do_optimization=True,
147
+ )
148
+ ```
149
+
150
+ ![qwen2](docs/assets/qwen2_omni_vision.gif)
151
+ ---
152
+
153
+ If you run into issues or want to contribute, feel free to open an Issue or PR. πŸ’‘
154
+
@@ -0,0 +1,127 @@
1
+ # πŸš€ HYPER-ONNX
2
+
3
+ [δΈ­ζ–‡](./README_CN.md)|[EN](./README.md)
4
+
5
+ Hyper-ONNX can export pytorch models (`nn.Module`) in a hierachical manner. It can keep the module hier information and make a nested onnx graph. ✨
6
+
7
+
8
+ ## πŸ“¦ Install
9
+
10
+ Simply install from pypi:
11
+
12
+ ```bash
13
+ pip install hyperonnx
14
+ ```
15
+
16
+ Or you may install from source:
17
+
18
+ ```bash
19
+ git clone https://github.com/LoSealL/hyperonnx.git
20
+ pip install -e hyperonnx[test]
21
+ ```
22
+
23
+ ## πŸ§ͺ Usage Example
24
+
25
+ ### 1) Export `nn.Module` with specified hier info
26
+
27
+ ```python
28
+ import torch
29
+ import torchvision as tv
30
+ from torchvision.models.resnet import BasicBlock, Bottleneck, ResNet
31
+
32
+ from hyperonnx import export_hyper_onnx
33
+
34
+ model = tv.models.resnet18()
35
+ export_hyper_onnx(
36
+ resnet,
37
+ (torch.randn(1, 3, 224, 224),),
38
+ "hyper-resnet18.onnx",
39
+ input_names=["img"],
40
+ output_names=["features"],
41
+ hiera=[ResNet, BasicBlock, Bottleneck],
42
+ do_optimization=False,
43
+ dynamo=False,
44
+ )
45
+ ```
46
+
47
+ ![r18-sample](docs/assets/r18-sample.gif)
48
+
49
+ ### 2) Export any call to a model by auto tracing
50
+
51
+ ```python
52
+ from hyperonnx import auto_trace_method
53
+ from hyperonnx.patch import patch_transformers
54
+ from transformers import (
55
+ GenerationConfig,
56
+ Qwen2_5OmniThinkerForConditionalGeneration,
57
+ )
58
+ from transformers.models.qwen2_5_omni.modeling_qwen2_5_omni import (
59
+ Qwen2_5_VisionPatchEmbed,
60
+ Qwen2_5_VisionRotaryEmbedding,
61
+ Qwen2_5OmniAudioEncoderLayer,
62
+ Qwen2_5OmniDecoderLayer,
63
+ Qwen2_5OmniPatchMerger,
64
+ Qwen2_5OmniVisionBlock,
65
+ )
66
+
67
+ thinker = Qwen2_5OmniThinkerForConditionalGeneration.from_pretrained(
68
+ "Qwen/Qwen2.5-Omni-3B",
69
+ dtype="float16",
70
+ device_map="cuda",
71
+ )
72
+ with (
73
+ patch_transformers(),
74
+ auto_trace_method(thinker.model.forward) as text_tracer,
75
+ auto_trace_method(thinker.visual.forward) as visual_tracer,
76
+ auto_trace_method(thinker.audio_tower.forward) as audio_tracer,
77
+ ):
78
+ try:
79
+ outputs = thinker.generate(
80
+ **inputs, # your any input data
81
+ max_new_tokens=2048,
82
+ generation_config=GenerationConfig(use_cache=False),
83
+ )
84
+ except StopIteration:
85
+ pass
86
+ text_tracer.export(
87
+ "qwen-omni-2.5-3b-text.onnx",
88
+ input_names=["input_ids"],
89
+ output_names=["hidden_states"],
90
+ hiera=[
91
+ Qwen2_5OmniDecoderLayer,
92
+ ],
93
+ external_data=True,
94
+ external_directory="qwen25_omni/text",
95
+ do_optimization=True,
96
+ )
97
+ visual_tracer.export(
98
+ "qwen-omni-2.5-3b-vision.onnx",
99
+ input_names=["hidden_states"],
100
+ output_names=["last_hidden_state"],
101
+ hiera=[
102
+ Qwen2_5_VisionPatchEmbed,
103
+ Qwen2_5_VisionRotaryEmbedding,
104
+ Qwen2_5OmniVisionBlock,
105
+ Qwen2_5OmniPatchMerger,
106
+ ],
107
+ external_data=True,
108
+ external_directory="qwen25_omni/vision",
109
+ do_optimization=True,
110
+ )
111
+ audio_tracer.export(
112
+ "qwen-omni-2.5-3b-audio.onnx",
113
+ input_names=["hidden_states"],
114
+ output_names=["last_hidden_state"],
115
+ hiera=[
116
+ Qwen2_5OmniAudioEncoderLayer,
117
+ ],
118
+ external_data=True,
119
+ external_directory="qwen25_omni/audio",
120
+ do_optimization=True,
121
+ )
122
+ ```
123
+
124
+ ![qwen2](docs/assets/qwen2_omni_vision.gif)
125
+ ---
126
+
127
+ If you run into issues or want to contribute, feel free to open an Issue or PR. πŸ’‘