# DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients

Low bitwidth gradients enable bit convolution training

Shuchang Zhou, Yuxin Wu, Zekun Ni, Xinyu Zhou, He Wen, Yuheng Zou · arXiv · 2016-6-20

- **Problem** Binarized networks keep gradients in full precision, so their backward pass cannot use fast bit convolution kernels. Most of their training time therefore stays in slow arithmetic.
- **Method** DoReFa-Net quantizes weights, activations and gradients to low bitwidth, with gradients quantized stochastically. Instead of keeping gradients in full precision, it runs both passes on bit convolution kernels.
- **Results** DoReFa-Net reached 46.1% single-crop top-1 on ImageNet with 1-bit weights, 2-bit activations and 6-bit gradients, trained from scratch.

## Why the backward pass limits binarized training

Binarized networks such as BNN and XNOR-Net binarize both the weights and the input activations of convolutional layers, so the forward pass can be computed with bitwise operations. The backward pass is different, because the gradients stay in full precision. The convolution between those gradients and the 1-bit weights therefore multiplies 1-bit numbers by 32-bit floating-point values.

The authors argue that this leaves the backward pass unable to exploit bit convolution, so most training time of these networks falls there.

Earlier reduced-precision training work, such as the schemes of Gupta et al. and Courbariaux et al., still performs convolutions on numbers of at least 10 bits. The authors state that no earlier work had quantized backward-pass gradients below 8 bits while keeping comparable prediction accuracy. DoReFa-Net targets this gap by making weights, activations and gradients all low bitwidth, so that convolutions in both passes can run on bit convolution kernels.

## Bit convolution as the computational core

For 1-bit vectors, a dot product equals the bit count of the bitwise AND of the two vectors. For fixed-point integers, each value is written as a sum of its bits weighted by powers of two, so the dot product becomes a double sum over the bit positions m of x and k of y, with each partial bit count weighted by \\(2^{m+k}\\). \\\[ x\\cdot y=\\sum\_{m=0}^{M-1}\\sum\_{k=0}^{K-1}2^{m+k}\\,\\mathrm{bitcount}\[\\mathrm{and}(c\_m(x),c\_k(y))\] \\\] Here \\(c\_m(x)\\) and \\(c\_k(y)\\) are bit vectors, so the cost is O(MK), proportional to the product of the two bitwidths.

When both vectors take values in {-1, 1}, an XNOR form replaces the AND form, and the dot product is N minus twice the bit count of the XNOR of the two vectors. Every low bitwidth tensor in the method is an affine image of fixed-point integers, so the same kernel serves the forward, backward-input and backward-weight products.

## Training through rounding with a straight-through estimator

A function with a small finite range has zero gradient with respect to its input almost everywhere, so ordinary backpropagation would not update anything behind such a quantizer. The straight-through estimator avoids this by choosing an operator with its own forward and backward rules, independent of the true derivative. For Bernoulli sampling with probability p, the backward rule passes the gradient with respect to the sample q to p, which is justified because q equals p in expectation.

The quantizer quantizek takes a real input r\_i in \[0, 1\] and, in the forward pass, returns the nearest k-bit level. \\\[ r\_o=\\frac{1}{2^k-1}\\,\\mathrm{round}\\big((2^k-1)\\,r\_i\\big) \\\] In the backward pass the gradient with respect to r\_o is passed unchanged to r\_i. Because the output is a k-bit fixed-point value, dot products of such outputs can use the integer dot product followed by a scaling step.

## Quantizing weights to one or k bits

BNN binarizes weights with a sign function, and its backward rule passes the gradient only where the latent weight magnitude is at most 1. XNOR-Net also scales each binarized filter by a factor equal to the mean absolute value of each output channel. DoReFa-Net instead multiplies the binarized weights by one constant scalar for all filters, because channel-wise scaling would prevent bit kernels from being used when gradients are convolved with weights in the backward pass.

For k greater than 1, the weights are first squashed with tanh, divided by twice their largest absolute tanh value in the layer, shifted by one half, quantized and then mapped back to \[-1, 1\]. The authors find that the 1-bit form of this mapping, which differs from the constant-scalar form, makes no meaningful difference in their experiments.

## Deterministic activations and stochastic gradients

The authors could not reproduce XNOR-Net results with its activation binarization, and they cite Rastegari et al. for the claim that binarizing activations as in BNN severely degrades AlexNet accuracy on ImageNet. DoReFa-Net assumes the previous layer's output passes through a bounded function h, so the input activations lie in \[0, 1\], and then applies quantizek directly to them.

The scaling maximum runs over every axis of the gradient except the mini-batch axis, so each instance keeps its own scale. The gradient quantizer acts only in the backward pass: each convolution output is passed forward unchanged, and its gradient is replaced by the quantized version. The authors find stochastic quantization necessary for low bitwidth gradients, in line with Gupta et al.

on 16-bit weights and gradients.

## Training loop and what stays at full precision

In the forward pass of Algorithm 1, each layer uses a quantized copy of its weights and quantizes its output activation when the layer is not the last one. In the backward pass, each layer's gradient goes through the activation function, the gradient quantizer, and then the backward input and backward weight products, which all operate on low bitwidth numbers.

The parameter update acts on the unquantized weights W\_k with the accumulated gradient, so the full-precision copy is kept for updates.

The first layer receives an image, which may hold 8-bit features, and the output layer produces nearly one-hot vectors, which the authors note are close to bit vectors. Most experiments therefore leave the first convolutional layer's weights unquantized while its outputs are quantized, and leave the last fully connected layer intact, with its gradients still quantized.

Storing h(a\_k) in full precision would consume run-time memory, so the authors fuse the nonlinearity with the rounding step. When h is monotonic, the few possible values of the quantized activation correspond to non-overlapping ranges of a\_k, so the quantized value can be obtained by comparisons between fixed-point numbers. For max-pooling, quantizek commutes with the max, so the quantized gradient can also be produced from the stored gradient by comparisons.

## SVHN bitwidth sweep

The SVHN cropped format has 73257 training digits, 26032 testing digits and 531131 less difficult samples that can serve as extra training data, with images resized to 40x40. Training uses ADAM with a learning rate of 0.001, and the reported number is the maximum test-set accuracy over 200 epochs.

With 1-bit weights, 1-bit activations and 2-bit gradients, Model A reaches 0.934 in the table, and the text rounds this configuration to 93% accuracy. Some rows are not monotone in bitwidth: 1-4-2 gives 0.815 for Model A, while 1-4-4 gives 0.975.

The authors find that weights, activations and gradients become progressively more sensitive to low bitwidth, and that gradients with G of 4 or fewer bits significantly degrade accuracy on SVHN. Gradient accuracy saturates at about 8 bits in most cases, and the authors find the best gradient bitwidth less tied to channel count. The authors attribute the smaller loss for Model A than for Model C to models with more channels being less sensitive to bitwidth, and suggest raising activation bitwidth for models with fewer channels as a compensation.

## ImageNet results for AlexNet variants

The evaluation uses ILSVRC12, with about 1.2 million training images, 50k validation images and 1000 categories, reported as single-crop top-1 accuracy with inputs at 224x224. The 32-bit baseline AlexNet reaches 55.9% single-crop top-1. It replicates the original model with the second, fourth and fifth convolutions split into two parallel blocks and batch normalization in place of local contrast renormalization, trained with ADAM at 10−4 and then lowered to 10−5 and 10−6.

With 1-bit weights and 6-bit gradients, raising activations from 1 bit to 2, 3 and 4 bits gives 0.395, 0.461, 0.471 and 0.482 top-1 in the table. The 1-2-6 setting reaches 46.1% top-1, the figure given as the headline result of the paper. At each activation bitwidth the 6-bit gradient rows are close to the 32-bit gradient rows: 0.395 against 0.401 for 1-1, 0.461 against 0.477 for 1-2, and 0.471 against 0.484 for 1-3.

The authors describe 6-bit gradients as producing similar accuracy to 32-bit gradients.

The BNN row, 0.279, is taken from Rastegari et al., and the XNOR-Net row, 0.442, is also a reported figure, so these two are not controlled runs under the authors' setup. The 1-1-32 row at 0.401 is the authors' own run.

Models initialized from a 32-bit model score higher than models trained from scratch: 0.498 against 0.477 for 1-2-32, and 0.530 against 0.503 for 1-4-32. The authors describe the gap between trained-from-scratch and initialized models as considerable and leave closing it to future work.

Training curves for 6-bit gradients do not differ clearly from the unquantized curves, while 4-bit gradients as in the 1-2-4 setting show a clear drop in accuracy. The histograms show weights that remain roughly symmetric as their scale changes, and activations whose distribution stays stable across epochs 5, 15 and 35.

## Effect of quantizing the first and last layers

The baseline (1, 2, 4) scores 0.975 for Model A, 0.969 for Model B and 0.939 for Model C. Adding quantization of the first convolutional layer gives 0.972, 0.963 and 0.932, and adding quantization of the last fully connected layer gives 0.973, 0.969 and 0.927. Quantizing both gives 0.971, 0.961 and 0.928.

The authors describe quantizing the first and last layers as causing significant accuracy degradation, larger for models with fewer channels. For Model C, the drop is from 0.939 to 0.927 when the last layer is quantized, while the changes for Model A are smaller. The authors read this as some justification for the practice of BNN and XNOR-Net of leaving these two layers unquantized.

## How gradient quantization differs from earlier work

Lin et al. make a step toward low bitwidth gradients by turning some multiplications into bit shifts, but additions between high bitwidth numbers remain at the same order of magnitude. Seide et al. quantize gradients before communication in distributed training, but they keep full precision gradients in the backward pass and quantize only before sending them.

To the authors' knowledge, this is the first work to reduce gradient bitwidth to 6 bits or lower while keeping comparable accuracy on AlexNet and ImageNet, without increasing channel count.

## Limitations

Trained-from-scratch models stay below initialized models, for example 0.477 against 0.498 for 1-2-32, and the authors leave closing that gap to future work. The ImageNet experiments use the combination (W, A) = (1, 2) with gradients of G of at least 4, chosen from the SVHN sweep, and most ImageNet runs leave the first and last layers unquantized.

The SVHN numbers are maxima of test-set accuracy over 200 epochs, not held-out selections. The complexity columns of Table 1 are computed from the bit-level dot product in Eqn. 3, and the text reports no measured run time on hardware. The authors list training on FPGA as future work because of the resource scaling of B-bit arithmetic.

## Paper info

- **Authors**: Shuchang Zhou, Yuxin Wu, Zekun Ni, Xinyu Zhou, He Wen, Yuheng Zou
- **Venue**: arXiv · Preprint
- **First published**: 2016-6-20
- **Added**: 2026-11-12
- **Updated**: 2018-2-2
- **Version**: v3
- **arXiv**: 1606.06160
- **Category**: cs.NE · cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1606.06160v3) · [PDF ↗](https://arxiv.org/pdf/1606.06160v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Shuchang Zhou, Yuxin Wu, Zekun Ni, Xinyu Zhou, He Wen, Yuheng Zou (2016). DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients. arXiv:1606.06160v3. https://arxiv.org/abs/1606.06160v3

**BibTeX**

```
@misc{zhou2016dorefa,
  title = {{DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients}},
  author = {Shuchang Zhou and Yuxin Wu and Zekun Ni and Xinyu Zhou and He Wen and Yuheng Zou},
  year = {2016},
  eprint = {1606.06160},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1606.06160v3}
}
```

## Other paper commentary

- [Deep Interest Network for Click-Through Rate Prediction](https://refivu.com/en/papers/436010e9-a2e2-4bc6-b152-9c915305a90b-deep-interest-network-for-click-through-rate-prediction.md)
- [Time Series Classification from Scratch with Deep Neural Networks: A Strong Baseline](https://refivu.com/en/papers/8883de27-afd8-4d47-acd8-ad01a7dfe332-time-series-classification-from-scratch-with-deep-neural.md)
- [Temporal Ensembling for Semi-Supervised Learning](https://refivu.com/en/papers/5823cdfc-4033-4589-9f86-a6c88d27f620-temporal-ensembling-for-semi-supervised-learning.md)
- [Modeling Long- and Short-Term Temporal Patterns with Deep Neural Networks](https://refivu.com/en/papers/2ced2044-9976-4c74-bbf8-ff344f253f42-modeling-long-and-short-term-temporal-patterns-with.md)
- [PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization](https://refivu.com/en/papers/d88e659c-e7cf-4fb4-acf4-46e297868666-posenet-a-convolutional-network-for-real-time-6.md)
- [Gate-Variants of Gated Recurrent Unit (GRU) Neural Networks](https://refivu.com/en/papers/15731593-7d6d-4afb-b434-961a20dea639-gate-variants-of-gated-recurrent-unit-gru-neural.md)
- [Learning Face Representation from Scratch](https://refivu.com/en/papers/c66cea99-ee67-42f0-85f5-a773fc796f34-learning-face-representation-from-scratch.md)
- [Counterfactual Explanations without Opening the Black Box: Automated Decisions and the GDPR](https://refivu.com/en/papers/0d61122d-d270-4b56-bf77-9a4632bff37e-counterfactual-explanations-without-opening-the-black-box.md)
- [Deep Visual Domain Adaptation: A Survey](https://refivu.com/en/papers/3dd8a4f2-35cf-4fdf-a297-20b7bede8d13-deep-visual-domain-adaptation-a-survey.md)
- [Maximum Classifier Discrepancy for Unsupervised Domain Adaptation](https://refivu.com/en/papers/22b90534-4c22-46ce-8bbe-924741648b13-maximum-classifier-discrepancy-for-unsupervised-domain.md)
- [Dota 2 with Large Scale Deep Reinforcement Learning](https://refivu.com/en/papers/75855eab-2276-4a17-9eaa-6ee97e11ddb7-dota-2-with-large-scale-deep-reinforcement-learning.md)
- [Connecting the Dots: Multivariate Time Series Forecasting with Graph Neural Networks](https://refivu.com/en/papers/f0231d70-9d15-48d0-aa7c-c83cefdf69ab-connecting-the-dots-multivariate-time-series-forecasting.md)

## Terms in this paper

- [ImageNet](https://refivu.com/en/terms/5eadad128667-imagenet)
- [Batch Normalization](https://refivu.com/en/terms/2b3e5f8509f6-batch-normalization)
- [Top-1 accuracy](https://refivu.com/en/terms/653c0b9eaa58-top-1-accuracy)
- [AlexNet](https://refivu.com/en/terms/e5142ede4de4-alexnet)
- [SVHN](https://refivu.com/en/terms/c24d35c2e4d0-svhn)
- [straight-through estimator](https://refivu.com/en/terms/daa90b015f59-straight-through-estimator)
- [DoReFa-Net](https://refivu.com/en/terms/9662c236e02d-dorefa-net)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/2b8264c6-509a-4bef-bf4f-0e373a15bf5f-dorefa-net-training-low-bitwidth-convolutional-neural)
