Transformers documentation

FP-Quant

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

FP-Quant

FP-Quantは、Nvidia GPUのBlackwell世代向けに設計された量子化アルゴリズムのファミリーです。その目的は、MXFP4およびNVFP4データ型において、LLMの効率的な学習後量子化(PTQ)および量子化認識学習(QAT)を可能にすることです。

This integration accompanies the pre-print of the Bridging the Gap Between Promise and Performance for Microscaling FP4 Quantization pre-print.

現在、pseudoquantization=TrueでのQATのみがサポートされています。モデルは、quantization_config=FPQuantConfig()を指定してオンザフライで量子化できます。

from transformers import AutoModelForCausalLM, AutoTokenizer, FPQuantConfig
import torch

model = AutoModelForCausalLM.from_pretrained(
    "qwen/Qwen3-8B",
    quantization_config=FPQuantConfig(),
    device_map="auto",
    dtype=torch.bfloat16,
)

または、FP Format Quantization Harnessを参照して、より高い品質を得るためにGPTQで前処理を行ってください。

FPQuantConfig(forward_dtype="mxfp4") を使用して、MXFP4 と NVFP4 のいずれかを選択できます。NVFP4 はより高い品質を提供しますが、メモリ使用量がわずかに多くなります。

カーネルの実行には、Blackwell世代のGPUが必要です。FP-Quantのランタイムサポートは、QuTLASSライブラリと軽量なPyTorchインターフェースライブラリfp_quantを通じて実装されています。前者はソースから、後者はpip install fp_quantでのインストールを推奨します。

Blackwell世代のGPUを持っていないユーザーは、QuTLASSをインストールせずに、quantization_config=FPQuantConfig(pseudoquantization=True)を指定してこのメソッドを使用できます。これにより速度向上は得られませんが、量子化の効果を完全にエミュレートできます。

FP-Quantで事前量子化されたモデルは、ISTA-DASLabの公式コレクションでご利用いただけます。

torch.compile

FP-Quant は torch.compile と完全に互換性があります。

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, FPQuantConfig

model = AutoModelForCausalLM.from_pretrained(
    "qwen/Qwen3-8B",
    quantization_config=FPQuantConfig(),
    device_map="auto",
    dtype=torch.bfloat16,
)

model.forward = torch.compile(model.forward, mode="max-autotune", fullgraph=True)

高速化

FP-Quant は、非常に大きなバッチサイズでの処理において、現時点で最高のパフォーマンスを発揮します。

高速化の詳細については、QuTLASS READMEを参照してください。

Update on GitHub