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.2).
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)을 가능하게 하는 것입니다.

이 통합은 마이크로스케일링 FP4 양자화의 약속과 성능 사이의 간극을 메우기 사전 인쇄본과 함께 제공됩니다.

현재 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,
)

또는 더 나은 품질을 위해 GPTQ로 사전 처리된 경우(FP Format Quantization Harness 참조).

FPQuantConfig(forward_dtype="mxfp4")를 통해 MXFP4와 NVFP4 중 하나를 선택할 수 있습니다. NVFP4는 더 나은 품질을 제공하지만 메모리를 약간 더 많이 사용합니다.

커널을 실행하려면 Blackwell 세대 GPU가 필요합니다. FP-Quant의 런타임 지원은 QuTLASS 라이브러리와 경량 PyTorch 인터페이스 라이브러리 fp_quant를 통해 구현됩니다. 전자(QuTLASS)는 소스에서 설치하고, 후자는 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