AI Logic

Continual Learning

Synaptic Intelligence (SI)

Updated:

SI training flow. Left: the task loss plus a penalty built from the reference weights θ~ and importance Ω updates the weights, the contribution ω is accumulated at every update, and Ω and θ~ are updated at the end of each task. Right: the parameter space of two weights, showing the training path for task 1 and the per-weight importance accumulated along it.

Background and overview

Synaptic Intelligence (SI) is a continual learning method that, during training, accumulates per weight how much each step of that weight's movement reduced the loss, obtaining "weight importance" online, and then on later tasks adds a penalty to the loss that makes more important weights harder to move from their previous values, so that earlier tasks are not forgotten. It was presented at ICML in 2017 by Zenke, Poole, and Ganguli of Stanford University.

When a neural network learns tasks one after another, moving its weights to fit a new task also overwrites weights that earlier tasks needed, and performance on earlier tasks drops sharply (catastrophic forgetting). One way to prevent this is to "leave weights that were important for earlier tasks alone and learn the new task with unimportant weights." EWC, published the same year, is also based on this idea.

The difference between SI and EWC lies in how weight importance is measured. EWC computes importance with a separate calculation (the Fisher information) at the weights reached after finishing a task. SI accumulates, alongside training, "how much the loss decreased because that weight moved" over the entire training path.

The "synapse" in the name refers to the junctions between neurons in the brain. A weight in an artificial neural network is a single number, but a synapse in the brain has a much more complex state. SI gives each weight, in addition to its "current value," a state consisting of its "value at the end of the previous task" and its "importance," so that each weight can compute its importance from locally available information alone.

Weight importance and the loss

Denote the weights by θk\theta_k (kk is the weight index) and the tasks by μ=1,2,…\mu = 1, 2, \dots. When training moves the weights by a small amount δk\delta_k, the change in loss can be approximated using the gradient gk=∂L/∂θkg_k = \partial L / \partial \theta_k as follows (Eq. (1) in the paper).

L(θ+δ)−L(θ)≈∑kgkδkL(\theta + \delta) - L(\theta) \approx \sum_k g_k \delta_k

In other words, the movement of weight θk\theta_k contributes gkδkg_k \delta_k to the change in loss. Summing this over the entire training path of task μ\mu gives weight kk's contribution to task μ\mu, ωkμ\omega_k^\mu (Eq. (3) in the paper).

ωkμ=−∫tμ−1tμgk(θ(t)) θk′(t) dt\omega_k^\mu = -\int_{t^{\mu-1}}^{t^\mu} g_k(\theta(t)) \, \theta_k'(t) \, dt

tμ−1t^{\mu-1} and tμt^\mu are the start and end times of training on task μ\mu, and the minus sign makes ωkμ\omega_k^\mu larger for weights that reduced the loss more. Summing ωkμ\omega_k^\mu over all weights gives the total loss reduction achieved while training on task μ\mu.

The procedure for learning tasks sequentially with SI is as follows.

  1. While training on task μ\mu, at every update, accumulate the product of the gradient gkg_k and the weight change Δθk\Delta\theta_k per weight as ωk−=gkΔθk\omega_k \mathrel{-}= g_k \Delta\theta_k.
  2. After finishing task μ\mu, update the weight importance Ωk\Omega_k using the weight movement during that task, Δkμ=θk(tμ)−θk(tμ−1)\Delta_k^\mu = \theta_k(t^\mu) - \theta_k(t^{\mu-1}).
  3. Save the current weights as the reference weights θ~k\tilde\theta_k for the next task, and reset ωk\omega_k to 0.
  4. Train the next task μ+1\mu + 1 with the loss L~μ+1\tilde L_{\mu+1} below, then return to step 1.

The weight importance in step 2 is the sum of past tasks' contributions, each divided by the squared distance moved (Eq. (5) in the paper).

