K-文化的一切——从回归到 K-美妆,发送到您的邮箱订阅邮件

METAL MEDIA

Efficient INT8 Inference of Small NLP Models on Server CPUs with PyTorch Native Stack

arXiv:2608.181822026-08-20

英特尔团队仅用PyTorch原生功能,让BERT类模型在服务器CPU上最高提速5.8倍

即使在大语言模型备受关注的当下,BERT系列小型NLP模型仍广泛用于分类、排序、检索等工业场景。这项工作将SmoothQuant这一能把模型数值压缩成8位整数(INT8)且几乎不损失精度的技术,直接整合进PyTorch自身的编译栈,而不再依赖第三方工具。最终在英特尔至强服务器CPU上实现了最高5.8倍的处理速度提升,精度损失微乎其微。

METAL MEDIA 解读图

英特尔团队仅用PyTorch原生功能,让BERT类模型在服务器CPU上最高提速5.8倍

  1. 01将SmoothQuant(一种把数值计算难度从激活值转移到权重上、便于压缩为INT8的方法)整合进PyTorch原生量化库TorchAO,无需额外第三方工具即可直接使用
  2. 02在PyTorch编译器TorchInductor中加入图融合功能,把INT8矩阵乘法与后续的缩放、偏置相加等操作合并成一个高效算子,避免运行时转换数据排布带来的开销
  3. 03针对AVX512_VNNI和AMX(英特尔CPU中加速整数运算的专用指令集)编写底层核函数,让较旧的Ice Lake和较新的Granite Rapids芯片都能发挥最佳速度
  4. 04设计了s8s8转u8s8的转换方案,使不支持特定指令的Ice Lake CPU也能高效运行INT8量化
  5. 05在BERT-large、DistilBERT、XLM-RoBERTa上测试,相比32位浮点(FP32)基准,Ice Lake上吞吐量提升1.9至2.6倍,Granite Rapids上提升4.2至5.8倍,在SQuAD和MultiNLI任务上精度损失低于1%
这是 METAL MEDIA 制作的解读图,并非论文作者提供的原图。

他们做了什么

  1. 将SmoothQuant(一种把数值计算难度从激活值转移到权重上、便于压缩为INT8的方法)整合进PyTorch原生量化库TorchAO,无需额外第三方工具即可直接使用
  2. 在PyTorch编译器TorchInductor中加入图融合功能,把INT8矩阵乘法与后续的缩放、偏置相加等操作合并成一个高效算子,避免运行时转换数据排布带来的开销
  3. 针对AVX512_VNNI和AMX(英特尔CPU中加速整数运算的专用指令集)编写底层核函数,让较旧的Ice Lake和较新的Granite Rapids芯片都能发挥最佳速度
  4. 设计了s8s8转u8s8的转换方案,使不支持特定指令的Ice Lake CPU也能高效运行INT8量化
  5. 在BERT-large、DistilBERT、XLM-RoBERTa上测试,相比32位浮点(FP32)基准,Ice Lake上吞吐量提升1.9至2.6倍,Granite Rapids上提升4.2至5.8倍,在SQuAD和MultiNLI任务上精度损失低于1%
Figure 1: SmoothQuant workflow built on TorchAO and TorchInductor. TorchAO prepares and quantizes the model, TorchInductor fuses INT8 subgraphs, and the CPP backend selects between oneDNN and template-based GEMM kernels. C++ code is generated and compiled for deployment.
Figure 1: SmoothQuant workflow built on TorchAO and TorchInductor. TorchAO prepares and quantizes the model, TorchInductor fuses INT8 subgraphs, and the CPP backend selects between oneDNN and template-based GEMM kernels. C++ code is generated and compiled for deployment.
Table 1: Hardware platforms used for baseline collection.
Xeon GenerationCodenameModelPhysical CoresInstruction Support
3rd GenIce Lake835864AVX512F, AVX512_VNNI
6th GenGranite Rapids6980P256AVX512F, AVX512_VNNI, AMX
Table 2: Baseline collection setup.
ItemValue
ModelBERT-large
Input shapeBatch size 1, sequence length 256
Precision modesFP32 on both platforms; BF16 on Granite Rapids
Launch strategyMulti-instance with weight-sharing on each socket
Cores per instance4
Number of instancesNumber of physical cores / 4
Deployment pathAOTI enabled
Input dataSynthetic
Table 3: Baseline hotspot breakdown for the BERT-large analysis case under the same multi-instance setup used for throughput benchmarking. Operator shares are aggregated from representative profiler logs. The linear-block consists of GEMM and fused post-operations such as bias addition, activation, and residual addition.
BaselineLinear-BlockAttentionLayerNormOther
FP32 on Ice Lake88.5%10.4%0.6%0.5%
FP32 on Granite Rapids86.9%11.8%0.8%0.5%
BF16 on Granite Rapids72.70%19.75%5.99%1.56%
Table 4: Estimated peak compute and measured memory bandwidth per socket, balance point for different data types on the evaluated platforms.
PlatformFP32 Throughput (TFLOPS)BF16 Throughput (TFLOPS)INT8 Throughput (TOPS)Memory Bandwidth (GB/s)FP32 Balance Point (FLOPs/byte)BF16 Balance Point (FLOPs/byte)INT8 Balance Point (OPs/byte)
Ice Lake6.76N/A27.03175.0038.63N/A154.46
Granite Rapids19.66262.14524.29700.0028.09374.49748.99
Table 5: BERT-large GEMM shapes and their arithmetic intensity.
Arithmetic Intensity (ops/byte)
GEMM Shape M × K × NOccurrences per forward passFP32BF16INT8
256×1024×10249685.33146.29227.56
256×1024×40962497.52163.84248.24
256×4096×10242497.52186.18341.33
Table 6: Effective memory bandwidth and balance point for INT8 GEMM on Granite Rapids.
GEMM ShapeEffective Memory Bandwidth (GB/s)Arithmetic Intensity (OPs/byte)Balance Point (OPs/byte)
256×1024×1024807.69227.56649.12
256×1024×4096819.15248.24640.04
256×4096×1024875.00341.33599.19
Table 7: Estimated GEMM throughput and speedup on Granite Rapids.
GEMM ShapeFP32 Throughput (TFLOPS)BF16 Throughput (TFLOPS)INT8 Throughput (TOPS)INT8 vs FP32 SpeedupINT8 vs BF16 Speedup
256×1024×102419.66102.40183.799.35×1.79×
256×1024×409619.66114.69203.3510.34×1.77×
256×4096×102419.66130.33298.6715.19×2.29×
Weighted Average19.66114.69218.8711.13×1.91×
Table 8: Models used for the performance benchmark.
ModelModel ID
BERT-largebert-large-uncased
DistilBERTdistilbert-base-uncased
XLM-RoBERTaxlm-roberta-base
Table 9: Task-finetuned checkpoints used for accuracy evaluation. The model marked by * is finetuned on SQuAD 2.0 but still workable for the test on SQuAD 1.1.
DatasetModelModel ID
SQuAD 1.1BERT-largegoogle-bert/bert-large-uncased-whole-word-masking-finetuned-squad
SQuAD 1.1DistilBERTdistilbert/distilbert-base-cased-distilled-squad
SQuAD 1.1XLM-RoBERTadeepset/xlm-roberta-base-squad2*
MultiNLIBERT-largeyoshitomo-matsubara/bert-large-uncased-mnli
MultiNLIDistilBERTtypeform/distilbert-base-uncased-mnli
MultiNLIXLM-RoBERTasymanto/xlm-roberta-base-snli-mnli-anli-xnli
Table 10: Quantization methods used in the experiments.
MethodShort Name
No quantization, no AMPFP32
No quantization, with AMPBF16
SmoothQuant, static quantizationSmooth-Static
SmoothQuant, dynamic quantizationSmooth-Dynamic
Table 11: INT8 speedup over FP32 on Ice Lake.
ModelMethodThroughput SpeedupLinear-Block Speedup
BERT-largeSmooth-Dynamic2.22×3.59×
BERT-largeSmooth-Static2.58×3.87×
DistilBERTSmooth-Dynamic1.90×3.31×
DistilBERTSmooth-Static2.30×3.35×
XLM-RoBERTaSmooth-Dynamic1.86×3.05×
XLM-RoBERTaSmooth-Static2.17×3.71×
Table 12: INT8 speedup over FP32 on Granite Rapids.
ModelMethodThroughput SpeedupLinear-Block Speedup
BERT-largeSmooth-Dynamic5.02×9.92×
BERT-largeSmooth-Static5.82×8.67×
DistilBERTSmooth-Dynamic4.24×7.60×
DistilBERTSmooth-Static5.37×8.84×
XLM-RoBERTaSmooth-Dynamic4.17×7.58×
XLM-RoBERTaSmooth-Static5.41×8.71×
Table 13: INT8 speedup over BF16 on Granite Rapids.
ModelMethodThroughput SpeedupLinear-Block Speedup
BERT-largeSmooth-Dynamic1.37×1.84×
BERT-largeSmooth-Static1.59×1.61×
DistilBERTSmooth-Dynamic0.98×1.45×
DistilBERTSmooth-Static1.24×1.69×
XLM-RoBERTaSmooth-Dynamic0.99×1.50×
XLM-RoBERTaSmooth-Static1.29×1.67×
Table 14: Realized speedup of BERT-large over estimated speedup ceiling on both evaluated platforms.
Throughput SpeedupLinear-Block Speedup
PlatformMethodBaselineRealizedEstimatedGapRealizedEstimatedGap
Ice LakeSmooth-DynamicFP322.22×3.15×29.59%3.59×4.00×10.22%
Ice LakeSmooth-StaticFP322.58×3.15×18.17%3.87×4.00×3.21%
Granite RapidsSmooth-DynamicFP325.02×7.06×28.89%9.92×11.13×10.89%
Granite RapidsSmooth-StaticFP325.82×7.06×17.56%8.67×11.13×22.12%
Granite RapidsSmooth-DynamicBF161.37×1.53×10.41%1.84×1.91×3.58%
Granite RapidsSmooth-StaticBF161.59×1.53×-3.98%1.61×1.91×15.64%
Table 15: Accuracy results on Granite Rapids.
ModelMetricFP32BF16Smooth-StaticAlphaLossSmooth-DynamicAlphaLoss
BERT-largeSQuAD F192.6492.6792.660.60.0%92.630.60.0%
BERT-largeSQuAD EM86.4186.4586.490.6-0.1%86.440.60.0%
BERT-largeMultiNLI Accuracy64.5564.5864.730.7-0.3%64.520.60.0%
DistilBERTSQuAD F186.3986.4186.000.70.5%86.400.60.0%
DistilBERTSQuAD EM79.0279.0478.490.70.7%79.040.60.0%
DistilBERTMultiNLI Accuracy82.2182.1682.260.8-0.1%82.170.60.0%
XLM-RoBERTaSQuAD F176.4376.3476.470.55-0.1%76.590.6-0.2%
XLM-RoBERTaSQuAD EM69.9569.8970.040.55-0.1%70.300.6-0.5%
XLM-RoBERTaMultiNLI Accuracy82.2682.2382.310.7-0.1%82.260.60.0%

为什么重要

许多企业在搜索排序、文本分类等日常任务中仍依赖运行在普通CPU上的小型NLP模型。将这类加速能力直接内置于标准PyTorch中,无需额外插件,任何团队都能在几乎不改代码的情况下获得数倍提速、成本更低的推理能力。

本文术语

  • INT8量化 · 用8位整数而非32位浮点数存储和计算数值,速度更快、占用内存更少,但可能降低精度
  • SmoothQuant · 通过在激活值与权重之间重新分配数值幅度,降低INT8量化带来的精度损失的技术
  • TorchAO · PyTorch官方提供的用于对模型进行量化等低精度处理的库
  • TorchInductor · PyTorch 2中负责优化并生成高效代码的编译器后端
  • GEMM · 神经网络各层内部反复执行的核心运算——通用矩阵乘法
  • AVX512_VNNI / AMX · 英特尔至强CPU内置的、用于加速INT8整数运算的专用指令集
  • 屋顶线模型 · 一种用于判断计算任务是受处理器速度限制还是受内存带宽限制的性能分析方法

论文原文摘要(英文)

Small NLP models, especially BERT-family encoders, remain important in industrial workloads such as classification, ranking, and retrieval even in the era of large language models. On server CPUs, INT8 quantization offers an attractive latency-throughput-cost trade-off, but users increasingly expect such acceleration to be available directly in the native PyTorch stack. We integrate SmoothQuant into TorchAO and optimize the resulting inference path for Intel Xeon CPUs through graph-level fusion in TorchInductor and efficient INT8 GEMM kernel selection across oneDNN-, AVX512_VNNI-, and AMX-based implementations. Across BERT, DistilBERT, and XLM-RoBERTa benchmarks, the approach delivers up to 5.8x end-to-end throughput speedup with negligible---and in some cases no measurable---accuracy loss relative to the FP32 baseline. We also validated our work by detailed performance analysis with roofline models. The implementation has been upstreamed to PyTorch and TorchAO, enabling out-of-the-box deployment with native PyTorch tooling

作者 · Weiwen Xia, Yuxin Cui, E Cao

在 arXiv 阅读

最新论文

全部论文 →

METAL MEDIA 最新报道

图片来源: Weiwen Xia et al., arXiv:2608.18182, CC BY 4.0