# 量化感知的大模型推理

量化感知的大模型推理，是指以更低的数值精度——通常是 8 位或 4 位整数，或低精度浮点格式——来存储和计算大语言模型（LLM）的权重（有时还包括激活值），而非训练所用的 16 位浮点精度。其目标是在保持任务准确度接近全精度基线的同时，削减内存占用、内存带宽需求和成本。

| 关键事实 | 详情 |
|---|---|
| 主要内存节省 | 4 位权重每个参数占用的字节数仅为 FP16 的四分之一，因此一个 7B 模型的权重从约 14 GB 降至约 3.5 GB<sup>[1](https://frontiercheckpoint.com/explainers/post-training-quantization-gptq-awq-fp8/)</sup> |
| GPTQ | 利用近似二阶（海森矩阵）信息的一次性训练后量化；约四个 GPU 小时即可将 1750 亿参数模型量化到 3 或 4 位，精度退化可忽略不计<sup>[2](https://arxiv.org/abs/2210.17323)</sup> |
| GPTQ 加速效果 | 端到端推理速度在 NVIDIA A100 上约为 FP16 的 3.25 倍，在 A6000 GPU 上约为 FP16 的 4.5 倍<sup>[2](https://arxiv.org/abs/2210.17323)</sup> |
| AWQ | 激活感知的权重量化，保护约 1% 的显著权重——这些权重依据激活统计而非权重数值识别——做法是在量化前对这些通道进行缩放<sup>[3](https://arxiv.org/abs/2306.00978)</sup> |
| 校准成本 | 在 Hugging Face Transformers 中，8B 模型的 AWQ 校准在单块 A100 GPU 上约需 10 分钟，而 GPTQ 约需 20 分钟<sup>[4](https://huggingface.co/docs/transformers/quantization/selecting)</sup> |
| 8 位与 4 位的精度差异 | 在长上下文任务上，8 位量化平均损失约 0.8% 的准确度，而 4 位方法的损失要大得多，在某些长上下文评测中高达 59%<sup>[5](https://arxiv.org/abs/2505.20276)</sup> |
| 端侧部署 | TinyChat 框架可在边缘平台上运行 4 位 LLM 与视觉语言模型，速度超过 Huggingface FP16 实现 3 倍以上，其中包括在 8 GB 内存、15 W 功耗的 NVIDIA Jetson Orin Nano 上的演示<sup>[3](https://arxiv.org/abs/2306.00978)</sup><sup> • </sup><sup>[6](https://proceedings.mlsys.org/paper_files/paper/2024/file/42a452cbafa9dd64e9ba4aa95cc1ef21-Paper-Conference.pdf)</sup> |

## 量化为何对推理至关重要

LLM 推理的瓶颈主要在于从内存中加载权重。解码一个词元需要读取模型的每一个参数，因此每参数字节数为每秒推理词元数和给定加速器上能容纳多大模型设定了硬性下限<sup>[16](https://www2.eecs.berkeley.edu/Pubs/TechRpts/2024/EECS-2024-210.pdf)</sup>。[训练后量化](https://www.edgepedia.org/zh/post-training-quantization)（PTQ）通过压缩权重参数来应对这一问题，降低内存需求并缓解内存带宽瓶颈<sup>[7](https://aclanthology.org/2023.emnlp-main.910.pdf)</sup>。一个 7B 模型的 FP16 权重约占 14 GB；在 4 位下，同样的权重仅占约四分之一<sup>[1](https://frontiercheckpoint.com/explainers/post-training-quantization-gptq-awq-fp8/)</sup>。

**两大类别。** 量化感知训练（QAT）将权重精度降低直接融入预训练或微调过程，使模型在优化参数时意识到数值精度的降低。训练后量化则不同，它对预训练模型进行量化，无需额外训练或微调<sup>[8](https://www.ibm.com/think/topics/quantization-aware-training)</sup>。PTQ 成本低得多，是下文所述广泛部署的 4 位格式的基础；QAT 可以达到更低的位宽，但需要训练过程。在 LLaMA-3 8B 上对 1 位、1.58 位和 2 位方法的比较发现，即便最好的量化感知训练方法 EfficientQAT，平均准确率仍下降 9.1 个百分点<sup>[9](https://openreview.net/pdf/d60552949e4c9d184b694025d9111adfcb953fac.pdf)</sup>。

## 训练后量化方法

**GPTQ。** GPTQ 是一种基于近似二阶信息的一次性权重量化方法，专为生成式预训练变换器设计。它可将模型量化至每权重 3 或 4 位，相对于未压缩基线精度退化可忽略不计，压缩收益超过此前提出的一次性方法一倍以上，并且是首个在单块 GPU 内完成 1750 亿参数模型生成式推理的方法<sup>[2](https://arxiv.org/abs/2210.17323)</sup>。在 2 位或三值量化级别的极端情形下，它也能保持合理的精度<sup>[2](https://arxiv.org/abs/2210.17323)</sup>。该方法逐层工作，利用激活海森矩阵更新未量化的权重，以补偿量化误差<sup>[7](https://aclanthology.org/2023.emnlp-main.910.pdf)</sup>。

**AWQ。** 激活感知的权重量化（AWQ）的出发点是：LLM 中并非所有权重同等重要——仅保护 1% 的显著权重就能大幅降低量化误差。显著通道依据激活分布而非权重数值来识别，并通过等价变换在量化前将其放大加以保护，从而避免硬件效率低下的混合精度。缩放系数通过离线收集激活统计量来确定，AWQ 不使用反向传播或重建，因此能跨领域和模态泛化，而不会过拟合校准集<sup>[3](https://arxiv.org/abs/2306.00978)</sup>。该方法获得了 MLSys 2024 最佳论文奖<sup>[3](https://arxiv.org/abs/2306.00978)</sup>。

**如何在两者间选择。** 在 [Hugging Face Transformers](https://www.edgepedia.org/zh/hugging-face-transformers) 生态中，GPTQModel 和 AWQ 是基于校准的选项，可获得良好的 4 位精度；AWQ 在 4 位下往往能达到高精度，在特定任务上有时超过 GPTQ，且校准时间更短<sup>[4](https://huggingface.co/docs/transformers/quantization/selecting)</sup>。两者都需要校准数据集和单独的校准步骤，且都可能过拟合校准数据<sup>[4](https://huggingface.co/docs/transformers/quantization/selecting)</sup>。免校准的替代方案如 HQQ 和 SINQ 可即时量化，但在低位深下退化更严重<sup>[4](https://huggingface.co/docs/transformers/quantization/selecting)</sup>。

## 精度权衡

量化的代价取决于位宽、模型规模和任务。对五个模型（Llama-3.1 8B 和 70B、Qwen-2.5 7B、32B 和 72B）和五种量化方法的系统评估发现，8 位量化保持精度，平均仅下降约 0.8%，而 4 位方法导致大幅损失，尤其对涉及长上下文输入的任务，降幅高达 59%<sup>[5](https://arxiv.org/abs/2505.20276)</sup>。对 7B 至 405B 参数指令微调模型的更广泛评估发现，将更大的 LLM 量化到与较小 FP16 LLM 相近的规模，在大多数基准上通常表现更好；且仅权重量化方法在较大模型中往往效果更佳<sup>[10](https://arxiv.org/abs/2409.11055)</sup>。

**仅权重与权重加激活。** 大多数已部署的 4 位方法仅量化权重，激活保持 16 位格式（W4A16）。同时量化激活至 W4A8，可启用更低精度的乘累加单元，节省逻辑面积和功耗，但也带来新问题。AWQ 的激活感知缩放在此情形下使激活容易产生量化误差，而激活离群值随序列长度变化，因此校准必须考虑目标任务的序列长度<sup>[7](https://aclanthology.org/2023.emnlp-main.910.pdf)</sup>。激活量化感知缩放和序列长度感知校准等技术可应对这些效应，一种带非规格化表示（denormal）的混合 dINT 整数格式可缓解下溢——即小数值舍入为零的问题<sup>[7](https://aclanthology.org/2023.emnlp-main.910.pdf)</sup>。

## 服务与硬件

量化检查点只有在推理引擎能高效执行时才有用。Hugging Face Transformers 以及 vLLM 等服务栈可直接加载 AWQ 检查点，这使 AWQ 与 GPTQ 一道成为 [Hugging Face Hub](https://www.edgepedia.org/zh/hugging-face-hub) 上两种常见的 4 位格式之一<sup>[11](https://realpython.com/ref/ai-coding-glossary/awq/)</sup>。vLLM 中使用的 Marlin 内核通过将反量化融合进矩阵乘法本身，加速 GPTQ、AWQ、FP8 和 FP4 格式，支持从 Turing 到 Hopper 的 GPU 架构<sup>[12](https://www.spheron.network/blog/gptq-vs-awq-vs-gguf-4-bit-quantization-comparison-2026/)</sup>。

**边缘部署。** AWQ 作者构建了 TinyChat，这是一个面向 4 位端侧 LLM 与视觉语言模型的推理框架，采用内核融合和平台感知的权重打包；在桌面和移动 GPU 上的速度均为 Huggingface FP16 实现的 3 倍以上，并可在移动 GPU 上运行 70B 的 Llama-2 模型<sup>[3](https://arxiv.org/abs/2306.00978)</sup>。在规模谱系的另一端，量化结合权重卸载甚至让微控制器也能参与：一个 2890 万参数的模型量化至 4 位后仅占 14.9 MB，可在售价 10 美元的 ESP32-S3 上以每秒 9.88 个词元运行，嵌入表存储在 16 MB 闪存中<sup>[13](https://www.tomshardware.com/tech-industry/artificial-intelligence/ai-developer-runs-28-9-million-parameter-model-on-usd10-esp32-s3-microcontroller-uses-googles-per-layer-embeddings-technique-stores-table-on-16mb-flash-memory)</sup>。

**更新的格式。** 微缩放浮点格式（MXFP）是整数量化的一种替代方案。

## 实践选择

对于 NVIDIA GPU 上的生产服务，在 4 位格式之间做选择，不如关注推理引擎派发到哪个内核重要；在近期基准中，GPTQ 和 AWQ 在吞吐量和精度上相差仅几个百分点<sup>[12](https://www.spheron.network/blog/gptq-vs-awq-vs-gguf-4-bit-quantization-comparison-2026/)</sup><sup> • </sup><sup>[14](https://pythondatabench.com/article/llm-quantization-gptq-awq-bitsandbytes-gguf-2026)</sup>。当校准时间重要时，AWQ 更受青睐，因为它缩放显著通道，而非运行逐层海森矩阵舍入<sup>[15](https://github.com/sudsho/llm-quantization-toolkit)</sup>。由于结果因模型家族、代际和提示分布而异，标准建议是在确定格式前，先在目标工作负载上进行基准测试<sup>[14](https://pythondatabench.com/article/llm-quantization-gptq-awq-bitsandbytes-gguf-2026)</sup>。

## References

1. [Post-Training Quantization in Practice: GPTQ, AWQ, and FP8, Frontier Checkpoint](https://frontiercheckpoint.com/explainers/post-training-quantization-gptq-awq-fp8/)
2. [Frantar, Elias, Ashkboos, Saleh, Hoefler, Torsten, Alistarh, Dan (2022). GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers. arXiv.](https://arxiv.org/abs/2210.17323)
3. [Lin, Ji, et al. (2023). AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration. arXiv.](https://arxiv.org/abs/2306.00978)
4. [Selecting a quantization method, Hugging Face Transformers documentation](https://huggingface.co/docs/transformers/quantization/selecting)
5. [Does quantization affect models' performance on long-context tasks? arXiv.](https://arxiv.org/abs/2505.20276)
6. [AWQ: Activation-aware Weight Quantization for On-Device LLM Compression and Acceleration, MLSys 2024 proceedings](https://proceedings.mlsys.org/paper_files/paper/2024/file/42a452cbafa9dd64e9ba4aa95cc1ef21-Paper-Conference.pdf)
7. [Lee, Janghwan, et al. (2023). Enhancing Computation Efficiency in Large Language Models through Weight and Activation Quantization, EMNLP 2023](https://aclanthology.org/2023.emnlp-main.910.pdf)
8. [What is Quantization Aware Training? IBM](https://www.ibm.com/think/topics/quantization-aware-training)
9. [Comparison of 1-bit, 1.58-bit and 2-bit quantization methods on LLaMA-3 8B, OpenReview](https://openreview.net/pdf/d60552949e4c9d184b694025d9111adfcb953fac.pdf)
10. [A Comprehensive Evaluation of Quantized Instruction-Tuned Large Language Models: An Experimental Analysis up to 405B, arXiv](https://arxiv.org/abs/2409.11055)
11. [Activation-aware weight quantization (AWQ), Real Python AI Coding Glossary](https://realpython.com/ref/ai-coding-glossary/awq/)
12. [GPTQ vs AWQ vs GGUF: Speed, Accuracy & Cost Compared, Spheron Blog](https://www.spheron.network/blog/gptq-vs-awq-vs-gguf-4-bit-quantization-comparison-2026/)
13. [AI developer runs 28.9-million-parameter model on $10 ESP32-S3 microcontroller, Tom's Hardware](https://www.tomshardware.com/tech-industry/artificial-intelligence/ai-developer-runs-28-9-million-parameter-model-on-usd10-esp32-s3-microcontroller-uses-googles-per-layer-embeddings-technique-stores-table-on-16mb-flash-memory)
14. [LLM Quantization Python: GPTQ vs AWQ, Python Data Bench](https://pythondatabench.com/article/llm-quantization-gptq-awq-bitsandbytes-gguf-2026)
15. [llm-quantization-toolkit, GitHub](https://github.com/sudsho/llm-quantization-toolkit)
16. [www2.eecs.berkeley.edu](https://www2.eecs.berkeley.edu/Pubs/TechRpts/2024/EECS-2024-210.pdf)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Neural networks and deep learning › Deep learning software and hardware › Inference acceleration and optimization

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/quantization-aware-large-model-inference

English original: https://www.edgepedia.org/quantization-aware-large-model-inference
