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

Speaker 1Speaker 2

Synthetic Gradients in Neural Networks

16:09
0:00-16:09
  1. Maria

    Welcome! Today we’re exploring synthetic gradients: a technique proposed to speed up deep neural network training, improve performance in some settings, and help recurrent networks learn patterns over longer time spans. The idea was introduced in the 2016 paper “Decoupled Neural Interfaces using Synthetic Gradients,” by Max Jaderberg and other DeepMind researchers.

  2. Michael

    Let’s build up to it from ordinary backpropagation. In a feedforward network, the forward pass sends the inputs through the layers, each layer using its parameters to produce its outputs. At the end, the network compares its prediction with the labels to calculate a loss.

  3. Maria

    Then the backward pass starts from the loss and computes gradients, which are propagated back through the network. Those gradients tell us how changes in the layer outputs and parameters relate to the loss. Finally, gradient descent uses them to adjust the parameters in a direction intended to reduce that loss.

  4. Michael

    That dependency on information from the whole network is important. Suppose we split a network across three GPUs—one part of the model on each card. That’s model parallelism, but standard backpropagation creates several waits that can leave the GPUs idle.

  5. Maria

    The first is the forward lock: a later GPU can’t process a batch until the previous part of the network has produced the activations it needs. There’s also an update lock, because the loss must be computed before the usual parameter updates can happen. And there’s a backward lock: to update a layer in the standard way, we have to wait for gradients to travel backward at least as far as that layer.

  6. Michael

    So even with several GPUs, the work is not automatically happening in parallel. One device may be waiting while another finishes its part. In the example, the combined effect of these locks can make three-GPU model-parallel training slower than training on one GPU.

  7. Maria

    Synthetic gradients aim to break those dependencies. Imagine a hidden layer producing an activation, say h1. Along with passing h1 onward, the layer sends it to a small auxiliary model called a synthetic-gradient model, M1.

  8. Michael

    M1 predicts the gradient that the hidden layer would eventually receive from the rest of the network. Its prediction is written as delta1-hat, to distinguish it from the true gradient, delta1. The layer can use that predicted gradient to update its parameters immediately, rather than waiting for the full backward pass.

  9. Maria

    That makes the layer less dependent on the rest of the network. The paper calls this arrangement a Decoupled Neural Interface, or DNI. The next hidden layer can have its own model, M2, and make its own update from a predicted gradient; at the output layer, the true gradient can be calculated directly from the loss.

  10. Michael

    In that simplified picture, the network makes a forward pass and uses synthetic gradients instead of waiting for a conventional backward pass through every hidden layer. That can potentially cut the training time substantially—though whether it does in practice depends on the costs of the method and the setup.

  11. Maria

    And the synthetic-gradient models are training-time helpers. Once training is finished, the network is used as usual, with its trained parameters. You don’t need to run those auxiliary models just to use the trained network.

  12. Michael

    Now let’s connect decoupling to model parallelism. Suppose three parts of a network run on three GPU cards, while the CPU loads training examples and puts batches into a queue. The first GPU can work on batch one, and while it does, the CPU can load batch two.

  13. Maria

    Then the second part can work on batch one while the first part starts batch two. With the layers no longer waiting for the usual backward signal before making their updates, different GPUs can work on different batches at the same time. The aim is to keep more of the hardware active instead of having every device wait for its neighbor.

  14. Michael

    There’s a catch: activations and other data still have to move between GPU cards, and moving lots of data can take a long time. That communication cost can outweigh the benefits, especially if the model is not large enough to provide plenty of computation between transfers.

  15. Maria

    A deep model gives you more room to make the approach worthwhile. For example, a network with 30 layers could be divided into three groups of 10 layers. You could place synthetic-gradient models after every hidden layer, every few layers, or just at the boundaries between GPU cards.

  16. Michael

    With many layers, the time spent transferring data can be smaller relative to the total computation. In that situation, the GPUs may spend less time waiting, and training could approach a threefold speedup compared with regular backpropagation on a single card. That’s a possible outcome, not a guarantee.

  17. Maria

    So how does a synthetic-gradient model learn to make useful predictions? Focus on a hidden layer i. Its auxiliary model, Mi, takes the layer’s output and predicts delta-i-hat, an estimate of the gradient that the layer will need.

  18. Michael

    Mi can be a small neural network. The paper describes options such as a single linear layer with no activation, or a model with one or two hidden layers. The goal is to train it to predict the true gradients as accurately as possible.

  19. Maria

    That auxiliary model can be trained with ordinary backpropagation, using a loss that measures the difference between its predicted gradients and the target gradients. For example, the loss could be the L2 distance between them, or the square of that distance.

  20. Michael

    But there’s a puzzle: if the target is the true gradient, don’t we have to wait for the whole network’s loss and full backward pass? That would bring back the very delay synthetic gradients are meant to avoid.

  21. Maria

    The proposed workaround uses the next layer’s synthetic gradient. Once layer i plus one predicts its gradient, we backpropagate that prediction through layer i plus one. That gives us an estimate of the gradient for layer i, which can serve as a training target for Mi.

  22. Michael

    It’s not exactly the true gradient, but it may be close enough to train the model. At the output layer, where the loss is available, we can calculate the true gradient and backpropagate it. Over time, better synthetic-gradient models can provide better updates for their own layers and better training signals for models attached to earlier layers.

  23. Maria

    The approach isn’t limited to fully connected networks. It can also be used with convolutional neural networks by attaching synthetic-gradient models after selected hidden layers. An important shape requirement is that each model’s output must match the shape of the output of the layer it’s attached to.

  24. Michael

    For instance, if a convolutional layer outputs five feature maps, each 400 by 200, then its synthetic-gradient model must output an array with that same 5-by-400-by-200 shape. One practical option described is a shallow convolutional network that preserves shape, such as a couple of convolutional layers with zero padding and stride one.

  25. Maria

    There’s also a way to give the gradient model more information. Rather than taking only the layer’s output, it can receive additional inputs, such as the labels for the current batch. This is called a conditional Decoupled Neural Interface, or cDNI.

  26. Michael

    In the experiments described in the paper, cDNI consistently performed better than regular DNI, which is why the presenter suggests it as a likely default choice. The extra conditioning information can help the model predict gradients more effectively.

  27. Maria

    The paper tested these methods on MNIST, the handwritten-digit dataset, using several architectures and training methods. One fully connected network had three to six hidden layers, with 256 neurons in each layer, and used batch normalization and ReLU activations.

  28. Michael

    With regular backpropagation, the network got below two percent test error, and performance improved as more layers were added. With regular DNI—synthetic-gradient models at the hidden layers—the three-layer network ultimately did better than before, but it took extra time to train the synthetic models, so training was a little longer overall.

  29. Maria

    And adding more layers to that DNI setup made the results worse: performance decreased while training time increased. The synthetic-gradient models in that experiment were fairly substantial: each had two hidden layers of 1,024 neurons and an output layer of 256 neurons, with batch normalization and ReLU in the hidden layers.

  30. Michael

    The conditional DNI results looked different. With cDNI, adding layers improved performance, and the six-layer network achieved the best result in that comparison. It was also described as the fastest-learning architecture, reaching below two percent error in just a few thousand iterations.

  31. Maria

    A striking detail is that the cDNI experiment used very simple synthetic-gradient models without hidden layers. The presenter raises a fair caution: because the DNI and cDNI experiments used different synthetic-model architectures, it’s not a perfectly matched comparison. Even so, the reported cDNI result was better than backpropagation on this task in both final accuracy and training speed, and the paper included additional results, including for convolutional networks.

  32. Michael

    Synthetic gradients can also address a challenge in recurrent neural networks. At each time step, an RNN takes the current input, Xt, and its previous output, h at t minus one, then produces a new output, ht. When we draw the RNN unrolled over time, each box represents the same recurrent layer at a different time step.

  33. Maria

    Training an RNN by backpropagation through time means carrying the computation across time steps and then sending gradients backward through them. In practice, we can’t unroll forever because we would run out of memory. So we stop after some number of steps, calculate the loss on the outputs so far, and update the recurrent layer. That method is called truncated backpropagation through time.

  34. Michael

    Truncation is useful, but it limits how far into the future the training signal reaches. If we compute loss on only a short stretch of outputs, we have no direct information about later losses. That can make it difficult for the network to learn long-term patterns.

  35. Maria

    The synthetic-gradient idea is to unroll a little farther, but use a learned estimate at the boundary. In the example, instead of stopping at time step three, we calculate one additional output at step four and send it to a synthetic-gradient model.

  36. Michael

    That model estimates the gradient for the extra time step, delta at t equals four, with a hat. We backpropagate that estimate through the recurrent layer to get an estimate for step three. Then we can combine that estimated future signal with the true gradients from the losses we did calculate.

  37. Maria

    Once we have the gradients needed for the earlier steps, we can update the recurrent layer’s parameters. But we must not update the final unrolled cell in that pass: its output at step four will be needed shortly to train the synthetic-gradient model.

  38. Michael

    To train that model, we move forward through the next few time steps, calculate the loss, and again use the synthetic-gradient model at an extra step. Backpropagating that prediction and mixing it with the true gradients gives us an estimate of the gradient at the boundary step. That estimate can then train the synthetic-gradient model.

  39. Maria

    The process can be repeated: the recurrent network’s parameters and the synthetic-gradient model both improve over time. The key benefit is that a network can get information about future losses without having to backpropagate through an extremely long unrolled sequence all at once.

  40. Michael

    The paper’s language-modeling example used the Penn Treebank task, and measured error in bits per character, or BPC. The comparison included regular RNNs trained with backpropagation through time unrolled for eight, 20, or 40 steps.

  41. Maria

    In that comparison, longer unrolls took more training time and data, but eventually achieved better performance. The reported synthetic-gradient model used an eight-step unroll and reached the lowest error—even lower than the 40-step model—while taking roughly half as much time and data to train.

  42. Michael

    So the result illustrates the promise of synthetic gradients for long-range learning: they may let a short unroll benefit from a training signal that reflects farther into the future. The source also notes that the method adds complexity, though it expresses hope that deep-learning libraries will eventually hide some of that complexity.

  43. Maria

    There’s another kind of decoupling: breaking the forward lock. So far, we’ve used synthetic gradients to estimate signals flowing backward. A synthetic-input model instead predicts the inputs a layer would receive, letting that layer begin before the preceding layer has finished.

  44. Michael

    For example, attach a synthetic-input model, I3, to the output layer, layer three. It predicts h2-hat, an approximation of h2—the input that layer three would normally receive. Layer three can use that predicted input to start computing, without waiting for hidden layers one and two to finish.

  45. Maria

    Once the real output from layer two arrives, it can be used to train I3. And the same idea can be extended: rather than waiting for the whole network to produce h2, a synthetic-input model at an earlier interface can provide an approximation for training the next synthetic-input model.

  46. Michael

    That’s the forward counterpart to using synthetic gradients to reduce backward dependencies. Together, synthetic inputs and synthetic gradients can make a Decoupled Neural Interface operate with more independent pieces of computation.

  47. Maria

    Here’s the overall data flow for a layer i. First, its synthetic-input model receives the next training batch and estimates the layer’s inputs, h at i minus one with a hat. The layer uses those estimated inputs to produce its output, h-i, and sends that output both to the next layer and to its own synthetic-gradient model.

  48. Michael

    The synthetic gradients are backpropagated through the layer to provide an approximate gradient for the previous layer. That signal can be sent back to help train the previous layer’s synthetic-gradient model, while the current layer can immediately use its own predicted gradient, delta-i-hat, to update its parameters.

  49. Maria

    Later, when the real inputs from the previous layer arrive, they train the synthetic-input model. And when the gradient signal from the next layer arrives, it trains the synthetic-gradient model. After those updates and training signals have been handled, the interface is ready for the next batch.

  50. Michael

    So the central idea is to replace some dependencies on exact, delayed signals with learned estimates. Synthetic gradients estimate backward signals; synthetic inputs estimate forward activations. That can enable more overlap in computation, support model parallelism, and provide useful future-gradient information in recurrent networks.

  51. Maria

    The 2016 paper also discusses additional topics, including implementation details and using synthetic gradients to help two recurrent networks communicate when they operate at different rates. For readers who want to go further, the paper and related blog posts and implementations offer more detail.

  52. Michael

    And the important caveat throughout is that the benefits depend on the setting: auxiliary models must be trained, and moving data across GPUs has a cost. But the experiments and examples show why synthetic gradients were an intriguing way to loosen the strict sequencing imposed by ordinary backpropagation.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent