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.1).
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ビット/トークン(fp8またはw8a8とも呼ばれます)に量子化できます。

H100のような、compute capability 9+を備えた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")

リソース

Read the Open-sourcing FBGEMM for state-of-the-art server-side inference blog post for more details on FBGEMM.

Update on GitHub