nunchaku-lite 0.3.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.
- nunchaku_lite-0.3.0/LICENSE +201 -0
- nunchaku_lite-0.3.0/MANIFEST.in +4 -0
- nunchaku_lite-0.3.0/PKG-INFO +394 -0
- nunchaku_lite-0.3.0/README.md +363 -0
- nunchaku_lite-0.3.0/pyproject.toml +63 -0
- nunchaku_lite-0.3.0/setup.cfg +4 -0
- nunchaku_lite-0.3.0/setup.py +63 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/__init__.py +65 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/__version__.py +3 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/adapters/__init__.py +3 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/adapters/attention_dispatch.py +230 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/adapters/common.py +698 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/adapters/flux.py +1032 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/adapters/flux2.py +677 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/adapters/ltx2.py +574 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/adapters/manifest.py +381 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/adapters/mps_processors.py +151 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/adapters/qwen_image.py +685 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/adapters/sdxl.py +226 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/adapters/z_image.py +426 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/checkpoint_keys.py +117 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/core.py +830 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/linear.py +566 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/lora/__init__.py +1 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/lora/core/__init__.py +1 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/lora/core/convert.py +274 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/lora/core/layout.py +213 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/lora/core/peft.py +78 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/lora/core/runtime.py +803 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/lora/flux.py +285 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/lora/flux2.py +263 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/lora/manifest.py +433 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/lora/qwen_image.py +128 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/lora/z_image.py +154 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/manifest.py +301 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/mlx/__init__.py +34 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/mlx/fused_attention.py +124 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/mlx/kernels.py +497 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/mlx/keymap.py +85 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/mlx/linear.py +443 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/mlx/manifest.py +267 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/mlx/mx_layout.py +106 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/mlx/packing.py +277 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/mlx/patch.py +308 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/mlx/pipeline.py +959 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/ops/__init__.py +15 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/ops/_mlx_steel_attention.py +3503 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/ops/attention.py +22 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/ops/backend.py +51 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/ops/fused.py +432 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/ops/gemm.py +167 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/ops/gemv.py +34 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/ops/mps.py +1114 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/ops/quantize.py +59 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/shaders.py +157 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/text_encoders/__init__.py +5 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/text_encoders/t5.py +62 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite/utils.py +231 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite.egg-info/PKG-INFO +394 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite.egg-info/SOURCES.txt +87 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite.egg-info/dependency_links.txt +1 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite.egg-info/requires.txt +15 -0
- nunchaku_lite-0.3.0/src/nunchaku_lite.egg-info/top_level.txt +1 -0
- nunchaku_lite-0.3.0/tests/test_adapter_common.py +48 -0
- nunchaku_lite-0.3.0/tests/test_attention_dispatch.py +61 -0
- nunchaku_lite-0.3.0/tests/test_awq_gemm.py +84 -0
- nunchaku_lite-0.3.0/tests/test_checkpoint_metadata_fallback.py +53 -0
- nunchaku_lite-0.3.0/tests/test_core.py +420 -0
- nunchaku_lite-0.3.0/tests/test_flux2_adapter.py +166 -0
- nunchaku_lite-0.3.0/tests/test_flux2_lora.py +333 -0
- nunchaku_lite-0.3.0/tests/test_flux_adapter.py +330 -0
- nunchaku_lite-0.3.0/tests/test_flux_lora.py +360 -0
- nunchaku_lite-0.3.0/tests/test_full_inference_flux.py +135 -0
- nunchaku_lite-0.3.0/tests/test_full_inference_flux2.py +151 -0
- nunchaku_lite-0.3.0/tests/test_full_inference_qwen_image.py +111 -0
- nunchaku_lite-0.3.0/tests/test_full_inference_z_image.py +313 -0
- nunchaku_lite-0.3.0/tests/test_ltx2_adapter.py +250 -0
- nunchaku_lite-0.3.0/tests/test_ltx2_fused_ops.py +216 -0
- nunchaku_lite-0.3.0/tests/test_manifest_adapter.py +705 -0
- nunchaku_lite-0.3.0/tests/test_mps_backend.py +484 -0
- nunchaku_lite-0.3.0/tests/test_mps_fused_attention.py +412 -0
- nunchaku_lite-0.3.0/tests/test_ops_backend.py +69 -0
- nunchaku_lite-0.3.0/tests/test_qwen_image_adapter.py +103 -0
- nunchaku_lite-0.3.0/tests/test_qwen_image_lora.py +160 -0
- nunchaku_lite-0.3.0/tests/test_sdxl_adapter.py +109 -0
- nunchaku_lite-0.3.0/tests/test_t5_encoder.py +78 -0
- nunchaku_lite-0.3.0/tests/test_torch_free_imports.py +47 -0
- nunchaku_lite-0.3.0/tests/test_z_image_adapter.py +272 -0
- nunchaku_lite-0.3.0/tests/test_z_image_lora.py +565 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
https://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
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nunchaku_lite
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Lite plugin runtime for applying Nunchaku v2 quantized transformer weights to Diffusers (PyTorch) and mflux (MLX) pipelines.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/rootonchair/nunchaku-lite
|
|
7
|
+
Project-URL: Documentation, https://nunchaku-lite.readthedocs.io/en/latest/
|
|
8
|
+
Project-URL: Issues, https://github.com/rootonchair/nunchaku-lite/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: accelerate>=0.31
|
|
18
|
+
Requires-Dist: diffusers>=0.36
|
|
19
|
+
Requires-Dist: huggingface-hub>=0.34
|
|
20
|
+
Requires-Dist: kernels<0.15,>=0.14
|
|
21
|
+
Requires-Dist: packaging>=23
|
|
22
|
+
Requires-Dist: peft
|
|
23
|
+
Requires-Dist: safetensors
|
|
24
|
+
Requires-Dist: torch>=2.7
|
|
25
|
+
Requires-Dist: transformers>=4.41.2
|
|
26
|
+
Provides-Extra: torch
|
|
27
|
+
Provides-Extra: mlx
|
|
28
|
+
Requires-Dist: mlx>=0.30; extra == "mlx"
|
|
29
|
+
Requires-Dist: numpy; extra == "mlx"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
<p align="center">
|
|
33
|
+
<img src="assets/logo.svg" alt="nunchaku_lite" width="640">
|
|
34
|
+
</p>
|
|
35
|
+
|
|
36
|
+
<p align="center">
|
|
37
|
+
<a href="https://github.com/rootonchair/nunchaku-lite/actions/workflows/cpu-tests.yml">
|
|
38
|
+
<img src="https://github.com/rootonchair/nunchaku-lite/actions/workflows/cpu-tests.yml/badge.svg" alt="CPU Tests">
|
|
39
|
+
</a>
|
|
40
|
+
<a href="https://github.com/rootonchair/nunchaku-lite/actions/workflows/wheels.yml">
|
|
41
|
+
<img src="https://github.com/rootonchair/nunchaku-lite/actions/workflows/wheels.yml/badge.svg" alt="Release Wheels">
|
|
42
|
+
</a>
|
|
43
|
+
<a href="https://nunchaku-lite.readthedocs.io/en/latest/">
|
|
44
|
+
<img src="https://img.shields.io/badge/docs-readthedocs.io-blue" alt="Documentation">
|
|
45
|
+
</a>
|
|
46
|
+
<a href="LICENSE">
|
|
47
|
+
<img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License: Apache 2.0">
|
|
48
|
+
</a>
|
|
49
|
+
</p>
|
|
50
|
+
|
|
51
|
+
## About
|
|
52
|
+
|
|
53
|
+
`nunchaku_lite` brings Nunchaku-quantized image generation models to standard
|
|
54
|
+
Diffusers pipelines with a lean runtime, native CUDA kernels, and drop-in
|
|
55
|
+
pipeline loading. It is designed for fast SVDQ W4A4 inference with a small
|
|
56
|
+
integration surface: load a normal Diffusers pipeline, replace only the
|
|
57
|
+
quantized component, and keep the rest of the workflow
|
|
58
|
+
unchanged.
|
|
59
|
+
|
|
60
|
+
Its core features include:
|
|
61
|
+
|
|
62
|
+
- Efficient pipeline loading: constructs the patched component up front so
|
|
63
|
+
Diffusers does not first materialize dense BF16 transformer or UNet weights
|
|
64
|
+
that are immediately replaced.
|
|
65
|
+
- Native quantized kernels: packages the CUDA kernels and Python wrappers needed
|
|
66
|
+
for INT4 and FP4 Nunchaku checkpoints.
|
|
67
|
+
- AWQ GEMM acceleration: unlike original Nunchaku, `nunchaku_lite` ships a
|
|
68
|
+
native W4A16 group-size-64/int32 GEMM path for large AWQ projections, turning
|
|
69
|
+
chunked GEMV bottlenecks into high-throughput CUDA matmuls.
|
|
70
|
+
- Broad image-model coverage: includes built-in adapters for FLUX.1, FLUX.2
|
|
71
|
+
Klein, Qwen-Image, Qwen-Image-Edit, SDXL, SDXL-Turbo, and Z-Image Turbo.
|
|
72
|
+
- Runtime LoRA support: exposes Diffusers-style LoRA loading, adapter strength
|
|
73
|
+
control, multi-LoRA composition, and unload/reset flows for supported model
|
|
74
|
+
families.
|
|
75
|
+
- Extensible adapter registry: keeps model-specific graph rewrites isolated in
|
|
76
|
+
small adapters without requiring pipeline subclasses or a dependency on the
|
|
77
|
+
full `nunchaku` Python package.
|
|
78
|
+
|
|
79
|
+
## Benchmarks
|
|
80
|
+
|
|
81
|
+
<p align="center">
|
|
82
|
+
<img src="docs/assets/benchmarks/readme-benchmark-summary.png" alt="nunchaku_lite benchmark gains versus original Diffusers" width="900">
|
|
83
|
+
</p>
|
|
84
|
+
|
|
85
|
+
On an NVIDIA RTX PRO 6000, `nunchaku_lite` delivers up
|
|
86
|
+
to `1.79x` lower latency, up to `46%` lower peak CUDA memory, and up to `71%`
|
|
87
|
+
smaller transformer storage versus unmodified Diffusers pipelines in the current
|
|
88
|
+
benchmark set.
|
|
89
|
+
|
|
90
|
+
See [docs/benchmarks.md](docs/benchmarks.md) for charts, generated samples,
|
|
91
|
+
run settings, and reproduction commands.
|
|
92
|
+
|
|
93
|
+
## Supported Models
|
|
94
|
+
|
|
95
|
+
`nunchaku_lite` currently supports Diffusers pipelines whose transformer or UNet
|
|
96
|
+
component matches one of the built-in adapters below. Checkpoints should be SVDQ
|
|
97
|
+
W4A4 Nunchaku v2 `.safetensors` files in INT4 or FP4 format. Full runnable
|
|
98
|
+
model guides live under `docs/models/`.
|
|
99
|
+
|
|
100
|
+
| Model family | Coverage | Runtime LoRA | Guide | Features |
|
|
101
|
+
| --- | --- | --- | --- | --- |
|
|
102
|
+
| FLUX.1 | FLUX.1-schnell and FLUX.1-dev | Yes | [docs/models/flux.md](docs/models/flux.md) | Pipeline loading, INT4/FP4 checkpoints, Diffusers-format LoRA loading, strength control, multi-LoRA composition, reset, and unload. |
|
|
103
|
+
| FLUX.2 Klein | FLUX.2 Klein | Yes | [docs/models/flux2.md](docs/models/flux2.md) | Pipeline loading, INT4/FP4 checkpoints, runtime LoRA, and ComfyUI Flux2 LoRA key conversion. |
|
|
104
|
+
| Qwen-Image and Qwen-Image-Edit | Qwen-Image, Qwen-Image-Lightning, Qwen-Image-Edit, and Qwen-Image-Edit-2509 | Yes | [docs/models/qwen_image.md](docs/models/qwen_image.md) | Pipeline loading, INT4/FP4 checkpoints, low-VRAM examples, Lightning LoRA workflows, and edit-pipeline examples. |
|
|
105
|
+
| SDXL and SDXL-Turbo | SDXL and SDXL-Turbo | Not yet | [docs/models/sdxl.md](docs/models/sdxl.md) | Pipeline loading for quantized UNet checkpoints. |
|
|
106
|
+
| Z-Image Turbo | Z-Image Turbo | Yes | [docs/models/z_image.md](docs/models/z_image.md) | Pipeline loading, INT4/FP4 checkpoints, runtime LoRA, and dense AdaLN modulation LoRA branches. |
|
|
107
|
+
|
|
108
|
+
The Qwen low-VRAM guides use `enable_model_cpu_offload()`, which requires
|
|
109
|
+
`accelerate`.
|
|
110
|
+
|
|
111
|
+
Additional model families should be added through the adapter registry rather
|
|
112
|
+
than pipeline subclasses. See [docs/roadmap.md](docs/roadmap.md) for planned
|
|
113
|
+
coverage and remaining feature work.
|
|
114
|
+
|
|
115
|
+
## Requirements
|
|
116
|
+
|
|
117
|
+
- Python 3.10 or newer
|
|
118
|
+
- PyTorch 2.7 or newer with CUDA
|
|
119
|
+
- Diffusers 0.36 or newer
|
|
120
|
+
|
|
121
|
+
Native source builds also require CUDA toolkit 12.6 or newer with `nvcc`. The
|
|
122
|
+
default runtime path uses prebuilt kernels from `rootonchair/nunchaku-lite-kernels`
|
|
123
|
+
through the Hugging Face `kernels` library instead.
|
|
124
|
+
|
|
125
|
+
The native build detects the local GPU architecture by default. Supported
|
|
126
|
+
targets are `sm75`, `sm80`, `sm86`, `sm89`, `sm120a`, and `sm121a`, subject to
|
|
127
|
+
the installed CUDA toolkit version. CUDA 12.6 or newer is the documented
|
|
128
|
+
minimum; `sm120a` requires CUDA 12.8 or newer, and `sm121a` requires CUDA 13.0
|
|
129
|
+
or newer. The Hugging Face kernels package provides prebuilt kernels for CUDA
|
|
130
|
+
`7.5`, `8.0`, `8.6`, `8.9`, `12.0a`, and `12.1a`.
|
|
131
|
+
|
|
132
|
+
The root Python package does not compile CUDA code. CUDA toolkit requirements
|
|
133
|
+
apply only when installing the local `nunchaku_lite_kernels` package from
|
|
134
|
+
`./nunchaku-lite-kernels`.
|
|
135
|
+
|
|
136
|
+
> **CUDA version note:** `nunchaku_lite` first tries a locally installed
|
|
137
|
+
> `nunchaku_lite_kernels` package, then falls back to
|
|
138
|
+
> `rootonchair/nunchaku-lite-kernels` through Hugging Face `kernels`.
|
|
139
|
+
|
|
140
|
+
### Apple silicon (MPS, experimental)
|
|
141
|
+
|
|
142
|
+
INT4 SVDQ checkpoints also run on Apple-silicon GPUs with `device="mps"`.
|
|
143
|
+
Apple GPUs have no INT4 matmul, so the MPS path runs SVDQ layers as **W8A8**:
|
|
144
|
+
the 4-bit weights (plus folded group scales) become int8, activations are
|
|
145
|
+
quantized to int8 per token after smoothing, and the matmul runs on the M5
|
|
146
|
+
Neural Accelerators with the SVD low-rank branch, scales and bias fused into
|
|
147
|
+
the kernel epilogue. Q/K RMSNorm and RoPE run in a fused Metal kernel.
|
|
148
|
+
|
|
149
|
+
- Requires macOS 26+ and a PyTorch build with MPS. With PyTorch 2.10 to 2.15 the
|
|
150
|
+
Metal kernels download from the Hugging Face Hub on first use (the `kernels`
|
|
151
|
+
dependency of `nunchaku-lite`). For other PyTorch versions, build them
|
|
152
|
+
locally: `pip install --no-build-isolation ./nunchaku-lite-kernels`
|
|
153
|
+
- Choose the quantized-kernel backend with `backend=` on `load_nunchaku_pipeline`
|
|
154
|
+
or `patch_transformer` (the same keyword Diffusers uses for kernel selection in
|
|
155
|
+
`AutoRoundConfig`; unrelated to `set_attention_backend`). CUDA has a single
|
|
156
|
+
kernel and accepts only `"auto"`.
|
|
157
|
+
- `"auto"` (default): `"int8"` when the transformer fits in half of the GPU
|
|
158
|
+
working set with int8 weights, otherwise `"int4"`; `"dense"` on Apple GPUs
|
|
159
|
+
without Neural Accelerators (pre-M5).
|
|
160
|
+
- `"int8"`: fastest. `"int4"`: weights stay 4-bit in memory, a few percent
|
|
161
|
+
slower, identical output. `"dense"`: exact dequantized fallback (more
|
|
162
|
+
memory, no speedup).
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
pipe = load_nunchaku_pipeline(..., device="mps", backend="int4")
|
|
166
|
+
```
|
|
167
|
+
- INT4 checkpoints only (no NVFP4). Verified end to end with FLUX.2 Klein 4B and
|
|
168
|
+
9B, FLUX.1-dev (Nunchaku and Nunchaku Lite checkpoints), Z-Image Turbo, and
|
|
169
|
+
Qwen-Image Lightning (which needs more than 24 GB to run without swapping).
|
|
170
|
+
|
|
171
|
+
On an M5 MacBook Pro (FLUX.2 Klein 4B, 4 steps, denoising only):
|
|
172
|
+
|
|
173
|
+
| Transformer | Weights | Live GPU memory (1024px) | Step 512px | Step 1024px |
|
|
174
|
+
| --- | --- | --- | --- | --- |
|
|
175
|
+
| Dense BF16 | 7.75 GB | 8.1 GB | 1.20 s | 4.96 s |
|
|
176
|
+
| INT4, `int8` backend (default) | 4.57 GB | 5.6 GB | 0.62 s (1.94x) | 2.27 s (2.19x) |
|
|
177
|
+
| INT4, `int4` backend | 2.67 GB | 4.4 GB | 0.70 s (1.71x) | 2.50 s (1.98x) |
|
|
178
|
+
|
|
179
|
+
The packed checkpoint `qweight` is released after conversion whenever the
|
|
180
|
+
kernel copy reproduces it exactly (94 of 100 layers for `int8`, all layers for
|
|
181
|
+
`int4`; AWQ modulation layers too); `state_dict()` re-packs it and
|
|
182
|
+
`load_state_dict()` restores it.
|
|
183
|
+
On M5-class GPUs the patched transformer's attention also runs on the Neural Accelerators (MLX's flash
|
|
184
|
+
attention kernel) instead of PyTorch's MPS attention, and the q/k norm + RoPE of FLUX.1, FLUX.2, Qwen-Image and
|
|
185
|
+
Z-Image is one fused kernel. Both come with the Hub kernels; with an older Hub build they are compiled at runtime
|
|
186
|
+
instead. The dense BF16 row uses stock Diffusers.
|
|
187
|
+
|
|
188
|
+
There is also an MLX runtime, `nunchaku_lite.mlx` (`pip install "nunchaku-lite[mlx]" mflux`),
|
|
189
|
+
which loads the same checkpoints into [mflux](https://github.com/filipstrand/mflux)
|
|
190
|
+
pipelines with the same `load_nunchaku_pipeline` interface. See
|
|
191
|
+
[docs/mlx.md](docs/mlx.md).
|
|
192
|
+
|
|
193
|
+
## Installation
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
pip install nunchaku-lite # PyTorch runtime (CUDA, Apple MPS) for Diffusers pipelines
|
|
197
|
+
pip install "nunchaku-lite[mlx]" mflux # adds the MLX runtime (Apple silicon) for mflux pipelines
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
From a source checkout, `pip install .` and `pip install ".[mlx]"` do the same.
|
|
201
|
+
|
|
202
|
+
This installs the root Python runtime and uses Hugging Face prebuilt kernels by
|
|
203
|
+
default. `nunchaku_lite.mlx` does not import torch, even though the base install
|
|
204
|
+
includes it.
|
|
205
|
+
|
|
206
|
+
To build and use the local CUDA kernels package:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
pip install --no-build-isolation ./nunchaku-lite-kernels
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`--no-build-isolation` ensures the extension is compiled against the PyTorch
|
|
213
|
+
version installed in the active environment.
|
|
214
|
+
|
|
215
|
+
When `nunchaku_lite_kernels` is installed locally, `nunchaku_lite` prefers it
|
|
216
|
+
over the Hugging Face fallback.
|
|
217
|
+
|
|
218
|
+
Build and install a wheel:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
python -m build --wheel
|
|
222
|
+
pip install dist/nunchaku_lite-*.whl
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
By default, the local kernels package build uses `NUNCHAKU_INSTALL_MODE=FAST`
|
|
226
|
+
and compiles for visible local CUDA devices. To build all supported
|
|
227
|
+
architectures:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
NUNCHAKU_INSTALL_MODE=ALL pip install --no-build-isolation ./nunchaku-lite-kernels
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Quick Start
|
|
234
|
+
|
|
235
|
+
Run from the repository root:
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from pathlib import Path
|
|
239
|
+
|
|
240
|
+
import torch
|
|
241
|
+
from diffusers import FluxPipeline
|
|
242
|
+
|
|
243
|
+
from nunchaku_lite import load_nunchaku_pipeline
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
model_id = "black-forest-labs/FLUX.1-schnell"
|
|
247
|
+
precision = "fp4" # "int4" or "fp4"
|
|
248
|
+
checkpoints = {
|
|
249
|
+
"int4": "nunchaku-ai/nunchaku-flux.1-schnell/svdq-int4_r32-flux.1-schnell.safetensors",
|
|
250
|
+
"fp4": "nunchaku-ai/nunchaku-flux.1-schnell/svdq-fp4_r32-flux.1-schnell.safetensors",
|
|
251
|
+
}
|
|
252
|
+
output_path = Path(f"outputs/flux_schnell_nunchaku_lite_{precision}.png")
|
|
253
|
+
|
|
254
|
+
pipe = load_nunchaku_pipeline(
|
|
255
|
+
model_id,
|
|
256
|
+
pipeline_cls=FluxPipeline,
|
|
257
|
+
checkpoint=checkpoints[precision],
|
|
258
|
+
target="flux",
|
|
259
|
+
precision=precision,
|
|
260
|
+
torch_dtype=torch.bfloat16,
|
|
261
|
+
device="cuda",
|
|
262
|
+
)
|
|
263
|
+
pipe = pipe.to("cuda")
|
|
264
|
+
|
|
265
|
+
image = pipe(
|
|
266
|
+
"A cat holding a sign that says hello world",
|
|
267
|
+
height=1024,
|
|
268
|
+
width=1024,
|
|
269
|
+
num_inference_steps=4,
|
|
270
|
+
guidance_scale=0.0,
|
|
271
|
+
generator=torch.Generator(device="cuda").manual_seed(12345),
|
|
272
|
+
).images[0]
|
|
273
|
+
|
|
274
|
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
275
|
+
image.save(output_path)
|
|
276
|
+
print(f"saved {output_path}")
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Runtime LoRA
|
|
280
|
+
|
|
281
|
+
Pipelines loaded with `load_nunchaku_pipeline` expose Diffusers-style LoRA
|
|
282
|
+
methods when the selected adapter supports runtime LoRA:
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
from pathlib import Path
|
|
286
|
+
|
|
287
|
+
import torch
|
|
288
|
+
from diffusers import FluxPipeline
|
|
289
|
+
|
|
290
|
+
from nunchaku_lite import load_nunchaku_pipeline
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
model_id = "black-forest-labs/FLUX.1-dev"
|
|
294
|
+
precision = "fp4"
|
|
295
|
+
checkpoint = "nunchaku-tech/nunchaku-flux.1-dev/svdq-fp4_r32-flux.1-dev.safetensors"
|
|
296
|
+
output_path = Path("outputs/flux_dev_ghibsky_lora_fp4.png")
|
|
297
|
+
|
|
298
|
+
pipe = load_nunchaku_pipeline(
|
|
299
|
+
model_id,
|
|
300
|
+
pipeline_cls=FluxPipeline,
|
|
301
|
+
checkpoint=checkpoint,
|
|
302
|
+
target="flux",
|
|
303
|
+
precision=precision,
|
|
304
|
+
torch_dtype=torch.bfloat16,
|
|
305
|
+
)
|
|
306
|
+
pipe.enable_model_cpu_offload()
|
|
307
|
+
|
|
308
|
+
pipe.load_lora_weights(
|
|
309
|
+
"aleksa-codes/flux-ghibsky-illustration",
|
|
310
|
+
weight_name="lora.safetensors",
|
|
311
|
+
adapter_name="ghibsky",
|
|
312
|
+
)
|
|
313
|
+
pipe.set_adapters("ghibsky", adapter_weights=0.75)
|
|
314
|
+
|
|
315
|
+
image = pipe(
|
|
316
|
+
"GHIBSKY style painting of a cozy mountain cabin beside a clear lake at sunset",
|
|
317
|
+
height=1024,
|
|
318
|
+
width=1024,
|
|
319
|
+
num_inference_steps=28,
|
|
320
|
+
guidance_scale=3.5,
|
|
321
|
+
generator=torch.Generator(device="cpu").manual_seed(12345),
|
|
322
|
+
).images[0]
|
|
323
|
+
|
|
324
|
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
325
|
+
image.save(output_path)
|
|
326
|
+
print(f"saved {output_path}")
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Checkpoint paths can be local `.safetensors` files or Hugging Face paths of the
|
|
330
|
+
form:
|
|
331
|
+
|
|
332
|
+
```text
|
|
333
|
+
org-or-user/repo-name/path/to/checkpoint.safetensors
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Documentation
|
|
337
|
+
|
|
338
|
+
| Topic | Link |
|
|
339
|
+
| --- | --- |
|
|
340
|
+
| Hosted documentation | [nunchaku-lite.readthedocs.io](https://nunchaku-lite.readthedocs.io/en/latest/) |
|
|
341
|
+
| Benchmark charts and samples | [docs/benchmarks.md](docs/benchmarks.md) |
|
|
342
|
+
| Public API and runtime LoRA usage | [docs/api.md](docs/api.md) |
|
|
343
|
+
| Development, testing, and adapter authoring | [docs/development.md](docs/development.md) |
|
|
344
|
+
| Documentation deployment flow | [docs/deployment.md](docs/deployment.md) |
|
|
345
|
+
| Release wheel build flow | [docs/release_wheels.md](docs/release_wheels.md) |
|
|
346
|
+
| Supported models and feature backlog | [docs/roadmap.md](docs/roadmap.md) |
|
|
347
|
+
| Benchmarks | [benchmarks/README.md](benchmarks/README.md) |
|
|
348
|
+
|
|
349
|
+
## Public API
|
|
350
|
+
|
|
351
|
+
```python
|
|
352
|
+
from nunchaku_lite import (
|
|
353
|
+
TransformerAdapter,
|
|
354
|
+
list_adapters,
|
|
355
|
+
load_nunchaku_pipeline,
|
|
356
|
+
patch_transformer,
|
|
357
|
+
register_adapter,
|
|
358
|
+
)
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
`load_nunchaku_pipeline(...)` is the preferred entry point for normal pipeline
|
|
362
|
+
loading. Use `patch_transformer(...)` only when a Diffusers component has already
|
|
363
|
+
been constructed and needs in-place patching.
|
|
364
|
+
|
|
365
|
+
See [docs/api.md](docs/api.md) for argument details, runtime LoRA examples, and
|
|
366
|
+
adapter registry usage.
|
|
367
|
+
|
|
368
|
+
## Development
|
|
369
|
+
|
|
370
|
+
Run the unit tests:
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
pytest -q tests
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
Build the extension in place:
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
python setup.py build_ext --inplace
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
See [docs/development.md](docs/development.md) for full inference tests, adapter
|
|
383
|
+
authoring guidance, runtime LoRA implementation notes, and repository layout.
|
|
384
|
+
|
|
385
|
+
## License
|
|
386
|
+
|
|
387
|
+
`nunchaku_lite` is licensed under the Apache License, Version 2.0. See
|
|
388
|
+
[LICENSE](LICENSE).
|
|
389
|
+
|
|
390
|
+
## Acknowledgements
|
|
391
|
+
|
|
392
|
+
`nunchaku_lite` builds on the Nunchaku project and uses selected native kernel
|
|
393
|
+
code for the lite runtime. We are grateful to the maintainers and contributors
|
|
394
|
+
of these projects.
|