wikillm

Paper · 2018-05-16 · cs.CV, cs.AI

PACT: Parameterized Clipping Activation for Quantized Neural Networks

PACT replaces ReLU with a clipped activation whose clip level alpha is a learned, per-layer parameter trained by backpropagation with an L2 penalty. Activations are then uniformly quantized to k bits with a straight-through estimator. Author-reported: 4-bit weights and activations stay within about 1 point of full precision top-1 on CIFAR10, SVHN, AlexNet, ResNet18 and ResNet50.

Quantization-aware trainingLow-precision arithmeticHardware-aware trainingquantizationactivation-quantizationlow-precisioninference-efficiency

arXivPDFMarkdown11 min read

AI-compiled by claude-haiku-5-5 on 2026-10-19, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

Neural networks run on numbers stored with many bits. Storing and multiplying those numbers with fewer bits makes a model smaller and faster, but the model usually gets worse. Most earlier work shrank the weights (the learned parameters). The activations (the values passed from layer to layer while the network runs) were harder to shrink, because a common activation function, ReLU, lets them grow without a limit, and a few-bit scale then fits them poorly.

PACT's idea is to cap each layer's activations at a threshold that the network learns during training. The threshold starts large, and training pulls it down to the range where the activations matter, so the few available levels are spent where they count. The rest of training then adjusts the network to the rounding. The authors report that this works with 4-bit weights and activations at roughly full-precision accuracy, and that the smaller number formats let a hardware accelerator pack in more compute units.

TL;DR

  • PACT swaps ReLU for a clipped activation with one learned clip level alpha per layer. §4 eq. 1
  • Clipped activations are rounded to k bits in the forward pass; gradients reach alpha through a straight-through estimator. §4 eq. 2 eq. 3
  • Author-reported: with 4-bit weights (DoReFa) and 4-bit activations (PACT), top-1 accuracy is within about 1 point of full precision on the five networks tested. tab. 1
  • The hardware analysis is a model estimate (14 nm MAC area, a performance simulator), not a measured chip. §6 fig. 6

Problem

Quantizing activations is harder than quantizing weights. ReLU outputs are unbounded, so quantizing them needs a high dynamic range, and accuracy is significantly degraded §3 fig. 1. Clipping activations with an upper bound helps, but the authors say it is hard to find one globally optimal clip value across layers and models §3. The Gaussian-based scale of HWGQ is set offline and stays fixed during training §3. The authors state that such schemes do not fully use back-propagation to learn the clip level §3.

Method

PACT is an activation function with one trainable parameter alpha. The forward pass is a truncation followed by a uniform k-bit quantizer. The backward pass uses a straight-through estimator (STE) for the rounding. §4

Activation (forward pass). The ReLU in each activation position is replaced by the function in eq. 1. It is 0 below zero, the identity on [0, alpha), and the constant alpha above alpha. §4 eq. 1

Quantization (forward pass). The truncated output y is mapped onto 2^k levels spaced alpha / (2^k - 1) apart, using the formula in eq. 2. The authors say the result is linearly quantized to k bits for the dot products. §4 eq. 2

Gradient for alpha (backward pass). The STE sets the derivative of the rounding to 1. The derivative of the output with respect to alpha is then 1 where the input is at or above alpha, and 0 elsewhere eq. 3. The paper therefore learns alpha by gradient descent through the loss. §4 eq. 3

Regularization of alpha. The loss includes an L2 penalty on alpha so that alpha shrinks during training and limits the dynamic range. The penalty uses the same coefficient as the weight decay §4.2 app. A.2, and the paper calls it lambda_alpha §4.1. The exact form of the penalty term in the loss is not written out in the paper. §4 app. A.2

Effect of alpha during training. In the ResNet20/CIFAR10 run of fig. 2 (lambda_alpha = 0.01), alpha falls from its initial value and settles at values much smaller than that start, which limits the dynamic range of the activations. §4 fig. 2

Sharing scope. The best scope for alpha was one value per layer. Sharing per layer also lets alpha be applied once after all multiply-accumulate operations of the layer §4.2 app. A.1 fig. 7.

