Transformers documentation

NVFP4

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

NVFP4

NVFP4는 NVIDIA의 4비트 부동소수점 형식입니다. 16개의 가중치로 구성된 각 블록은 FP8 스케일을 공유하며, 각 텐서는 그 위에 FP32 스케일을 추가로 가집니다. Transformers는 모델 로딩 시 가중치를 양자화하고, 활성화는 실시간으로 양자화합니다. 이를 통해 prefill은 Blackwell 텐서 코어에서 W4A4 matmul로, decode는 W4A16 matmul로 실행됩니다. Blackwell GPU에서 4비트 모델을 실행하는 데 사용하세요.

아래 표는 Transformers에서 NVFP4가 지원하는 내용을 요약합니다.

설정NVFP4Config
quant_methodnvfp4
워크플로Quantize while loading
Bits4
하드웨어Compute capability 10.0 이상(Blackwell)을 지원하는 CUDA GPU 1개
저장❌
파인튜닝❌
자동 컴파일✅

NVFP4 커널 설치

Transformers는 Hub의 kernels-community/nvfp4-gemm 저장소에서 NVFP4 커널을 다운로드합니다. kernels 라이브러리를 설치하세요. 해당 커널은 사용 중인 PyTorch 및 CUDA 버전과 일치하는 빌드가 필요합니다.

pip install -U "transformers[kernels]"

NVFP4로 모델 양자화

Create a NVFP4Config and pass it to from_pretrained() with a device_map that places the whole model on one CUDA GPU. The source checkpoint must have floating-point weights.

from transformers import AutoModelForCausalLM, NVFP4Config

quantization_config = NVFP4Config()
model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen3-8B",
    quantization_config=quantization_config,
    device_map="cuda",
)

NVFP4는 bias가 없고 in_features와 out_features가 모두 16으로 나누어 떨어지는 각 torch.nn.Linear 레이어를 대체합니다. 다른 linear 레이어는 원래의 정밀도를 유지합니다. NVFP4Config에는 가중치가 양자화되는 방식을 변경하는 매개변수가 없습니다.

한계

  • NVFP4는 compute capability 10.0 이상의 CUDA GPU가 필요합니다. CUDA GPU 없이 또는 구형 GPU에서 로드하면 RuntimeError가 발생합니다.
  • NVFP4는 하나의 GPU에서 실행됩니다. 여러 GPU에 걸쳐 설정된 device_map 또는 텐서 병렬성을 사용하면 ValueError가 발생합니다.
  • NVFP4는 CPU나 디스크로 오프로드할 수 없습니다. "cpu" 또는 "disk"를 포함하는 device_map이거나, device_map이 전혀 없는 경우 ValueError가 발생합니다.
  • NVFP4는 사전 양자화된 NVFP4 체크포인트를 로드할 수 없습니다. 로드 시 ValueError가 발생합니다.
  • NVFP4 모델은 저장하거나 파인튜닝할 수 없습니다.

리소스

Update on GitHub