class_docstr: Gradient Episodic Memory Plugin.
  GEM projects the gradient on the current minibatch by using an external
  episodic memory of patterns from previous experiences. The gradient on
  the current minibatch is projected so that the dot product with all the
  reference gradients of previous tasks remains positive.
  This plugin does not use task identities.
docstr: Project gradient based on reference gradients
docstr_tok: ["Project","gradient","based","on","reference","gradients"]
code: def after_backward(self, strategy, **kwargs):
      """
      Project gradient based on reference gradients
      """
  
      if strategy.clock.train_exp_counter > 0:
          g = torch.cat(
              [
                  p.grad.flatten()
                  if p.grad is not None
                  else torch.zeros(p.numel(), device=strategy.device)
                  for p in strategy.model.parameters()
              ],
              dim=0,
          )
  
          to_project = (torch.mv(self.G, g) < 0).any()
      else:
          to_project = False
  
      if to_project:
          v_star = self.solve_quadprog(g).to(strategy.device)
  
          num_pars = 0  # reshape v_star into the parameter matrices
          for p in strategy.model.parameters():
              curr_pars = p.numel()
              if p.grad is not None:
                  p.grad.copy_(
                      v_star[num_pars : num_pars + curr_pars].view(
                          p.size()
                      )
                  )
              num_pars += curr_pars
  
          assert (
              num_pars == v_star.numel()
          ), "Error in projecting gradient"
  
file_path: avalanche/avalanche/training/plugins/gem.py
imports: from typing import Dict
  import numpy
  import quadprog
  import torch
  from torch import Tensor
  from torch.utils.data import DataLoader
  from avalanche.models import avalanche_forward
  from avalanche.training.plugins.strategy_plugin import SupervisedPlugin
label_desc: Use image node_id 3 for calling the GEMPlugin obj's underlying member method code with example usage: obj.after_backward(strategy) without return types