Ωkμ=∑ν<μωkν(Δkν)2+ξ\Omega_k^\mu = \sum_{\nu < \mu} \frac{\omega_k^\nu}{\left(\Delta_k^\nu\right)^2 + \xi}

ξ\xi is a small value that keeps the denominator from approaching 0 for weights that barely moved, preventing extremely large importance values. The loss in step 4 is task μ\mu's loss plus a quadratic penalty (Eq. (4) in the paper).

L~μ=Lμ+c∑kΩkμ(θ~k−θk)2\tilde L_\mu = L_\mu + c \sum_k \Omega_k^\mu \left( \tilde\theta_k - \theta_k \right)^2

θ~k\tilde\theta_k is the weight at the end of the previous task, and cc is a strength that sets how much to favor old versus new tasks.

The penalty has the same form as EWC: "per-weight importance × squared distance from the previous value." What differs is the importance itself: EWC uses the Fisher information at the weights at the end of a task, while SI uses the contribution ω\omega accumulated along the training path divided by the squared distance moved.

Why important weights can be identified

SI's penalty is constructed as a quadratic loss that stands in for the previous task's loss (a surrogate loss). The paper considers replacing the previous task's loss with a quadratic function that satisfies the following three conditions (Figure 2 in the paper).

  • Its minimum is at the weights θ~\tilde\theta at the end of training on the previous task
  • The distance Δ\Delta moved during training on the previous task is the same
  • The loss reduction ω\omega over that movement is the same

Only one quadratic function satisfies all three, and its curvature along weight kk is proportional to ωk/Δk2\omega_k / \Delta_k^2. A weight that reduced the loss greatly while moving only a little lies along a steeply curved direction (a small move increases the loss a lot), so it is anchored strongly. A weight that moved a lot without reducing the loss much lies along a gently curved direction, so it is free to move for the new task.

The paper analyzes the simple case of gradient descent on a quadratic loss and shows that, when averaged over random initial values, the accumulated contributions (as a matrix) are proportional to the second derivative of the loss (the Hessian). When the Hessian is diagonal, dividing by Δ2\Delta^2 in the denominator cancels the scale differences due to the choice of initial values, and the importance becomes exactly the diagonal of the Hessian. In other words, SI's importance, like EWC's, estimates "the curvature of the loss."

For general losses, however, the Hessian changes along the training path, so SI's importance and the curvature at the endpoint (EWC's estimate) do not coincide. Still, the paper notes that the two are correlated in practice, which is likely why they perform similarly.

SI's ω\omega is obtained simply by summing the product of the gradient gg and the weight change Δθ\Delta\theta, both already computed in ordinary training, so no extra backpropagation is needed. Unlike EWC, there is also no separate stage for computing importance at the end of each task.

Experiments in the paper

The paper evaluates SI on three benchmarks. Its results are shown in figures, and the findings described in the text are as follows.

BenchmarkSetupResults
split MNISTMNIST split into 5 tasks: 0/1, 2/3, …, 8/9. MLP with two hidden layers of 256, per-task outputs (multi-head), ξ=10−3\xi = 10^{-3}, Adam (learning rate 10−310^{-3}), 10 epochsWithout the penalty (c=0c = 0), accuracy on the first two tasks fell to chance level after 5 tasks. With c=1c = 1, it dropped only slightly
permuted MNIST10 tasks, each with a different pixel permutation. MLP with two hidden layers of 2000, ξ=0.1\xi = 0.1, c=0.1c = 0.1, Adam, 20 epochsMaintained high accuracy after learning 10 tasks, only slightly below a network trained on all data at once. Comparable to EWC and far better than SGD or SGD with Dropout
split CIFAR-10/100CIFAR-10 followed by 5 tasks of 10 CIFAR-100 classes each. CNN with four convolutional and two fully connected layers, multi-head, Adam. Average of 5 runsExcept for the last task, validation accuracy was higher with the penalty on every task. It was also equal to or better than networks trained from scratch on each task alone (except CIFAR-10)

