# LLM.int8()

LLM.int8() 是一种面向大型 Transformer 语言模型的 8 位推理方法，由蒂姆·德特默斯、迈克·刘易斯、尤尼斯·贝尔卡达和卢克·泽特尔莫耶于 2022 年 8 月提出。该方法将大多数矩阵乘法量化为 8 位整数，同时将少量大幅值的“离群”特征维度保留为 16 位浮点数。<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup> 作者称这是首个面向 Transformer 的、达到数十亿参数规模的 Int8 量化流程，在其基准测试中不产生性能退化，使得一个 1750 亿参数模型的前馈层和注意力投影层可以转换为 8 位并立即用于推理。<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup> 该工作发表于 NeurIPS 2022，并在 bitsandbytes 库和 [Hugging Face](https://www.edgepedia.org/zh/hugging-face) transformers 中发布。<sup>[2](https://papers.nips.cc/paper_files/paper/2022/file/c3ba4962c05c49636d4c6206a97e9c8a-Paper-Conference.pdf)</sup>

| 关键事实 | 内容 |
|---|---|
| 提出时间 | 2022 年 8 月（arXiv 2208.07339）；NeurIPS 2022<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup><sup> • </sup><sup>[2](https://papers.nips.cc/paper_files/paper/2022/file/c3ba4962c05c49636d4c6206a97e9c8a-Paper-Conference.pdf)</sup> |
| 核心思想 | >99.9% 的数值以 int8 相乘；离群维度（约 0.1%，幅值超过 α = 6.0）保留为 fp16<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup> |
| 内存节省 | BLOOM-176B 的内存占用降至原来的约 1/1.96（减少约 50%）；OPT-175B 从 340 GB 降至约 180 GB<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup><sup> • </sup><sup>[3](https://ashwanijha.dev/blog/llm-int8-what-the-paper-actually-says)</sup> |
| 硬件 | 需具备 INT8 张量核心的 GPU，CUDA 计算能力 sm_75+（Turing/Ampere）；不支持 CPU<sup>[4](https://github.com/huggingface/blog/blob/main/hf-bitsandbytes-integration.md)</sup><sup> • </sup><sup>[3](https://ashwanijha.dev/blog/llm-int8-what-the-paper-actually-says)</sup> |
| 速度（厂商报告） | BLOOM-176B 在批大小为 1 时比 fp16 慢约 15–23%，使用 4×A100 而非 8×A100<sup>[4](https://github.com/huggingface/blog/blob/main/hf-bitsandbytes-integration.md)</sup> |
| 速度/能耗（独立测量） | 在 6–7B 模型上，吞吐量损失 72.7–75.3%，能耗比 fp16 高 17–147%，原因在于 int8↔fp16 类型转换<sup>[5](https://github.com/bitsandbytes-foundation/bitsandbytes/issues/1867)</sup> |
| 现状（2026） | 仍在 transformers 和 bitsandbytes 中有文档记载，但在推理服务方面已被 Hopper GPU 上的原生 FP8 取代，在微调方面已被 4 位 QLoRA 取代<sup>[6](https://huggingface.co/docs/transformers/en/quantization/bitsandbytes)</sup><sup> • </sup><sup>[3](https://ashwanijha.dev/blog/llm-int8-what-the-paper-actually-says)</sup> |

## LLM.int8() 是什么

朴素的 8 位量化将 Transformer 矩阵乘法中的每个数值都以 int8 相乘。这种方法在大规模下会失败，原因在于涌现出的离群特征：从大约 67 亿参数开始，所有 Transformer 层中都会出现大幅值特征，破坏量化精度，导致 C4 困惑度升高、零样本准确率下降。<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup> LLM.int8() 通过混合精度分解来处理这一问题：约 0.1% 的特征维度——即包含超过阈值的离群值的维度——被分离出来以 16 位矩阵乘法计算，而超过 99.9% 的数值以 8 位相乘。<sup>[2](https://papers.nips.cc/paper_files/paper/2022/file/c3ba4962c05c49636d4c6206a97e9c8a-Paper-Conference.pdf)</sup> bitsandbytes 文档描述了同样的设计：离群值从输入和权重中提取出来以 16 位相乘，其余所有数值以 8 位相乘并反量化，然后将两部分输出合并。<sup>[7](https://huggingface.co/docs/bitsandbytes/reference/nn/linear8bit)</sup>

阈值为 α = 6.0，作者发现该值足以将性能退化降至接近零。<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup> 由于离群值是稀疏且系统性的——出现在各个序列位置上但局限于特定的隐藏维度——保留它们的代价很小：对于不超过 130 亿参数的 Transformer，离群特征维度的数量最多为 7，因此分解仅增加约 0.1% 的内存。<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup>

## 逐步工作原理

Hugging Face 的集成文档将分裂矩阵乘法描述为三个步骤。首先，从输入隐藏状态中按列提取离群值（大于阈值的数值）。其次，将离群值以 FP16 进行矩阵乘法，非离群值以 int8 进行矩阵乘法。第三，将非离群值结果反量化，并将两部分相加，得到 FP16 的完整结果。<sup>[4](https://github.com/huggingface/blog/blob/main/hf-bitsandbytes-integration.md)</sup>

在 bitsandbytes 的实现中，每个 `nn.Linear` 层被替换为 `Linear8bitLt` 模块，在每次前向传播时执行该分解。权重矩阵以 INT8 存储；离群值检测和 FP16 路径在运行时进行，阈值通过 `llm_int8_threshold` 暴露。<sup>[3](https://ashwanijha.dev/blog/llm-int8-what-the-paper-actually-says)</sup>

## 起源与采用

该方法以“LLM.int8()：面向大规模 Transformer 的 8 位矩阵乘法”为题发表（arXiv，2022 年 8 月），作者为德特默斯、刘易斯、贝尔卡达和泽特尔莫耶，并在 NeurIPS 2022 上经过同行评审。<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup><sup> • </sup><sup>[2](https://papers.nips.cc/paper_files/paper/2022/file/c3ba4962c05c49636d4c6206a97e9c8a-Paper-Conference.pdf)</sup> 在完成 BLOOM-176B 的训练后，Hugging Face 和 [BigScience](https://www.edgepedia.org/zh/bigscience) 寻找在更少 GPU 上运行该模型的方法，于 2022 年将 LLM.int8() 集成到 transformers 和 Accelerate 库中，称其为首个即使对 1760 亿参数模型也不降低性能的技术。<sup>[4](https://github.com/huggingface/blog/blob/main/hf-bitsandbytes-integration.md)</sup> 论文报告称，LLM.int8() 使得当时最大的开源模型 [OPT-175B](https://www.edgepedia.org/zh/opt-175b) 和 BLOOM-176B 可以在配备消费级 GPU 的单节点上运行。<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup> 通过 transformers 中的 `load_in_8bit` 路径，这一机制后来成为在本地硬件上运行大模型的标准方式。<sup>[6](https://huggingface.co/docs/transformers/en/quantization/bitsandbytes)</sup>

## 数据一览

**内存。** 对于 BLOOM-176B，该方法将模型的内存占用降至原来的约 1/1.96，相比 16 位约减少 50%。<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup> 对于 OPT-175B，FP16 权重占用 340 GB，而 INT8 约占 180 GB，因此原本需要超过两台 8×A100 服务器的模型可以放在一台服务器上。<sup>[3](https://ashwanijha.dev/blog/llm-int8-what-the-paper-actually-says)</sup>

**速度，厂商报告。** Hugging Face 的集成基准测试发现，BLOOM-176B 使用 LLM.int8() 在批大小为 1 时比 fp16 慢约 15% 到 23%，运行在 4×A100 80 GB 上（282 毫秒/词元），而 bf16 使用 8×A100（239 毫秒/词元），GPU 数量减半。<sup>[4](https://github.com/huggingface/blog/blob/main/hf-bitsandbytes-integration.md)</sup> 较小的模型最初出现更大的减速；一天内的优化将 T5-3B 从每词元 312 毫秒改善到 173 毫秒，T5-11B 从 45 毫秒改善到 25 毫秒。<sup>[4](https://github.com/huggingface/blog/blob/main/hf-bitsandbytes-integration.md)</sup>

**速度和能耗，独立测量。** 一项基于 NVML 的功耗监测研究（10 Hz 采样，RTX 4090D 和 A800 GPU，四个模型包括 Yi-1.5-6B 和 Mistral-7B）发现，默认配置（`llm_int8_threshold=6.0`）相比 FP16 基线增加 17–147% 的能耗，吞吐量降低 72.7–75.3%（例如，批大小为 1 时 9.87 对 36.18 词元/秒，能耗增加 122%；在 A800 上批大小为 4 时，吞吐量降低 75.3%，能耗增加 147%）。<sup>[5](https://github.com/bitsandbytes-foundation/bitsandbytes/issues/1867)</sup> 将 `llm_int8_threshold` 设为 `0.0` 后可消除能耗开销并恢复约 80% 的吞吐量，表明代价来自分解路径中的 INT8↔FP16 类型转换，而非 INT8 算术本身。<sup>[5](https://github.com/bitsandbytes-foundation/bitsandbytes/issues/1867)</sup>

厂商和独立数据之间存在明显分歧，来源并未解决这一差异：厂商数据针对 1760 亿参数模型在批大小为 1 时的情况，而独立测量覆盖 6–7B 模型——论文本身已报告这些模型会出现减速。<sup>[4](https://github.com/huggingface/blog/blob/main/hf-bitsandbytes-integration.md)</sup><sup> • </sup><sup>[5](https://github.com/bitsandbytes-foundation/bitsandbytes/issues/1867)</sup> 论文自己的基准测试发现，cuBLASLt 中的原始 Int8 矩阵乘法只有在隐藏层大小为 20560 时速度才达到 cuBLAS 的两倍，加上量化开销后降至 1.6 倍，而隐藏层大小为 2560 或更小的模型会变慢；加上混合精度分解会进一步减慢推理，因此在论文的基准测试中只有 130 亿和 1750 亿参数的模型保持了加速。<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup>

## 限制、失效模式与硬件要求

该方法需要具备 INT8 张量核心的 GPU：bitsandbytes 在 Turing 和 Ampere 硬件上运行（RTX 20 系列、RTX 30 系列、A40–A100、T4+），CPU 不支持 8 位张量核心。<sup>[4](https://github.com/huggingface/blog/blob/main/hf-bitsandbytes-integration.md)</sup> 用 CUDA 术语来说，这是计算能力 sm_75 或更高；较旧的 GPU 如 P100 和 V100 缺少硬件 INT8 矩阵乘法单元。<sup>[3](https://ashwanijha.dev/blog/llm-int8-what-the-paper-actually-says)</sup>

已知的失效模式源于其机制。小模型和小隐藏维度会受到影响，因为固定的转换开销超过了 int8 的加速效果。<sup>[1](https://export.arxiv.org/pdf/2208.07339v2.pdf)</sup> 默认的离群阈值 6.0 并非在所有模型家族中普遍正确；有些模型的离群值幅值高于或低于该值，而且量化在加载时按模型固定，而非按请求固定。<sup>[3](https://ashwanijha.dev/blog/llm-int8-what-the-paper-actually-says)</sup> 独立能耗研究发现开销随批大小增长（A800 上批大小为 1 时能耗增加 122%，批大小为 4 时增至 147%），并在消费级和数据中心 GPU 上均可复现。<sup>[5](https://github.com/bitsandbytes-foundation/bitsandbytes/issues/1867)</sup>

## 近期发展：被 FP8 和 4 位方法取代

两项发展削弱了 LLM.int8() 的作用。在 H100 级（Hopper）硬件上，建议从业者通过 PyTorch AMP 或 [TensorRT-LLM](https://www.edgepedia.org/zh/tensorrt-llm) 使用原生 FP8 而非 LLM.int8()，因为 FP8 提供相似的内存节省，精度更好，且没有软件分解开销。<sup>[3](https://ashwanijha.dev/blog/llm-int8-what-the-paper-actually-says)</sup> 在软件方面，Hugging Face 的 bitsandbytes 文档现在将 [QLoRA](https://www.edgepedia.org/zh/qlora)——一种 4 位技术，通过插入可训练的 LoRA 权重在进一步压缩模型的同时保持可训练性——作为与 8 位加载并列的头条功能。<sup>[6](https://huggingface.co/docs/transformers/en/quantization/bitsandbytes)</sup>

## References

1. [LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale (arXiv 2208.07339, Dettmers et al.)](https://export.arxiv.org/pdf/2208.07339v2.pdf)
2. [LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale — NeurIPS 2022 proceedings](https://papers.nips.cc/paper_files/paper/2022/file/c3ba4962c05c49636d4c6206a97e9c8a-Paper-Conference.pdf)
3. [LLM.int8(): What the 8-bit Matrix Multiplication Paper Actually Says — Ashwani Jha](https://ashwanijha.dev/blog/llm-int8-what-the-paper-actually-says)
4. [A Gentle Introduction to 8-bit Matrix Multiplication — Hugging Face blog](https://github.com/huggingface/blog/blob/main/hf-bitsandbytes-integration.md)
5. [Default LLM.int8() mixed-precision decomposition causes 17-147% energy overhead (bitsandbytes issue #1867)](https://github.com/bitsandbytes-foundation/bitsandbytes/issues/1867)
6. [Bitsandbytes — Hugging Face Transformers documentation](https://huggingface.co/docs/transformers/en/quantization/bitsandbytes)
7. [LLM.int8() · Hugging Face bitsandbytes API reference](https://huggingface.co/docs/bitsandbytes/reference/nn/linear8bit)

---
*Initially written Sep 17, 2026 · Edited: Oct 11, 2026; Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 现代人工智能：基础模型、生成式人工智能与人工智能产业 › 基础模型方法与训练 › 基础模型的推理、服务与效率

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/llm-int8

English original: https://www.edgepedia.org/llm-int8