Initialization. Starting alpha at a large value and then regularizing it down worked better than starting it small §4.2 app. A.2. The ResNet20 run uses an initial value of 10 §4 fig. 2.

Layers kept at full precision. The paper follows common practice and does not quantize the first and last layers in its main comparisons §4.2. Table 2 and Figure 9 show how quantizing those layers changes accuracy tab. 2 fig. 9.

Pseudocode. The two functions below restate eq. 1 to eq. 3. The paper gives no algorithm box.

Pseudocode
# PACT forward pass  [eq. 1] [eq. 2]
# Input:  x (activation tensor), alpha (scalar clip level, one per layer),
#         k (activation bit-width)
# Output: y_q (quantized activations, same shape as x)

def pact_forward(x, alpha, k):
    # Truncate to [0, alpha]  [eq. 1]
    truncated = 0.5 * (abs(x) - abs(x - alpha) + alpha)
    # Uniform k-bit grid with 2^k levels spaced alpha / (2^k - 1)  [eq. 2]
    step = alpha / (2 ** k - 1)
    quantized = round(truncated / step) * step
    return quantized
Pseudocode
# Gradient of the output with respect to alpha, with STE  [eq. 3]
# Input:  x (pre-activation tensor), alpha, upstream (dL/dy_q, same shape as x)
# Output: grad_alpha (scalar)

def pact_grad_alpha(x, alpha, upstream):
    # 1 where x >= alpha, 0 where x < alpha  [eq. 3]
    inside_clip = (x >= alpha)
    # Sum over every element that shares this alpha (one alpha per layer)
    # [§4.2] [app. A.1]
    grad_alpha = sum(upstream * inside_clip)
    return grad_alpha

Hyperparameters

Values are as stated in the paper. Where the paper is silent, the cell says so. The full comparison tables are in the paper's appendix app. C.2.

NameValueWhereNotes
Activation replacementPACT replaces the ReLU that follows each convolution's BatchNorm; FC output uses Softmaxapp. BBaselines use ReLU
Activation bit-widths studied2, 3, 4, 5 bitstab. 1 tab. 3–tab. 8
Weight bit-widthsDoReFa at the same bits as activations in tab. 1tab. 1 §5.2Weight precision in the activation-only runs (fig. 4, fig. 7–fig. 9) not stated
Scope of alphaOne per layer§4.2 app. A.1 fig. 7Per channel and per neuron scopes were tried
Initial alpha10 (ResNet20/CIFAR10 run)§4 fig. 2Other networks: not stated
lambda_alpha (L2 on alpha)0.01 in fig. 2fig. 2 fig. 8Sweep 1e-5 to 1e-1 in fig. 8; "same as weight lambda works well" app. A.2
First and last layersNot quantized in the main comparison§4.2Table 1 setup for PACT not stated; tab. 2 tests 8-bit
FrameworkTensorFlow with Tensorpack§5
CIFAR10 modelResNet20: conv, 3 ResNet blocks (16 conv, 3x3), FCapp. BTrained from scratch
CIFAR10 optimizerSGD, momentum 0.9app. B
CIFAR10 learning rate0.1, scaled by 0.1 at epochs 60 and 120app. B
CIFAR10 weight decay0.0002 on weightsapp. B
CIFAR10 batch size / epochs128 / 200app. B
SVHN model7 conv layers, then 1 FCapp. BInputs resized to 40 x 40
SVHN optimizerADAM, epsilon 1e-5app. B
SVHN learning rate1e-3, scaled by 0.5 every 50 epochsapp. B
SVHN weight decay1e-7 on weightsapp. B
SVHN batch size / epochs128 / 200app. B
ImageNet preprocessingResize to 256 x 256, random crop 224 x 224app. B
AlexNet5 parallel conv layers, then 3 FC; LRN replaced by BatchNormapp. B
AlexNet optimizerADAM, epsilon 1e-5; learning rate 1e-4 scaled by 0.2 at epochs 56 and 64app. B
AlexNet weight decay / batch / epochs5e-6 / 128 / 100app. B
ResNet18Conv, 8 ResNet blocks (16 conv 3x3), FC; pre-activation ResNetapp. B
ResNet50Conv, 16 bottleneck blocks (48 conv), FC; pre-activation ResNetapp. B
ResNet18/50 optimizerSGD, momentum 0.9; learning rate 0.1 scaled by 0.1 at epochs 30, 60, 85, 95app. B
ResNet18/50 weight decay / batch / epochs1e-4 / 256 / 110app. B
Hardware model: MAC array8 rows x 64 columns, 2 GHzfig. 6
Hardware model: cores and on-chip memory4 cores (16A-16W), 8 (8A-8W), 16 (4A-4W), 32 (2A-2W); 16 MB on-chipfig. 6Iso-area across bit-widths
Hardware model: external bandwidthUnconstrained, 32 GB/s, 64 GB/s§6 fig. 6

