Transformers documentation

FBGEMM

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

FBGEMM

FBGEMM(Facebook GEneral Matrix Multiplication)是一个面向小批量场景的低精度矩阵乘法库,支持行级量化和离群值感知量化等精度损失最小化技术。借助 FBGEMM,可将模型权重量化为 8 位/通道,并将激活值量化为 8 位/token(也称为 fp8 或 w8a8)。

您需要一个具有 计算能力 9+ 的 GPU,例如 H100。

使用以下命令安装 FBGEMM_GPU 包,以确保您拥有最新版本。

pip install --upgrade accelerate fbgemm-gpu torch

如果安装遇到问题,请尝试安装 nightly release。

创建一个 FbgemmFp8Config 并将其传递给 from_pretrained(),以将模型量化为 fp8。

from transformers import FbgemmFp8Config, AutoModelForCausalLM

quantization_config = FbgemmFp8Config()
quantized_model = AutoModelForCausalLM.from_pretrained(
    "meta-llama/Meta-Llama-3-8B",
    dtype="auto",
    device_map="auto",
    quantization_config=quantization_config
)

save_pretrained() 和 from_pretrained() 支持保存和加载量化模型。

quant_path = "/path/to/save/quantized/model"
quantized_model.save_pretrained(quant_path)
model = AutoModelForCausalLM.from_pretrained(quant_path, device_map="auto")

资源

阅读开源 FBGEMM 以实现最先进的服务器端推理博客文章,了解更多关于 FBGEMM 的详细信息。

Update on GitHub