On permuted MNIST, the paper also examines the correlation of the weights' contributions ω\omega across tasks. Without the penalty, the contributions of second-layer weights became correlated across tasks (the same weights were reused and overwritten); with the penalty, there was almost no correlation, and each task used different weights.

On split CIFAR-10/100, the network with the penalty tended to do better on validation data than networks trained on each task alone, but worse on training data. The paper interprets this as retained knowledge from earlier tasks suppressing overfitting on new tasks with little data.

Practical considerations

The paper itself notes that SI's importance is affected by the noise of stochastic gradients (mini-batch gradients) and tends to be overestimated relative to its true value. As a result, although c=1c = 1 should in theory weight old and new tasks equally, in practice cc must be set below 1 (the paper uses c=0.1c = 0.1 for permuted MNIST and CIFAR). cc and ξ\xi need tuning for each dataset and model.

  • Task boundaries must be known: Ω\Omega and θ~\tilde\theta are updated at the end of each task, so it must be known where tasks switch.
  • Derivation assumes two tasks: The surrogate loss correctly approximates the original loss in the two-task case. That it also works with three or more tasks has been confirmed experimentally.
  • Use the actual update for the weight change Δθ\Delta\theta: ω\omega is the product of the gradient and the "amount actually moved." Even with optimizers that adapt step sizes, such as Adam, it can be computed using the actual update. The paper resets the optimizer state per task on split MNIST and keeps it on permuted MNIST.
  • What must be stored: For each weight, the reference weight θ~\tilde\theta, the importance Ω\Omega, the running ω\omega, and the weight at the start of the task. This uses several times the memory of the weights themselves, but no past data is stored.

Comparison with other continual learning methods

Continual learning methods can be compared by "what is kept from previous tasks, and how forgetting is prevented." The method closest to SI is EWC.

MethodWhat is keptWeight importance / mechanism against forgettingWhen importance is computedSuited to
SIWeights and weight importance Ω\OmegaLoss reduction ω\omega accumulated along the training path, divided by the squared distance movedDuring training (almost no extra computation)Past data cannot be stored; importance should be computed alongside training
EWCWeights and weight importance FFDiagonal of the Fisher information at the weights at the end of a taskAt the end of each task, computed separately with that task's dataPast data cannot be stored; task boundaries are known
LwFThe original networkPreserves previous-task outputs on new data via knowledge distillation(No importance used)Separate output layer per task; old and new task images are similar
iCaRLRepresentative images per classPreserves representations with exemplars and knowledge distillation; classifies by mean features(No importance used)A single classifier with growing classes; a few images can be stored
GEMSome examples from each taskCorrects the gradient direction so the loss on stored examples does not increase(No importance used)A few examples can be stored; each data point is seen only once

The paper notes that EWC and SI have the same penalty form, and the difference is whether importance is measured "at a single endpoint" or "over the entire training path." It also points out that computing EWC's Fisher information by definition requires summing over all output labels, which becomes expensive when there are many outputs. Choose by conditions: SI if past data cannot be stored and extra computation at the end of each task should be avoided, EWC if the abundance of implementations and analyses matters. If even a little past data can be stored, data-based methods such as GEM and iCaRL are also candidates.

PyTorch example

Show code
python
import torch
import torch.nn as nn
import torch.nn.functional as F

"""
Synaptic Intelligence (SI): accumulate per-weight contributions ω during training, update importance Ω at the end of each task
  ω_k ← ω_k − g_k Δθ_k             (Eq. (3) of the paper, summed over updates)
  Ω_k ← Ω_k + ω_k / (Δ_k² + ξ)    (Eq. (5))
  loss = L_μ + c Σ_k Ω_k (θ~_k − θ_k)²  (Eq. (4))
"""

c = 0.1   # penalty strength (value used for permuted MNIST in the paper)
xi = 0.1  # small value ξ keeping the denominator away from 0 (value used for permuted MNIST in the paper)


