class_docstr: Learning Without Forgetting.
  
  The method applies knowledge distilllation to mitigate forgetting.
  The teacher is the model checkpoint after the last experience.
docstr: Compute weighted distillation loss.
docstr_tok: ["Compute","weighted","distillation","loss","."]
code: def _lwf_penalty(self, out, x, curr_model):
      """
      Compute weighted distillation loss.
      """
      if self.prev_model is None:
          return 0
      else:
          if isinstance(self.prev_model, MultiTaskModule):
              # output from previous output heads.
              with torch.no_grad():
                  y_prev = avalanche_forward(self.prev_model, x, None)
              y_prev = {k: v for k, v in y_prev.items()}
              # in a multitask scenario we need to compute the output
              # from all the heads, so we need to call forward again.
              # TODO: can we avoid this?
              y_curr = avalanche_forward(curr_model, x, None)
              y_curr = {k: v for k, v in y_curr.items()}
          else:  # no task labels. Single task LwF
              with torch.no_grad():
                  y_prev = {0: self.prev_model(x)}
              y_curr = {0: out}
  
          dist_loss = 0
          for task_id in y_prev.keys():
              # compute kd only for previous heads and only for seen units.
              if task_id in self.prev_classes_by_task:
                  yp = y_prev[task_id]
                  yc = y_curr[task_id]
                  au = self.prev_classes_by_task[task_id]
                  dist_loss += self._distillation_loss(yc, yp, au)
          return dist_loss
  
imports: import copy
  from collections import defaultdict
  from typing import List
  import torch
  import torch.nn.functional
  from avalanche.models import MultiTaskModule, avalanche_forward
label_desc: Use image node_id 3 for calling the LearningWithoutForgetting obj's underlying member method code with example usage: obj._lwf_penalty(out, x, curr_model) and returns: int, dist_loss