技术指南

模型量化

模型量化以较低精度的格式表示选定的神经网络值,以减少其存储或计算成本。

听听这个指南AI叙述 · ~2 min

在本页阅读时间:2分钟
  1. 概述
  2. 深入探讨
  3. 现实世界的实施
  4. 模型量化的未来
  5. 付诸实践
  6. 不断探索
  7. 常见问题

概述

Whether it improves speed and preserves quality depends on the quantization method, kernels, hardware, and task.

深入探讨

Trained models normally store each weight as a 32-bit or 16-bit floating-point number. Quantization replaces those with lower-precision formats like 8-bit integers (INT8) or 4-bit values (INT4), reducing the raw storage of the quantized values according to their bit width. Seventy billion weights have a raw payload of about 140 GB at sixteen bits or 35 GB at four bits, before scales, metadata, unquantized tensors, caches, and other runtime memory. Whether the model fits depends on actual device capacity. The catch is accuracy: squeezing a wide range of values into 256 or 16 buckets loses detail. Modern methods like GPTQ, AWQ, and the NF4 format used in QLoRA pick smart scaling factors and protect the most sensitive weights, with task-dependent quality results. Quantization is why tools like llama.cpp and Ollama can run capable models locally without a data center.

现实世界的实施

使用 llama.cpp 或使用 4 位 GGUF 文件的 Ollama 在笔记本电脑上运行 7B 或 13B Llama 模型。

QLoRA 通过将基本权重冻结在 4 位 NF4 中来微调单个 GPU 上的大型模型。

在具有设备运行时的手机上部署 INT8 模型,以便助手可以离线且私密地工作。

A serving team benchmarks INT8 or FP8 kernels and measures memory and answer quality before choosing a lower-precision deployment.

模型量化的未来

预计越来越低的精度将成为常态。研究正在推动可靠的 4 位、2 位甚至二进制权重,以及保持敏感层更高的混合精度方案。硬件如下:GPU 和手机芯片现在包含原生 INT8、INT4 和 FP8 数学单元。 FP8 和 MXFP4 等格式旨在将浮点数的范围与整数的大小结合起来。与 QLoRA 等技术相结合,量化将不断降低前沿模型在日常设备上运行和微调的成本。

付诸实践

为什么这很重要

  • 成本与预算. 多年来,架构决策决定着性能和运营成本。
  • 更清晰的判决. 技术教育帮助团队选择正确的堆栈,而不仅仅是最新的堆栈。
  • 质量控制. 更好的工程选择可以减少生产中的可靠性事故。

留意

  • 优化一项基准测试可以隐藏更广泛的系统弱点。
  • 基础设施和维护成本常常被低估。
  • 随着系统变得更加复杂,安全性和可观察性差距可能会扩大。

后续步骤

  1. 在实施之前定义延迟、质量和成本目标。
  2. 在实际负载和数据条件下进行基准测试。
  3. 仪器监控错误、漂移和用户影响。
  4. 在扩展之前准备回滚和事件响应路径。

不断探索

免费通讯

获取每日AI简报

每个工作日早晨提供三条经过验证的AI故事,使用简明英文撰写。永久免费,无广告。

每个工作日发送一封邮件。一键退订。我们永不出售或分享您的地址。

测试一下自己

Take the Model Quantization quiz

每个答案即时反馈,课程通过后可获得可验证ID的可分享证书。

开始测验

支持免费AI教育。AI Understanding是一家501(c)(3)非营利组织——无广告,无付费墙,永不收费。 捐款

常见问题

What is Model Quantization?

Model quantization represents selected neural-network values with lower-precision formats to reduce their storage or computation costs. Whether it improves speed and preserves quality depends on the quantization method, kernels, hardware, and task.

Quantizing a model mainly reduces what?

量化以更少的位存储相同的参数(例如 INT8 或 INT4,而不是 16 位或 32 位浮点数),从而减少内存并加快数学运算速度。

Ignoring scale metadata and other runtime tensors, what is the weight-payload ratio from sixteen bits to four bits per weight?

Four divided by sixteen is one quarter. Complete runtime memory also includes tensors and metadata not captured by this raw weight calculation.

激进的低位量化的主要缺点是什么?

将广泛的值映射到几个离散的级别会丢失细节,这会降低质量,除非智能缩放可以保护敏感权重。

量化感知训练与训练后量化有何不同?

量化感知训练将舍入误差构建到训练循环中,因此网络可以适应并通常在低位宽下保持更高的准确性。

哪种技术使用 4 位量化来在一个 GPU 上实现大型模型的微调?

QLoRA 将基本模型保持在 4 位 NF4 格式中并训练小型适配器权重,从而使大型模型可以在适度的硬件上进行微调。