class SynapticIntelligence:
  def __init__(self, model):
    self.model = model
    self.params = {n: p for n, p in model.named_parameters() if p.requires_grad}
    self.omega = {n: torch.zeros_like(p) for n, p in self.params.items()}       # running ω
    self.Omega = {n: torch.zeros_like(p) for n, p in self.params.items()}       # importance Ω
    self.ref = {n: p.detach().clone() for n, p in self.params.items()}          # reference weights θ~
    self.start = {n: p.detach().clone() for n, p in self.params.items()}        # weights at the start of the task

  def penalty(self):
    return c * sum((self.Omega[n] * (self.ref[n] - p) ** 2).sum() for n, p in self.params.items())

  def train_step(self, optimizer, x, y):
    self.model.train()
    task_loss = F.cross_entropy(self.model(x), y)
    # ω uses the gradient g of the task loss L_μ
    grads = torch.autograd.grad(task_loss, list(self.params.values()), retain_graph=True)
    before = {n: p.detach().clone() for n, p in self.params.items()}

    loss = task_loss + self.penalty()
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

    with torch.no_grad():
      for (n, p), g in zip(self.params.items(), grads):
        self.omega[n] -= g * (p.detach() - before[n])  # ω_k ← ω_k − g_k Δθ_k (uses the amount actually moved)
    return task_loss.item()

  @torch.no_grad()
  def end_task(self):
    """Call after finishing a task: update Ω, save θ~, reset ω to 0"""
    for n, p in self.params.items():
      delta = p.detach() - self.start[n]                      # Δ_k^μ
      self.Omega[n] += self.omega[n] / (delta ** 2 + xi)
      self.ref[n] = p.detach().clone()
      self.start[n] = p.detach().clone()
      self.omega[n].zero_()


# Example usage:
#   model = nn.Sequential(nn.Flatten(), nn.Linear(784, 2000), nn.ReLU(), nn.Linear(2000, 2000), nn.ReLU(), nn.Linear(2000, 10))
#   si = SynapticIntelligence(model)
#   optimizer = torch.optim.Adam(model.parameters(), lr=1e-3, betas=(0.9, 0.999))
#   for task_loader in tasks:
#     for epoch in range(20):
#       for x, y in task_loader:
#         si.train_step(optimizer, x, y)
#     si.end_task()

FAQ

Q. Which should be used, EWC or SI?
A.

In the paper's permuted MNIST experiments, the two performed almost identically. SI accumulates importance during training, so no stage for computing the Fisher information at the end of each task is needed. EWC has a clearer meaning for its importance (the Fisher information) and more available implementations. Choosing based on computational effort and ease of use is reasonable.

Q. Can $\omega$ be negative?
A.

Yes. ωk\omega_k is the total "loss reduction due to that weight's movement," so it becomes negative if a weight's movement acted to increase the loss. It is also affected by the noise of mini-batch gradients. The paper notes that with stochastic gradients, importance tends to be overestimated relative to its true value.

Q. How should $c$ and $\xi$ be chosen?
A.

The paper uses c=1c = 1 and ξ=10−3\xi = 10^{-3} for split MNIST, c=0.1c = 0.1 (coarse grid search on validation data) and ξ=0.1\xi = 0.1 for permuted MNIST, and searches cc in the range 10−310^{-3} to 0.10.1 for split CIFAR-10/100. Because gradient noise inflates importance, start with values of cc smaller than 1.

References

  1. Zenke, F., Poole, B., & Ganguli, S. (2017). Continual Learning Through Synaptic Intelligence. Proceedings of the 34th International Conference on Machine Learning (ICML 2017), PMLR 70.
  2. Kirkpatrick, J., et al. (2017). Overcoming catastrophic forgetting in neural networks. Proceedings of the National Academy of Sciences, 114(13), 3521–3526.