Results

Author-reported. Setup: CIFAR10, SVHN, ImageNet (AlexNet, ResNet18, ResNet50), trained from scratch in TensorFlow §5 app. B. Baselines are DoReFa-Net for the same bit-widths §5.2 tab. 1 and the prior schemes of app. C.1 for ImageNet. "PACT" below means DoReFa weights with PACT activations, unless noted tab. 1 tab. 1 caption.

Top-1 accuracy on CIFAR10, SVHN, AlexNet, ResNet18, ResNet50 tab. 1

NetworkFull precisionDoReFa 2bDoReFa 3bDoReFa 4bDoReFa 5bPACT 2bPACT 3bPACT 4bPACT 5b
CIFAR100.9160.8820.8990.9050.9040.8970.9110.9130.917
SVHN0.9780.9760.9760.9750.9750.9770.9780.9780.979
AlexNet0.5510.5360.5500.5490.5490.5500.5560.5570.557
ResNet180.7020.6260.6750.6810.6840.6440.6810.6920.698
ResNet500.7690.6710.6990.7140.7140.7220.7530.7650.767

Validation error (%) for CIFAR10-ResNet20 with first and last layers at different bit-widths tab. 2. Column groups are the bit-width of the other layers (BIT-M). Within each group the columns are the bit-width of the first and last layers (BIT-FL = 2, 4, 8, 32). FL/M/FL quantizes first, middle and last layers. FL/M/NQ leaves the last layer unquantized. NQ/M/FL leaves the first layer unquantized. NQ means no quantization.

ConfigBIT-M 2: 2 / 4 / 8 / 32BIT-M 3: 2 / 4 / 8 / 32BIT-M 4: 2 / 4 / 8 / 32BIT-M 5: 2 / 4 / 8 / 32
FL/M/FL21.0 / 12.9 / 11.1 / 10.917.4 / 10.0 / 9.4 / 8.915.9 / 9.7 / 9.2 / 8.918.2 / 9.0 / 8.4 / 8.5
FL/M/NQ21.3 / 11.5 / 11.5 / 10.717.6 / 9.7 / 9.2 / 9.016.5 / 9.7 / 8.7 / 8.716.3 / 9.3 / 8.6 / 8.5
NQ/M/FL12.1 / 11.2 / 11.0 / 11.59.8 / 8.9 / 9.2 / 9.28.4 / 8.4 / 8.7 / 8.88.5 / 9.0 / 8.5 / 8.5

ImageNet, PACT rows only (full comparisons with DoReFa, BalancedQ, WRPN, FGQ, WEP, LPBN and HWGQ are in the cited tables app. C.2). The first row of each block is the bit configuration as BitW / BitA. The full-precision baseline is given per table.

AlexNet top-1, full precision 55.1 tab. 3:

BitW32323232322223334445
BitA3223452342342345
PACT55.154.955.655.555.255.055.455.754.655.655.754.655.755.755.7

AlexNet top-5, full precision 77.0 tab. 4:

BitW32323232322223334445
BitA3223452342342345
PACT77.077.277.877.677.277.777.978.077.178.078.077.178.078.077.8

ResNet18 top-1, full precision 70.4 tab. 5:

BitW323232323211112345
BitA322345322342345
PACT70.467.569.270.070.065.862.965.365.064.468.169.269.8

ResNet18 top-5, full precision 89.6 tab. 6:

BitW323232323211112345
BitA322345322342345
PACT89.687.688.989.389.386.784.785.985.985.688.289.089.3

ResNet50 top-1, full precision 76.9 tab. 7:

BitW32323232122345
BitA32345224345
PACT76.975.575.976.067.872.274.575.376.576.7

ResNet50 top-5, full precision 93.1 tab. 8:

BitW323232122345
BitA345224345
PACT92.692.992.987.990.591.992.693.293.3

Hardware (modelled). Over 16 to 2 bits, the MAC density improves by about 14x when weight and activation bit-widths are reduced together §6 fig. 6. With external bandwidth limited to 64 GB/s, going from 16 to 4 bits gives a 4x increase in peak FLOPs and about 4.5x in performance. The authors attribute the extra gain to data fitting in on-chip memory §6. The first and last layers stayed at 8 bits in these runs; the authors estimate about 1.24x more if they were also quantized to 4 or 2 bits §6.

Paper vs code

No official code. The arXiv source is a wrapper around the PDF, and the PDF has no code link [raw/src/1805.06085/main2.tex]. Searches with the GitHub API: "PACT quantization" returned six repositories, none owned by an author or by IBM; "pact ibm org:IBM" returned none; "parameterized clipping activation" returned none. The closest match, KwangHoonAn/PACT (Apache-2.0), is a third-party reimplementation and is not used.

Pitfalls

  • Alpha's L2 penalty is unspecified. The paper says alpha has an L2 penalty with coefficient lambda_alpha §4 app. A.2, but does not write the term in the loss (for example whether it is lambda * alpha^2 or with a 1/2 factor). No official code is available to settle it.
  • Gradient with respect to the input is not stated. eq. 3 covers only alpha. The gradient with respect to x, and the handling of the STE for the rounding in eq. 2, are not written out. An implementation has to choose them. The usual choice is the straight-through identity for rounding and the step of eq. 1 for the input; this is an inference, not stated.
  • Initial alpha is only given for one run. The value 10 is from the ResNet20/CIFAR10 study §4 fig. 2. For other networks, the initial value is not stated. app. A.2 says a very small start puts activations where the gradient is nonzero, so alpha adapts unstably in early epochs. A very large start makes the gradient small, so alpha may stay large and quantization error suffers.
  • Quantization of the first and last layers in Table 1 is not stated. The paper's default is to keep them full precision §4.2; tab. 2 shows that quantizing them to low bits costs accuracy. Whether the Table 1 PACT runs did so is not stated.
  • Weight precision in the activation-only runs is not stated. Figure 4 and Figures 7 to 9 vary activation bit-width. Whether weights were full precision in those runs is not stated.
  • "Full precision" versus "near full precision." The text says 4-bit runs reach "full-precision accuracy consistently across the networks tested", then says "near (<= 1%)" §5.2. In tab. 1, ResNet18 with 4-bit PACT is 1.0 point below full precision (0.692 against 0.702). Use the table numbers.
  • Accuracy degradation curves are read from plots. Figures 5 and 4(f) give degradation values only as bar heights, so they are not reproduced here.
  • Hardware numbers are a model. The area and performance results come from a 14 nm MAC area estimate and the DeepMatrix framework §6 fig. 6. They are not measured silicon. The memory bandwidth of the modelled system is set per configuration §6.
  • Scope of alpha drives the hardware benefit. Per-layer scope lets alpha be applied once after all MAC operations §4.2. Per-channel and per-neuron scopes give different training and validation error app. A.1 fig. 7, and the paper prefers per-layer scope partly for hardware complexity app. A.1.

Lineage

  • Used with: DoReFa-Net (arXiv:1606.06160) for weights in tab. 1 §5.2.
  • Builds on: clipping activation functions with an upper bound (Hubara et al., Zhou et al., as cited in §3), with the clip level learned rather than set.
  • Compared against: DoReFa, BalancedQ, WRPN, FGQ, WEP, LPBN, HWGQ, with their reported numbers and settings app. C.1 app. C.2.
  • Superseded by: not stated.

Source and license

Adapted from “PACT: Parameterized Clipping Activation for Quantized Neural Networks” by Jungwook Choi, Zhuo Wang, Swagath Venkataramani, Pierce I-Jen Chuang, Vijayalakshmi Srinivasan, Kailash Gopalakrishnan (arXiv:1805.06085), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors.