1. Home
  2. Explore
  3. Computer Science
  4. Synthetic Gradients in Neural Networks

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Synthetic Gradients in Neural Networks

Synthetic Gradients and Decoupled Neural Networks

Backpropagation refresher

A feedforward neural network processes an input through a sequence of layers. Each layer uses its parameters to transform its inputs and produce outputs. For example, a network with three layers produces activations h1h_1h1​, h2h_2h2​, and h3h_3h3​, using parameter sets θ1\theta_1θ1​, θ2\theta_2θ2​, and θ3\theta_3θ3​. The network’s final output is compared with the target label to calculate a loss.

Training with backpropagation consists of two main phases:

  1. Forward pass: The input travels through the network, layer by layer, until the output and loss are computed.

  2. Backward pass: Gradients of the loss are propagated backward through the layers. These gradients indicate how changes to each layer’s activations and parameters would affect the loss.

The parameters are then adjusted using gradient descent, moving them in a direction intended to reduce the loss. In ordinary backpropagation, a layer cannot calculate its true gradient until the forward pass has reached the output and the backward pass has returned to that layer.


Why ordinary model parallelism can be inefficient

Model parallelism divides a neural network among multiple processors, such as GPUs, with different parts of the network assigned to different processors. This can make it possible to work with models too large for a single processor, but ordinary backpropagation can leave the processors idle.

Three dependencies create delays:

  • Forward lock: A layer cannot process a batch until the preceding layer has produced its activations.

  • Update lock: The loss must be calculated before the network can obtain the gradients needed to update its parameters.

  • Backward lock: A layer cannot update its parameters using true gradients until the backward pass has reached it.

As a result, processors may have to wait for other processors to finish their portions of the same batch. With a small number of network parts, the time spent waiting and moving data can outweigh the benefit of using multiple processors.

Synthetic gradients are intended to reduce these dependencies. Rather than waiting for a true gradient to travel backward through the entire network, a layer uses a learned model to estimate its gradient and can update its parameters sooner.


Synthetic gradients and decoupled neural interfaces

A synthetic gradient is an estimated gradient produced by a learned model, rather than the exact gradient obtained from backpropagating the loss. If a layer produces activation hih_ihi​, a synthetic-gradient model MiM_iMi​ uses that activation to predict an estimate of the gradient, written δ^i\hat{\delta}_iδ^i​.

The layer can use δ^i\hat{\delta}_iδ^i​ to update its parameters without waiting for the loss to be calculated and the true gradient to propagate back through the rest of the network. This separates the layer’s learning step from the timing of the rest of the network.

A layer equipped with its own synthetic-gradient model is a Decoupled Neural Interface (DNI). In a DNI network:

  • Each hidden layer can estimate the gradient it needs.

  • Layers can update their parameters independently and earlier than they could with ordinary backpropagation.

  • The output layer can still use true gradients, since it has direct access to the loss.

Synthetic-gradient models are used during training. Once training is complete, the network makes predictions using its trained parameters in the usual way; the synthetic-gradient models are not required for ordinary inference.

Potential speed benefit

If layers can perform their updates from a forward pass and estimated gradients, they need not wait for a full backward pass. In principle, this can substantially reduce training time. The actual speedup depends on the cost of the synthetic-gradient models, communication between processors, and other implementation details.


Training synthetic-gradient models

A synthetic-gradient model can be a small neural network. For example, it might consist of a linear layer, or it might include one or more hidden layers. Its goal is to predict the gradients that would otherwise be calculated for the layer’s activations.

The model can be trained by minimizing a loss between its prediction and a target gradient. One possible objective is the squared distance between the predicted gradient and the target:

∥δ^i−δi∥2\left\|\hat{\delta}_i-\delta_i\right\|^2​δ^i​−δi​​2

Here, δ^i\hat{\delta}_iδ^i​ is the synthetic gradient, and δi\delta_iδi​ is the target gradient. The synthetic-gradient model itself can be trained with ordinary backpropagation.

Obtaining a target without waiting for the full backward pass

Using the exact gradient δi\delta_iδi​ as the target would seem to require waiting for the loss and the full backward pass, undermining the point of synthetic gradients. A workaround is to use the next layer’s synthetic gradient.

If layer i+1i+1i+1 produces an estimated gradient δ^i+1\hat{\delta}_{i+1}δ^i+1​, that estimate can be backpropagated through layer i+1i+1i+1 to produce an approximation of the gradient for layer iii. This approximation can serve as the training target for MiM_iMi​. If the next layer is the output layer, the true gradient can be calculated and backpropagated instead.

As the synthetic-gradient models improve, their predictions can become more useful in two ways: they can guide their own layers’ parameter updates, and they can provide better training targets for synthetic-gradient models in earlier layers.


Using synthetic gradients for model parallelism

In model parallelism, the network is split across processors. A CPU or other coordinator can load training batches and place them in a queue. With synthetic gradients, different processors can work on different batches at the same time:

  1. The first processor begins processing batch 111.

  2. While later layers process batch 111, the first processor can begin batch 222.

  3. Each network segment can continue working as soon as its required inputs are available, rather than waiting for every other segment to finish the same batch.

This pipeline can keep more processors active and reduce idle time.

Communication and partitioning trade-offs

Model parallelism still requires activations and other data to move between processors. When the network is shallow, the communication cost may be large compared with the computation saved by parallel execution. In that case, using multiple processors can fail to speed training and may even make it slower.

For a deeper network, the same communication cost may be smaller relative to the total computation. For example, a network with about thirty layers could be split into several segments, each containing multiple layers. Synthetic-gradient models could be placed at every hidden layer, every few layers, or mainly at the boundaries between processors.

The placement of synthetic-gradient models therefore involves a trade-off: more interfaces can create more opportunities for independent computation, but also introduce additional computation and communication. Speedups depend on the network, hardware, batch schedule, and data-transfer overhead.


Applying synthetic gradients to convolutional networks

Synthetic gradients can be used with different network types, including convolutional neural networks (CNNs). A synthetic-gradient model is attached to a selected hidden layer and predicts a gradient with the same shape as that layer’s output.

For example, if a convolutional layer produces five feature maps, each of size 400×200400 \times 200400×200, then its output has shape 5×400×2005 \times 400 \times 2005×400×200. The attached synthetic-gradient model must produce an output of that same shape.

A shallow convolutional network can be designed to preserve the input shape. For instance, convolutional layers with zero padding and stride 111 can maintain the spatial dimensions, allowing the synthetic-gradient model’s output to match the layer’s activation shape.


Conditional decoupled neural interfaces

A synthetic-gradient model does not have to rely only on its layer’s activation hih_ihi​. It can also receive additional information that may help it predict the gradient.

A conditional Decoupled Neural Interface (cDNI) supplies such additional context. One example is the labels for the current training batch. The synthetic-gradient model then predicts its gradient using both the layer’s activation and the extra information.

Experiments described in the source report that cDNI performed consistently better than ordinary DNI in the tested settings. The added context can make gradient predictions more informative. However, comparisons between methods should be interpreted in light of their specific model designs and training configurations.


Reported MNIST experiments

The reported experiments used the MNIST handwritten-digit dataset and fully connected networks with three to six hidden layers, each containing 256256256 neurons. The hidden layers used batch normalization and the ReLU activation function.

Ordinary backpropagation

With regular backpropagation, the tested networks reached test error below 2%2\%2%. Adding layers improved performance in the reported results.

DNI at every hidden layer

With synthetic-gradient models at each hidden layer, the three-layer network ultimately performed better than its backpropagation counterpart, but training took longer overall because the synthetic-gradient models also needed to learn.

For deeper networks, the reported DNI results were less favorable: performance decreased as layers were added, while training time increased. In this experiment, each synthetic-gradient model had two hidden layers of 102410241024 neurons each and an output layer of 256256256 neurons. Its hidden layers also used batch normalization and ReLU.

Conditional DNI

The reported cDNI results improved as network depth increased. The six-layer network achieved the best performance in the comparison and reached test error below 2%2\%2% within a few thousand iterations. It was also reported as the fastest-learning architecture in that experiment.

The synthetic-gradient models used for cDNI were described as simple models without hidden layers, unlike the deeper models used in the DNI experiment. This difference means the results do not isolate the effect of conditioning alone: the model architectures also differed. The reported results nevertheless demonstrate that cDNI can perform very well in this task. Other experiments described in the source included promising results with convolutional networks.


Synthetic gradients for recurrent neural networks

A recurrent neural network (RNN) processes a sequence over time. At time step ttt, a recurrent layer receives the current input XtX_tXt​ and its previous output ht−1h_{t-1}ht−1​, then produces a new output hth_tht​.

The same recurrent layer is used at every time step. To make the sequence of operations explicit, an RNN is often represented as if that layer were copied across time. The copies share parameters, but each processes a different input and recurrent state.

Truncated backpropagation through time

Training an RNN over a long sequence can require substantial memory. A common approach is to stop the unrolled network after a limited number of time steps, calculate the loss from the outputs so far, and backpropagate through that limited segment. This is truncated backpropagation through time (truncated BPTT).

Truncation makes training more manageable, but it limits how far back the training signal can reach. If the loss depends on events beyond the segment, the network receives no direct gradient information about those future losses during that update. Consequently, learning patterns that require long-term dependencies can be difficult.

Extending the training signal with synthetic gradients

Synthetic gradients can estimate future gradient information without requiring a very long unrolling of the RNN:

  1. The RNN is unrolled for a short segment and then for an additional time step.

  2. Rather than relying only on a loss at that added step, a synthetic-gradient model estimates the gradient associated with it.

  3. That estimated gradient is backpropagated through the recurrent computation to produce an estimate for the preceding time step.

  4. The estimated future gradient is combined with true gradients from the observed portion of the sequence.

  5. The resulting gradients are used to update the recurrent network’s shared parameters.

This approach can provide information about future losses even when the network is unrolled through only a few time steps. It therefore offers a way to capture longer-term patterns without backpropagating through the entire sequence.

The last unrolled cell needs special handling during this procedure. Its output may be needed later to train the synthetic-gradient model. Updating the recurrent parameters in a way that changes that output before the synthetic-gradient model is trained would interfere with that training signal.

Training the RNN’s synthetic-gradient model

Training the synthetic-gradient model requires obtaining a better target for its prediction:

  1. The RNN is run forward over the next few time steps.

  2. The loss is computed from those later outputs.

  3. An additional time step and the synthetic-gradient estimate are used to propagate an estimated gradient backward.

  4. The estimated gradient at the target time step is compared with the synthetic-gradient model’s prediction.

  5. That comparison is used to train the synthetic-gradient model.

  6. The resulting gradients can then be used to update the RNN parameters.

Repeating this process can improve both the recurrent network and the model that estimates its gradients. It adds training complexity, but it can extend the useful reach of the training signal.


Reported recurrent-network results

The reported RNN comparison used a language-modeling task on the Penn Treebank dataset. Performance was measured in bits per character (BPC), with lower error indicating better performance. Training time was also compared.

Ordinary RNNs trained with backpropagation through time were unrolled for different numbers of steps: 888, 202020, or 404040. Longer unrolling took more time and data but eventually produced better performance in the reported comparison.

A separate RNN was unrolled for only 888 steps and trained using synthetic gradients. Its learning curve reached a lower error than the ordinary RNN unrolled for 404040 steps, while taking roughly half as much time and data in the reported results. This illustrates how synthetic gradients can help a short unrolling benefit from information about later time steps.


Synthetic inputs and breaking the forward lock

Synthetic gradients address delays caused by waiting for gradients to travel backward. A related idea, the synthetic input model, addresses the forward lock: the need to wait for lower layers to produce their activations before an upper layer can begin processing.

A synthetic-input model IiI_iIi​ predicts an approximation of the input that layer iii would receive. For example, a synthetic-input model attached to the output layer can estimate the preceding hidden layer’s activation, written h^2\hat{h}_2h^2​. The output layer can then process h^2\hat{h}_2h^2​ before the actual activation h2h_2h2​ is available.

When the actual lower-layer output later arrives, it can be used to train the synthetic-input model. The same general idea can be applied across multiple layers: a layer’s synthetic-input model can use predictions from earlier layers rather than waiting for all true activations to pass through the network.

Thus, synthetic inputs work in the forward direction much as synthetic gradients work in the backward direction: both use learned estimates to reduce a dependency on information that has not yet arrived.


Data flow in a fully decoupled interface

A fully decoupled layer can use both a synthetic-input model and a synthetic-gradient model. The main information flows are:

  1. The synthetic-input model receives the next training batch and estimates the layer’s input, h^i−1\hat{h}_{i-1}h^i−1​.

  2. The layer processes that estimated input and produces its output, hih_ihi​.

  3. The output is sent to the next layer and to the layer’s synthetic-gradient model.

  4. The synthetic-gradient model estimates the layer’s gradient, δ^i\hat{\delta}_iδ^i​.

  5. The estimated gradient is backpropagated through the layer to produce an approximation of the gradient for the preceding layer.

  6. The layer can use its synthetic gradient to update its own parameters without waiting for all true gradients.

  7. When the actual preceding-layer output hi−1h_{i-1}hi−1​ arrives, it is used to train the synthetic-input model.

  8. When a gradient arrives from the next layer, it is used to train the synthetic-gradient model.

This arrangement allows the layer to proceed using estimates, while later-arriving real activations and gradients improve those estimates. It is designed to reduce both forward and backward dependencies in training.


Key ideas and limitations

  • Synthetic gradients are learned estimates that let layers update before exact gradients arrive.

  • DNI uses synthetic-gradient models to decouple layer updates from the rest of the network’s backward pass.

  • cDNI supplies additional context, such as labels, to improve gradient prediction.

  • Synthetic inputs estimate activations that have not yet arrived, helping reduce forward-pass dependencies.

  • In RNNs, synthetic gradients can provide estimated information about future losses beyond a short truncated sequence.

  • These methods can improve processor utilization and training speed, but their effectiveness depends on the quality of the estimates, the cost of the added models, and communication overhead.

  • A poor synthetic estimate may lead to less accurate updates, so the synthetic models must themselves be trained effectively.

  • Reported advantages are task- and configuration-dependent; experimental comparisons may involve differences in model architecture as well as differences in the training method.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent