Diffusers に Nunchaku 4 ビット推論を導入
Hugging Face は Diffusers ライブラリに Nunchaku の 4 ビット推論機能を統合し、低リソース環境での効率的な画像生成を可能にした。
キーポイント
Diffusers と Nunchaku の連携強化
Hugging Face が Diffusers ライブラリに Nunchaku の機能を直接統合し、4 ビット量子化推論をサポートするようになった。
低リソース環境での画像生成実現
メモリ使用量を大幅に削減できるため、GPU メモリが限られた環境やエッジデバイスでも拡散モデルを動作可能にする。
開発者への利便性向上
複雑な設定なしに Diffusers を通じて高性能かつ軽量な推論が可能となり、実装のハードルが下がる。
重要な引用
Hugging Face が、Diffusers ライブラリに Nunchaku の 4 ビット拡散モデル推論機能を追加したと発表した
これにより、低リソース環境での効率的な画像生成が可能になる
影響分析・編集コメントを表示
影響分析
この発表は、拡散モデルのデプロイメントにおけるハードウェア要件を緩和する重要な一歩であり、開発者がより幅広い環境で高性能な画像生成を実現できる基盤を整えた。特にリソース制約が厳しい現場やエッジデバイスでの実用化を加速させる効果が期待される。
編集コメント
Diffusers という主要なオープンソースライブラリに Nunchaku のような高度な量子化技術が標準的に統合されたことは、開発者の実装負担を劇的に減らす画期的な動きです。これにより、高性能な画像生成モデルの導入障壁がさらに下がるでしょう。
大規模な拡散トランスフォーマーは、驚くほど美しい画像(さらには動画や音声のスニペット、そして最近ではテキスト)を生成できます。しかし、最新のテキストから画像への変換モデルを BF16 精度で読み込むには、通常 20〜30 GB の VRAM が必要となり、これは一般的な消費者向け GPU では対応が難しいレベルです。
この課題に対する強力な解決策として「量子化(Quantization)」があります。Diffusers はすでに bitsandbytes、GGUF、torchao、Quanto といった複数の量子化バックエンドを統合しており、これらについては Diffusers における量子化バックエンドの探求 で詳しく解説しています。
これらのバックエンドの多くは「ウェイトのみ(weight-only)」の方式です。これは、重みを低精度で保存し、計算時に高精度に展開(デ量子化)する仕組みを指します。これによりメモリ使用量は大幅に削減されますが、通常は推論速度の向上には寄与せず、場合によってはわずかなレイテンシの増加を招くこともあります。
人気のある推論エンジン Nunchaku の背後にある量子化手法 SVDQuant は、これとは異なるアプローチを採用しています。これは、主要なトランスフォーマー層を 4 ビットの重みと活性化値(W4A4)で実行するもので、メモリ使用量を削減しつつ、ノイズ除去ループの処理速度も向上させます。
詳細は後述しますが、これまでこれらのチェックポイントを使用するには、専用の推論ライブラリが必要でした。
現在の Diffusers では、Nunchaku チェックポイントの読み込みは from_pretrained() を呼び出すだけで完了します。kernels パッケージのおかげで、ローカルでの CUDA コンパイルは不要です。
また、サードパーティ製のツールキット diffuse-compressor を使えば、新しいアーキテクチャを自分で量子化し、通常の Diffusers リポジトリとして公開することも可能です。

目次
- Nunchaku Lite の始め方
- 背景:SVDQuant と Nunchaku
- Nunchaku Lite の紹介
- Diffusers でのネイティブ読み込み
- さらに高速化とメモリ削減を実現
- ベンチマーク結果
- 独自のモデルを量子化する
- すぐに使えるチェックポイント
- まとめ
- お礼
Nunchaku Lite の始め方
まずは必要なパッケージをインストールしましょう。最新の Diffusers と、Hugging Face の kernels パッケージが必要です。
pip install -U diffusers transformers accelerate kernels bitsandbytes
次に、他の Diffusers モデルと同様に、事前量子化済みのパイプラインを読み込みます。
import torch
from diffusers import ErnieImagePipeline
pipe = ErnieImagePipeline.from_pretrained(
"lite-infer/ERNIE-Image-Turbo-nunchaku-lite-nvfp4_r32-bnb4-text-encoder",
torch_dtype=torch.bfloat16,
).to("cuda")
image = pipe(
prompt="A cinematic portrait of a red fox in a misty forest at sunrise, "
"detailed fur, volumetric light",
height=1024,
width=1024,
num_inference_steps=8,
guidance_scale=1.0,
generator=torch.Generator("cuda").manual_seed(42),
).images[0]
image.save("output.png")

