Consider a neural network layer with * N* input and

*output units. The forward computation is*

**M***where*

**y = h(W x + b)***and*

**W***are weights and biases, respectively,*

**b***is the activation function, and*

**h***and*

**x***are the layer’s inputs and outputs. If we choose*

**y***, or Rectified Linear Unit/Ramp Function as*

**ReLU***, there will be no multiplications in computing the activation function, thus all multiplications reside in the matrix product*

**h***. For each input vector*

**W x***,*

**x***floating point multiplications are needed.*

**N M**Binary connect eliminates these multiplications by stochastically sampling weights to be −1 or 1. Full resolution weights * w* ̄ are kept in memory as reference, and each time when

*is needed, we sample a stochastic weight matrix*

**y***according to*

**W***̄. For each element of the sampled matrix*

**w***, the probability of getting a 1 is proportional to how “close” its corresponding entry in*

**W***is to 1. i.e.,*

**w ̄*** P(W_{ij} = 1) = (w ̄_{ij}+ 1)/2*;

**P(W _{ij} = −1) = 1 − P(W_{ij} = 1)**

It is necessary to add some edge constraints to * w ̄*. To ensure that

*lies in a reasonable range, values in*

**P(W**_{ij}= 1)*are forced to be a real value in the interval [-1, 1]. If during the updates any of its value grows beyond that interval, we set it to be its corresponding edge values −1 or 1. That way floating point multiplications become sign changes.*

**w ̄**A remaining question concerns the use of multiplications in the random number generator involved in the sampling process. Sampling an integer has to be faster than multiplication for the algorithm to be worth it.

Moving on from binary to ternary connect, whereas in the former weights are allowed to be −1 or 1, in a trained neural network, it is common to observe that many learned weights are zero or close to zero. Although the stochastic sampling process would allow the mean value of sampled weights to be zero, this suggests that it may be beneficial to explicitly allow weights to be zero.

To allow weights to be zero, split the interval of [-1, 1], within which the full resolution weight value * w ̄* lies, into two sub-intervals: [−1, 0] and (0, 1]. If a weight value

*drops into one of them, we sample*

**w ̄**_{ij}*to be the two edge values of that interval,*

**w ̄**_{ij}according to their distance from * w ̄_{ij}* , i.e., if

*:*

**w ̄**_{ij}> 0**P(W _{ij} =1)= w ̄_{ij}; P(W_{ij} = 0) = 1−w ̄_{ij}**

and if

* w ̄_{ij} <=0*:

**P(W _{ij} = −1) = −w ̄_{ij}; P(W_{ij} = 0) = 1 + w ̄_{ij}**

Like binary connect, ternary connect also eliminates all multiplications in the forward pass.

We move from the forward to the backward pass. Suppose the i-th layer of the network has * N* input and

*output units, and consider an error signal*

**M***propagating downward from its output. The updates for weights and biases would be the outer product of the layer’s input and the error signal:*

**δ****∆W = ηδ◦h′ (W x + b) x ^{T }**

**∆b = ηδ◦h (W x + b)**

where * η* is the learning rate, and

*the input to the layer. While propagating through the layers, the error signal*

**x***needs to be updated, too. Its update taking into account the next layer below takes the form:*

**δ****δ = W ^{T}δ◦h′ (W x + b)**

Three terms appear repeatedly in the above three equations, viz. * δ*,

*and*

**h (W x + b)***.*

**x***The latter two terms introduce matrix outer products. To eliminate multiplications, one can quantize one of them to be an integer power of 2, so that multiplications involving that term become binary shifts. The expression*

*contains down flowing gradients, which are largely determined by the cost function and network parameters, thus it is hard to bound its values. However, bounding the values is essential for quantization because we need to supply a fixed number of bits for each sampled value, and if that value varies too much, we will need too many bits for the exponent. This, in turn, will result in the need for more bits to store the sampled value and unnecessarily increase the required amount of computation.*

**h′ (W x + b)**While * h′ (W x + b)* is not a good choice for quantization,

*is a better choice, because it is the hidden representation at each layer, and we know roughly the distribution of each layer’s activation.*

**x**The approach is therefore to eliminate multiplications in

**∆W = ηδ◦h′ (W x + b) x ^{T }**

by quantizing each entry in * x* to an integer power of 2. That way the outer product in

* ∆W = ηδ◦h′ (W x + b) x^{T }* becomes a series of bit shifts. Experimentally, it is discovered that allowing a maximum of 3 to 4 bits of shift is sufficient to make the network work well. This means that 3 bits are already enough to quantize

*. As the float 32 format has 24 bits of mantissa, shifting (to the left or right) by 3 to 4 bits is completely tolerable. This approach is referred to as “quantized back propagation”.*

**x**If we choose * ReLU* as the activation function and use binary (ternary) connect to sample W, computing the term

*involves no multiplications at all. In addition, quantized back propagation eliminates the multiplications in the outer product in*

**h’ (W x + b)*** ∆W = ηδ◦h′ (W x + b) x^{T}*.

The only place where multiplications remain is the element-wise product. From

* ∆W = ηδ◦h′ (W x + b) x^{T}*,

*and*

**∆b = ηδ◦h (W x + b),***,*

**δ = W**^{T}δ◦h′ (W x + b)*can see that*

**one***multiplications are needed for all computations. Like in the forward pass, most of the multiplications are used in the weight updates. Compared with standard back propagation, which would need*

**6 × M***multiplications, the amount of multiplications left is negligible in quantized back propagation.*

**2MN + 6M**