VLLM支持使用llmcompressor同时使用SmoothQuant和GPTQ这2种量化方式:

from llmcompressor.transformers import oneshot
from llmcompressor.modifiers.quantization import GPTQModifier
from llmcompressor.modifiers.smoothquant import SmoothQuantModifier

# Configure the quantization algorithms
recipe = [
    SmoothQuantModifier(smoothing_strength=0.8),
    GPTQModifier(targets="Linear", scheme="W8A8", ignore=["lm_head"]),
]

# Apply quantization
oneshot(
    model=model,
    dataset=ds,
    recipe=recipe,
    max_seq_length=MAX_SEQUENCE_LENGTH,
    num_calibration_samples=NUM_CALIBRATION_SAMPLES,
)

# Save the compressed model
SAVE_DIR = MODEL_ID.split("/")[1] + "-W8A8-Dynamic-Per-Token"
model.save_pretrained(SAVE_DIR, save_compressed=True)
tokenizer.save_pretrained(SAVE_DIR)

VLLM文档:INT8 W8A8 — vLLM

SmoothQuant是W8A8,GPTQ是W8A16,两者一起使用,可以得到精度损失更小的W8A8量化。

DeepSeek的解释:

  • SmoothQuant mathematically "migrates" quantization difficulty from activations to weights, making activations easier to quantize.

  • GPTQ then optimizes the 8-bit weight quantization using the smoothed activations as a calibration dataset.

  • Together, they achieve W8A8 with minimal accuracy loss compared to FP16/FP32 models.

Logo

火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。

更多推荐