カスタムパイプラインクラスを用意したり、別個の推論エンジンを使ったりする必要はありません。ローカルでのコンパイルも不要です。NVFP4 カーネルは、初めて使用した際に Nunchaku Lite kernels page から自動的にダウンロードされます。
このチェックポイントは、Nunchaku NVFP4 トランスフォーマーと bitsandbytes NF4 テキストエンコーダーを組み合わせ、RTX 5090 で 1024x1024 の画像を約 1.7 秒で生成します。ピークメモリ使用量は約 12GB です。一方、BF16 パイプラインでは約 24GB を必要とします。
Nunchaku Lite チェックポイントの詳細な形式については、公式 Diffusers ドキュメントをご覧ください。
NVFP4 チェックポイントは NVIDIA Blackwell GPU(RTX 50 シリーズ、RTX PRO 6000、B200)が必要です。それ以前の世代の GPU をお使いの場合は、INT4 バリアントをご利用ください。詳細は以下の ハードウェアサポート テーブルをご確認ください。
背景:SVDQuant と Nunchaku
SVDQuant は、Nunchaku の背後にある量子化手法であり、その参照用 CUDA 推論エンジンでもあります。拡散トランスフォーマーにおける標準的な 4 ビット量子化は困難を伴います。なぜなら、重みと活性化の両方に大きな外れ値が含まれているからです。SVDQuant は、この課題に対処するために、活性化の外れ値を重みに移動させます。具体的には、各重み行列の中で最も扱いにくい部分を小さな 16 ビットの低ランクブランチで表現し、残りの部分(残余)を 4 ビットに量子化します。Nunchaku では、4 ビットパスと低ランクブランチの両方に対して融合カーネルを採用することで、この処理を高速化しています。

Nunchaku は、低ランク降下投影を量子化カーネルと融合させ、低ランク上昇投影を 4 ビット計算カーネルと融合させることで、16 ビットブランチにおけるメモリアクセスのオーバーヘッドを排除しています。図は SVDQuant の論文 から引用。
Nunchaku Lite の紹介
元々の Nunchaku エンジン は、モデル固有の融合実行パス(例:融合された QKV 投影や GELU/MLP カーネル)によって大幅な高速化を実現しています。これらの最適化は各アーキテクチャのモジュールレイアウトとチェックポイント形式に依存しているため、新しいモデルファミリーをサポートするには、通常、モデルごとの統合作業が必要となります。
Nunchaku Liteは、Diffusersにおける新しい統合パスです。これにより、カスタムパイプラインや別個の推論エンジンを用意しなくても、DiffusersでNunchakuスタイルのチェックポイントを読み込めるようになります。
内部では、Nunchaku Liteはチェックポイント読み込み前に、標準的なDiffusersモデル内の関連するnn.Linearモジュールを、ランタイム実行時のSVDQ/AWQ対応の線形層にパッチ適用します。CUDAカーネルは、kernelsパッケージを通じてHubから取得されます。ここでは2つのカーネルファミリーが使用されています。
- svdq_w4a4:SVDQuantによる低ランク補正を備えた4ビット重みと活性化値です。この層はトランスフォーマーの注意機構(attention)やMLP投影に用いられ、計算量のほとんどがこの部分で消費されます。INT4およびNVFP4のバリアントが利用可能です。
- awq_w4a16:4ビット重みと16ビット活性化値を使用します。FLUXのadanorm_single/ananorm_zeroやQwen-Imageのモジュレーション層など、適応型正規化やモジュレーション投影に用いられます。これらの層はメモリーバウンドかつ精度感度が高いため、AWQを採用することで、メモリと容量を節約しつつ精度を維持するのに適しています。
トレードオフとして、アーキテクチャ固有の融合カーネルやモジュールがないため、Nunchaku LiteがオリジナルのNunchakuエンジンほどの高速化を実現することはできません。しかし、最小限の実装でもVRAM削減効果は同等に保ちつつ、約30%の速度向上をもたらします。
Diffusersにおけるネイティブ読み込み
Diffusers で bitsandbytes や torchao を使った経験があれば、Nunchaku Lite の仕組みもすぐに馴染むはずです。Nunchaku Lite 対応モデルのリポジトリは、通常の Diffusers リポジトリと変わりありません。特別な点は、transformer の config.json ファイル内にある quantization_config ブロックだけです。
"quantization_config": {
"quant_method": "nunchaku_lite",
"compute_dtype": "bfloat16",
"svdq_w4a4": {
"precision": "nvfp4",
"group_size": 16,
"rank": 32,
"targets": [
"layers.0.self_attention.to_q",
"layers.0.self_attention.to_k",
"..."
]
},
"awq_w4a16": {
"precision": "int4",
"group_size": 64,
"targets": [
"adaLN_modulation.1",
"..."
]
}
}
この設定は、Diffusers にどのモジュールを量子化するか、どのような方式を使うか、そして Nunchaku Lite ランタイムのどのレイヤー(SVDQW4A4Linear または AWQW4A16Linear)をインスタンス化するのかを指示します。
量子化モデルでも元の密なモデルと同じモジュール構造が維持されているため、スケジューラーや LoRA の読み込みフック、オフローディング、torch.compile といった下流の処理も、通常の Diffusers モデルとして認識されます。
ハードウェア対応状況
Nunchaku Lite は、GPU の世代とチェックポイントの精度に応じて異なるカーネルバリアントを使用します:
| スキーム | 精度 | 対応 GPU |
|---|---|---|
| svdq_w4a4 | nvfp4 | Blackwell (RTX 50 シリーズ、RTX PRO 6000、B200) |
| svdq_w4a4 | int4 | Turing / Ampere / Ada (RTX 30 & 40 シリーズ、A100、L40S) |
| awq_w4a16 | int4 | Turing / Ampere / Ada (RTX 30 & 40 シリーズ、A100、L40S) |
Volta および Hopper GPU は、現在 4 ビットカーネルに対応していません。
量子化器はロード時に GPU の CUDA 能力を検証し、誤った出力を生成するのではなく、明確なエラーを返します。
より高速で、より少ないメモリへ
Nunchaku Lite は、Diffusers が提供する他のメモリ最適化や速度向上機能と組み合わせることができます。
torch.compile
トランスフォーマーをコンパイルすると、エンドツーエンドの速度向上率が 1.35 倍から 1.8 倍に改善されます:
pipe.transformer.compile(fullgraph=True)または、より高速なコンパイルのために compile_repeated_blocks() を使用します
pipe.transformer.compile_repeated_blocks(fullgraph=True)量子化されたテキストエンコーダー
トランスフォーマーだけが大きなメモリを消費するわけではありません。T5 や Qwen3 などのテキストエンコーダーは、それ単体で数ギガバイトの容量を占有します。bitsandbytes の NF4 を用いてテキストエンコーダーもさらに量子化すると、ベンチマークではピーク VRAM が約 22% 削減されます。
オフローディング
パイプラインをより小さな GPU に収めたい場合、enable_model_cpu_offload() や enable_sequential_cpu_offload() といった Diffusers のオフローディングヘルパーは通常どおり機能します。
ベンチマーク結果
以下の数値は、NVIDIA RTX PRO 6000 (Blackwell) を使用し、解像度 1024x1024 で測定したものです。モデルには rootonchair/ERNIE-Image-Turbo-nunchaku-lite-int4-bnb4-text-encoder を使用しました。
エンドツーエンドのレイテンシとメモリ使用量
| 構成 | フルパイプライン | デノイズループ | ピーク VRAM | 速度向上率 |
|---|---|---|---|---|
| BF16 ベースライン | 3.00 秒 | 2.86 秒 | 31.1 GB | 1.0x |
Nunchaku Lite NVFP4
2.27 秒
2.13 秒
20.6 GB
1.35 倍
Nunchaku Lite NVFP4 + torch.compile
1.68 秒
1.53 秒
20.6 GB
1.8 倍
Nunchaku Lite NVFP4 + NF4 テキストエンコーダー
2.29 秒
2.13 秒
16.0 GB
1.35 倍
上記の結果が示す通り、Nunchaku を採用するとピーク VRAM(ビデオメモリ)使用量を最大 50% 削減できながら、レイテンシも約 30% 短縮できます。残りのオーバーヘッドは主にカーネル起動の増加によるものでしたが、torch.compile を活用することでこれを解消し、フルパイプラインの実行時間を 1.68 秒にまで短縮。これは BF16 ベースラインと比較して 1.8 倍の高速化となります。
画像品質

BF16 と 4 ビット出力を、シードと設定を同一にして比較した結果。
独自のモデルの量子化
Diffusers における Nunchaku Lite のサポートはアーキテクチャに依存しません。また、diffuse-compressor ツールキットを使えば、Diffusers モデル向けにキャリブレーション、量子化、パッケージ化、公開までの一連の SVDQuant ワークフローを完結して実行できます。
以下では、FLUX.2 Klein 4B の量子化を例に、主要な手順を解説します。具体的には、モデルの確認から始まり、トランスフォーマー部分のキャリブレーションと量子化、結果を Diffusers パイプラインとしてパッケージ化し、検証後に Hugging Face Hub への公開までを行います。各フラグの詳細については、完全なチュートリアルをご参照ください。
1. 量子化する対象の確認
スキャナーはモデルを走査し、どの部分をターゲットにするかを判断します。繰り返し現れるトランスフォーマー・ブロック内の互換性のある線形層は SVDQ W4A4 の対象となり、認識されたモジュレーション線形層は AWQ W4A4 の対象となります。それ以外の部分はすべて密(dense)なままです。
python examples/text_to_image/quantize_hf.py black-forest-labs/FLUX.2-klein-4B \
--precision int4 --rank 32 --inspect-config
量子化を行う前には、必ずこのレポートを確認してください。FLUX.2 Klein 4B の場合、期待される結果は SVDQ ターゲットが 100 個、AWQ ターゲットが 3 つ、密な外側線形層が 6 つです。パターンが欠落したり、重複した名前があったりしないことを確認してください。
2. 量子化の実行
以下のコマンドは SVDQuant をトランスフォーマー上で実行し、量子化されたチェックポイントを outputs/checkpoints/svdq-int4_r32-flux-2-klein-4b.safetensors に書き出します:
python examples/text_to_image/quantize_hf.py black-forest-labs/FLUX.2-klein-4B \
--precision int4 \
--output outputs/checkpoints/svdq-int4_r32-flux-2-klein-4b.safetensors
Blackwell ネイティブの重みを作成する場合は、--precision int4 を nvfp4 に置き換えてください。
3. Diffusers パイプラインのパッケージ化
コンバータは量子化されたトランスフォーマーをベースパイプラインの他のコンポーネントと組み合わせ、compact な nunchaku_lite の設定を transformer/config.json に書き出します。また、オプションでテキストエンコーダーも NF4 形式に変換できます。
python examples/convert_nunchaku_lite_diffusers.py \
--checkpoint outputs/checkpoints/svdq-int4_r32-flux-2-klein-4b.safetensors \
--model-id black-forest-labs/FLUX.2-klein-4B \
--bnb4-text-encoder text_encoder \
--compute-dtype bfloat16 \
--output-dir outputs/diffusers/FLUX.2-klein-4B-nunchaku-lite-int4-bnb4-text-encoder
4. ロード、検証、そして Hub へのアップロード
import torch
from diffusers import DiffusionPipeline
pipe = DiffusionPipeline.from_pretrained(
"outputs/diffusers/FLUX.2-klein-4B-nunchaku-lite-int4-bnb4-text-encoder",
device_map="cuda",
)
image = pipe(
"A glass robot in a greenhouse, cinematic lighting",
num_inference_steps=4, guidance_scale=1.0,
generator=torch.Generator("cuda").manual_seed(12345),
).images[0]
出力結果に問題がなければ、pipe.push_to_hub("your-name/your-model-nunchaku-lite-int4") を実行して Hub にアップロードしましょう。これで他のユーザーも、先ほど示した from_pretrained() のパターンを使ってモデルをロードできるようになります。
構造的書き換えによるモデルの量子化
一般的な手順では、アーキテクチャに構造的な書き換えが必要ないことを前提としています。さらに高速化を図るには、元の Nunchaku エンジンが Diffusers のレイヤー群を融合モジュールとして書き換える必要があります。一般的な手順だけでは、Q、K、V 投影を一つのモジュールに結合したり、融合された投影を複数のモジュールに分割したりといった変更を検出・適用することはできません。
FLUX.1-dev の QKV プロジェクションは具体的な例です。Diffusers では 3 つのモジュールが別々に定義されています:
self.to_q = torch.nn.Linear(query_dim, self.inner_dim, bias=bias)
self.to_k = torch.nn.Linear(query_dim, self.inner_dim, bias=bias)
self.to_v = torch.nn.Linear(query_dim, self.inner_dim, bias=bias)Nunchaku の FLUX モジュールは、これら 3 つの層を結合し、1 つの量子化された to_qkv モジュールとして実装しています:
to_qkv = fuse_linears([other.to_q, other.to_k, other.to_v])
self.to_qkv = SVDQW4A4Linear.from_linear(to_qkv, **kwargs)この結合されたモジュールが必要な理由は、Nunchaku の融合演算子が QKV プロジェクション、Q/K 正規化、そして回転埋め込み(rotary embeddings)をまとめて処理するためです。一方、デフォルトの Diffusers のパス では、これらは個別に実行されます:
query = attn.to_q(hidden_states)
key = attn.to_k(hidden_states)
value = attn.to_v(hidden_states)
query = query.unflatten(-1, (attn.heads, -1))
key = key.unflatten(-1, (attn.heads, -1))
value = value.unflatten(-1, (attn.heads, -1))
query = attn.norm_q(query)
key = attn.norm_k(key)if image_rotary_emb is not None:
query = apply_rotary_emb(query, image_rotary_emb, sequence_dim=1)
key = apply_rotary_emb(key, image_rotary_emb, sequence_dim=1)
Nunchaku のパス では、グループ化された投影(projection)や正規化モジュール、ロータリ埋め込みを 1 つの融合演算子にまとめています。
qkv = fused_qkv_norm_rottary(
hidden_states, attn.to_qkv, attn.norm_q, attn.norm_k, image_rotary_emb
)
これは汎用的なパスでは推測できない構造的な書き換えです。Diffusers では to_q、to_k、to_v というパラメータ接頭辞を持つ 3 つの宛先モジュールが存在する一方、Nunchaku では to_qkv の下に 1 つのグループ化されたモジュールが用意されています。したがって、Q、K、V パラメータを出力次元に沿って(その順序で)結合し、to_qkv に読み込む必要があることを示す、モデル固有のターゲット設定やアダプターが必要です。
こうした構造的な書き換えは、量子化時にモデル固有のターゲット設定ファイルによって記述され、チェックポイントが読み込まれる際に小さなランタイムアダプターによって処理されます。
構造的に書き換えられたチェックポイントを生成するための具体的なターゲット設定の例については、FLUX.2 Klein 4B 量子化スクリプト をご覧ください。また、グループ化された QKV テンソルの読み込みや、融合された投影行列の分割、その他の融合演算の処理に必要なランタイムアダプターは、rootonchair/nunchaku-lite で提供されています。
完全なワークフローについては、新しいモデルの追加方法 のガイドをご覧ください。
すぐに使えるチェックポイント
すぐに使い始めるには、以下のリポジトリを確認してください:
- rootonchair/ERNIE-Image-Turbo-nunchaku-lite-int4-bnb4-text-encoder: bitsandbytes NF4 テキストエンコーダーを搭載した INT4 版 ERNIE-Image-Turbo
- rootonchair/ERNIE-Image-Turbo-nunchaku-lite-nvfp4-bnb4-text-encoder: bitsandbytes NF4 テキストエンコーダーを搭載した NVFP4 版 ERNIE-Image-Turbo
- OzzyGT/Krea_2_Turbo_nunchaku_lite_nvfp4: NVFP4 版 Krea 2 Turbo チェックポイント
- lite-infer: Nunchaku Lite のチェックポイントとコレクションの追加情報
結論
Nunchaku の SVDQuant カーネルは、コンシューマー向けハードウェア上で拡散トランスフォーマーを効率的に実行するための最も効果的な手法の一つです。この機能は現在、Diffusers でネイティブサポートされています。
事前量子化されたチェックポイントは from_pretrained() を使用して読み込むことができますし、diffuse-compressor ツールキットを使えば、エンジン側のサポート待ちなしで新しいアーキテクチャを量子化することも可能です。重みと活性化の両方を量子化する W4A4 パスでは、メモリ使用量を削減しつつ推論遅延も改善されながら、画像品質は BF16 版に匹敵するレベルを維持します。
もしあなたが新しいモデルを量子化して公開される場合は、ぜひその成果をお聞かせください。Hugging Face Hub に投稿して、私たちまでご連絡ください。本機能についてご質問がある場合は、お気軽に Discord にご参加ください。
詳しくは以下のリソースをご覧ください:
- Diffusers Nunchaku ドキュメント
- 統合に関する PR (huggingface/diffusers#14100)
- SVDQuant の論文と Nunchaku エンジン
- diffuse-compressor
- 過去の投稿:Diffusers における量子化バックエンドの探求、Quanto と Diffusers を使ったメモリ効率の高い拡散トランスフォーマー
謝辞
統合プロセスを通じてレビューやガイダンスをいただいた Diffusers のメンテナの皆様、そして SVDQuant の元となる研究を行った MIT HAN Lab / Nunchaku チームに感謝いたします。また、本ブログ記事へのフィードバックを提供してくださった Marc Sun 様、nunchaku-lite を試してご意見をくださった Álvaro Somoza 様にも厚く御礼申し上げます。
rootonchair は、本研究への支援と開発の多くが行われた環境を提供してくれた SilverAI にも感謝しています。
原文を表示
Large diffusion transformers can create stunning images (or even videos, audio snippets, and now text), but loading a modern text-to-image model in BF16 precision often requires 20-30 GB of VRAM, which puts these models out of reach of most consumer GPUs. Quantization is a powerful solution to this problem, and Diffusers already integrates several quantization backends such as bitsandbytes, GGUF, torchao, and Quanto, which we covered in Exploring Quantization Backends in Diffusers.
Most of these backends are *weight-only*. This means that they store the weights in low precision and dequantize them back to high precision at compute time. This reduces memory usage significantly, but it usually does not make inference faster, and can even add a small latency overhead.
SVDQuant, the quantization method behind the popular Nunchaku inference engine, takes a different approach. It runs the main transformer layers with 4-bit weights and activations (W4A4), reducing memory while also speeding up the denoising loop. The details are covered below, but until now, using these checkpoints required a separate inference library.
With current Diffusers, loading a Nunchaku checkpoint is as simple as calling from_pretrained(), with no local CUDA compilation required thanks to the kernels package. In addition, the companion diffuse-compressor toolkit lets you quantize new architectures yourself and publish them as regular Diffusers repositories.

Table of Contents
- Getting started with Nunchaku Lite
- Background: SVDQuant and Nunchaku
- Introducing Nunchaku Lite
- Native loading in Diffusers
- Getting more speed and lower memory
- Benchmarks
- Quantizing your own model
- Ready-to-use checkpoints
- Conclusion
- Acknowledgements
Getting started with Nunchaku Lite
First, install the requirements. You need a recent version of Diffusers and the Hugging Face kernels package:
pip install -U diffusers transformers accelerate kernels bitsandbytes
Then load a pre-quantized pipeline like any other Diffusers model:
import torch
from diffusers import ErnieImagePipeline
pipe = ErnieImagePipeline.from_pretrained(
"lite-infer/ERNIE-Image-Turbo-nunchaku-lite-nvfp4_r32-bnb4-text-encoder",
torch_dtype=torch.bfloat16,
).to("cuda")
image = pipe(
prompt="A cinematic portrait of a red fox in a misty forest at sunrise, "
"detailed fur, volumetric light",
height=1024,
width=1024,
num_inference_steps=8,
guidance_scale=1.0,
generator=torch.Generator("cuda").manual_seed(42),
).images[0]
image.save("output.png")

No custom pipeline class or separate inference engine is needed, and there is nothing to compile locally. The NVFP4 kernels are downloaded from the Hub through the Nunchaku Lite kernels page the first time they are used. This checkpoint pairs a Nunchaku NVFP4 transformer with a bitsandbytes NF4 text encoder, and generates a 1024x1024 image in about 1.7 seconds on an RTX 5090 with a peak memory usage of about 12 GB, compared with about 24 GB for the BF16 pipeline. You can find more details about the Nunchaku Lite checkpoint format in the official Diffusers documentation.
NVFP4 checkpoints require an NVIDIA Blackwell GPU (RTX 50 series, RTX PRO 6000, B200). For earlier generations, use the INT4 variants. See the hardware support table below for details.
Background: SVDQuant and Nunchaku
SVDQuant is the quantization method behind Nunchaku, its reference CUDA inference engine. Standard 4-bit quantization is difficult for diffusion transformers because both weights and activations contain large outliers. SVDQuant handles this by moving activation outliers into the weights, representing the hardest part of each weight matrix with a small 16-bit low-rank branch, and quantizing the remaining residual to 4 bits. Nunchaku makes this fast with fused kernels for the 4-bit path and the low-rank branch.
Nunchaku fuses the low-rank down projection with the quantization kernel and the low-rank up projection with the 4-bit compute kernel, eliminating the memory access overhead of the 16-bit branch. Figure from the [SVDQuant paper.](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/nunchaku-diffusers/svdquant_kernel_fusion.png)
Introducing Nunchaku Lite
The original Nunchaku engine gets much of its speed from model-specific fused execution paths, such as fused QKV projections and fused GELU/MLP kernels. Those optimizations are tied to each architecture's module layout and checkpoint format, so supporting a new model family usually requires model-specific integration work.
Nunchaku Lite is the new integration path in Diffusers. With it, Diffusers can load Nunchaku-style checkpoints without a custom pipeline or a separate inference engine. Under the hood, Nunchaku Lite patches the relevant nn.Linear modules of a stock Diffusers model with runtime SVDQ/AWQ linear layers before the checkpoint is loaded. The CUDA kernels come from the Hub through the kernels package. Two kernel families are used:
- svdq_w4a4: 4-bit weights and activations with the SVDQuant low-rank correction. This layer is used for the transformer's attention and MLP projections, where nearly all of the compute is spent, and is available in INT4 and NVFP4 variants.
- awq_w4a16: 4-bit weights with 16-bit activations, used for adaptive normalization and modulation projections such as FLUX adanorm_single / adanorm_zero or Qwen-Image modulation layers. These layers are memory-bound and precision-sensitive, making AWQ a good fit to preserve precision while still saving memory and space.
The trade-off is that, without architecture-specific fused kernels and modules, Nunchaku Lite cannot match the speedup of the original Nunchaku engine. However, the bare-bones implementation still delivers around 30% speedup while retaining the same level of VRAM reduction.
Native loading in Diffusers
If you have used bitsandbytes or torchao in Diffusers, the mechanics will feel familiar. A Nunchaku Lite model repository is an ordinary Diffusers repository. The only special part is a quantization_config block inside the transformer's config.json:
"quantization_config": {
"quant_method": "nunchaku_lite",
"compute_dtype": "bfloat16",
"svdq_w4a4": {
"precision": "nvfp4",
"group_size": 16,
"rank": 32,
"targets": [
"layers.0.self_attention.to_q",
"layers.0.self_attention.to_k",
"..."
]
},
"awq_w4a16": {
"precision": "int4",
"group_size": 64,
"targets": [
"adaLN_modulation.1",
"..."
]
}
}
This config tells Diffusers which modules were quantized, which scheme they use, and which Nunchaku Lite runtime layer to instantiate (SVDQW4A4Linear or AWQW4A16Linear).
Because the quantized model keeps the exact module structure of the dense one, everything downstream (schedulers, LoRA loading hooks, offloading, torch.compile) sees a normal Diffusers model.
Hardware support
Nunchaku Lite uses different kernel variants depending on the GPU generation and checkpoint precision:
Scheme
Precision
Supported GPUs
svdq_w4a4
nvfp4
Blackwell (RTX 50 series, RTX PRO 6000, B200)
svdq_w4a4
int4
Turing / Ampere / Ada (RTX 30 & 40 series, A100, L40S)
awq_w4a16
int4
Turing / Ampere / Ada (RTX 30 & 40 series, A100, L40S)
Volta and Hopper GPUs are currently not supported by the 4-bit kernels. The quantizer validates the GPU's CUDA capability at load time and raises a clear error instead of producing incorrect outputs.
Getting more speed and lower memory
Nunchaku Lite can be combined with other Diffusers memory and speed optimizations.
torch.compile. Compiling the transformer improves the end-to-end speedup from 1.35x to 1.8x:
pipe.transformer.compile(fullgraph=True)
# or compile_repeated_blocks() for faster compilation
pipe.transformer.compile_repeated_blocks(fullgraph=True)
Quantized text encoders. The transformer is not the only component with a large memory footprint. Text encoders such as T5 or Qwen3 can occupy several gigabytes on their own. Further quantizing the text encoder with bitsandbytes NF4 reduces peak VRAM by about 22% in our benchmark.
Offloading. Diffusers offloading helpers such as enable_model_cpu_offload() and enable_sequential_cpu_offload() work as usual if you need to fit the pipeline onto a smaller GPU.
Benchmarks
All numbers below were measured on an NVIDIA RTX PRO 6000 (Blackwell) at 1024x1024 using rootonchair/ERNIE-Image-Turbo-nunchaku-lite-int4-bnb4-text-encoder.
End-to-end latency and memory
Configuration
Full pipeline
Denoise loop
Peak VRAM
Speedup
BF16 baseline
3.00 s
2.86 s
31.1 GB
1.0x
Nunchaku Lite NVFP4
2.27 s
2.13 s
20.6 GB
1.35x
Nunchaku Lite NVFP4 + torch.compile
1.68 s
1.53 s
20.6 GB
1.8x
Nunchaku Lite NVFP4 + NF4 text encoder
2.29 s
2.13 s
16.0 GB
1.35x
As shown above, Nunchaku reduces peak VRAM by up to 50% while still improving latency by roughly 30%. The remaining overhead comes largely from extra kernel launches, which torch.compile can mitigate, bringing the full pipeline down to 1.68 s, or 1.8x faster than the BF16 baseline.
Image quality

Quantizing your own model
Nunchaku Lite support in Diffusers is architecture-agnostic, and the diffuse-compressor toolkit provides an end-to-end SVDQuant workflow for Diffusers models: calibrate, quantize, package, and publish.
Below, we walk through quantizing FLUX.2 Klein 4B as an example. It covers the main steps: inspect the model, calibrate and quantize the transformer, package the result as a Diffusers pipeline, then verify and push it to the Hub. The full tutorial covers every flag in detail.
1. Inspect what will be quantized
The generic scanner walks the model and decides what to target: compatible linears inside the repeated transformer-block stack become SVDQ W4A4 targets, recognized modulation linears become AWQ W4A16 targets, and everything else stays dense.
python examples/text_to_image/quantize_hf.py black-forest-labs/FLUX.2-klein-4B \
--precision int4 --rank 32 --inspect-config
Always read this report before quantizing. For FLUX.2 Klein 4B, the expected result is 100 SVDQ targets, 3 AWQ targets, and 6 dense outer linears, with no missing patterns or duplicate names.
2. Run quantization
The following command runs SVDQuant on the transformer and writes the quantized checkpoint to outputs/checkpoints/svdq-int4_r32-flux-2-klein-4b.safetensors:
python examples/text_to_image/quantize_hf.py black-forest-labs/FLUX.2-klein-4B \
--precision int4 \
--output outputs/checkpoints/svdq-int4_r32-flux-2-klein-4b.safetensors
Replace --precision int4 with nvfp4 to build Blackwell-native weights.
3. Package a Diffusers pipeline
The converter combines the quantized transformer with the base pipeline's other components, writes the compact nunchaku_lite configuration into transformer/config.json, and can optionally convert text encoders to NF4:
python examples/convert_nunchaku_lite_diffusers.py \
--checkpoint outputs/checkpoints/svdq-int4_r32-flux-2-klein-4b.safetensors \
--model-id black-forest-labs/FLUX.2-klein-4B \
--bnb4-text-encoder text_encoder \
--compute-dtype bfloat16 \
--output-dir outputs/diffusers/FLUX.2-klein-4B-nunchaku-lite-int4-bnb4-text-encoder
4. Load, verify, and push to the Hub
import torch
from diffusers import DiffusionPipeline
pipe = DiffusionPipeline.from_pretrained(
"outputs/diffusers/FLUX.2-klein-4B-nunchaku-lite-int4-bnb4-text-encoder",
device_map="cuda",
)
image = pipe(
"A glass robot in a greenhouse, cinematic lighting",
num_inference_steps=4, guidance_scale=1.0,
generator=torch.Generator("cuda").manual_seed(12345),
).images[0]
Once the outputs look good, run pipe.push_to_hub("your-name/your-model-nunchaku-lite-int4"). Other users can then load it with the same from_pretrained() pattern shown above.
Quantizing models with structural rewrites
Note that the generic path assumes the architecture can be quantized without structural rewrites. For additional speedup, the original Nunchaku engine rewrites groups of Diffusers layers as fused modules. The generic path cannot infer these changes on its own, such as combining separate Q, K, and V projections into one module or splitting a fused projection across several modules.
FLUX.1-dev's QKV projection is a concrete example. Diffusers defines three separate modules:
self.to_q = torch.nn.Linear(query_dim, self.inner_dim, bias=bias)
self.to_k = torch.nn.Linear(query_dim, self.inner_dim, bias=bias)
self.to_v = torch.nn.Linear(query_dim, self.inner_dim, bias=bias)
The Nunchaku FLUX module combines those layers into one quantized to_qkv module:
to_qkv = fuse_linears([other.to_q, other.to_k, other.to_v])
self.to_qkv = SVDQW4A4Linear.from_linear(to_qkv, **kwargs)
This grouped module is required because Nunchaku's fused operator consumes the QKV projection, Q/K normalization, and rotary embeddings together. By comparison, the default Diffusers path executes them separately:
query = attn.to_q(hidden_states)
key = attn.to_k(hidden_states)
value = attn.to_v(hidden_states)
query = query.unflatten(-1, (attn.heads, -1))
key = key.unflatten(-1, (attn.heads, -1))
value = value.unflatten(-1, (attn.heads, -1))
query = attn.norm_q(query)
key = attn.norm_k(key)
if image_rotary_emb is not None:
query = apply_rotary_emb(query, image_rotary_emb, sequence_dim=1)
key = apply_rotary_emb(key, image_rotary_emb, sequence_dim=1)
The Nunchaku path supplies the grouped projection, normalization modules, and rotary embeddings to one fused operator:
qkv = fused_qkv_norm_rottary(
hidden_states, attn.to_qkv, attn.norm_q, attn.norm_k, image_rotary_emb
)
This is the structural rewrite that the generic path cannot infer. Diffusers has three destination modules with to_q, to_k, and to_v parameter prefixes, while Nunchaku has one grouped module under to_qkv. A model-specific target config or adapter must state that the Q, K, and V parameters should be concatenated along the output dimension, in that order, and loaded into to_qkv.
Structural rewrites like these are described by a model-specific target config during quantization and handled by a small runtime adapter when the checkpoint is loaded.
The FLUX.2 Klein 4B quantization script provides a concrete target-config example for producing a structurally rewritten checkpoint, while rootonchair/nunchaku-lite provides the runtime adapters needed to load grouped QKV tensors, split fused projections, and other fused operations.
For the complete workflow, you can check the Adding A New Model guide.
Ready-to-use checkpoints
To get started right away, check out the following repositories:
- rootonchair/ERNIE-Image-Turbo-nunchaku-lite-int4-bnb4-text-encoder: INT4 ERNIE-Image-Turbo with a bitsandbytes NF4 text encoder
- rootonchair/ERNIE-Image-Turbo-nunchaku-lite-nvfp4-bnb4-text-encoder: NVFP4 ERNIE-Image-Turbo with a bitsandbytes NF4 text encoder
- OzzyGT/Krea_2_Turbo_nunchaku_lite_nvfp4: NVFP4 Krea 2 Turbo checkpoint
- lite-infer: more Nunchaku Lite checkpoints and collections
Conclusion
Nunchaku's SVDQuant kernels are one of the most effective ways to run diffusion transformers efficiently on consumer hardware, and they are now natively supported in Diffusers. Pre-quantized checkpoints load with from_pretrained(), and the diffuse-compressor toolkit makes it possible to quantize new architectures without waiting for engine support. By quantizing both weights and activations, the W4A4 path lowers memory use while improving denoising latency, keeping image quality close to the BF16 original.
If you quantize and publish a new model, we would love to hear about it. Share it on the Hub and let us know! If you have any questions about this feature, feel free to join our Discord.
To learn more, check out the following resources:
- Diffusers Nunchaku documentation
- The integration PR (huggingface/diffusers#14100)
- SVDQuant paper and the Nunchaku engine
- diffuse-compressor
- Previous posts: Exploring Quantization Backends in Diffusers and Memory-efficient Diffusion Transformers with Quanto and Diffusers
Acknowledgements
Thanks to the Diffusers maintainers for reviews and guidance throughout the integration, and to the MIT HAN Lab / Nunchaku team for the original SVDQuant work. Thanks to Marc Sun for providing feedback on the blog post. Thanks to Álvaro Somoza for trying out nunchaku-lite and for providing feedback.
rootonchair is also grateful to SilverAI for supporting this work and providing the environment in which much of this development took place.
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み