class_docstr: Implements the DER and the DER++ Strategy,
  from the "Dark Experience For General Continual Learning"
  paper, Buzzega et. al, https://arxiv.org/abs/2004.07211
class_docstr_tok: ["Implements","the","DER","and","the","DER++","Strategy",",","from","the","``","Dark","Experience","For","General","Continual","Learning","''","paper",",","Buzzega","et",".","al",",","https",":","\/\/arxiv.org\/abs\/2004.07211"]
docstr: :param model: PyTorch model.
  :param optimizer: PyTorch optimizer.
  :param criterion: loss function.
  :param mem_size: int       : Fixed memory size
  :param batch_size_mem: int : Size of the batch sampled from the buffer
  :param alpha: float : Hyperparameter weighting the MSE loss
  :param beta: float : Hyperparameter weighting the CE loss,
                       when more than 0, DER++ is used instead of DER
  :param transforms: Callable: Transformations to use for
                               both the dataset and the buffer data, on
                               top of already existing
                               test transformations.
                               If any supplementary transformations
                               are applied to the
                               input data, it will be
                               overwritten by this argument
  :param train_mb_size: mini-batch size for training.
  :param train_passes: number of training passes.
  :param eval_mb_size: mini-batch size for eval.
  :param device: PyTorch device where the model will be allocated.
  :param plugins: (optional) list of StrategyPlugins.
  :param evaluator: (optional) instance of EvaluationPlugin for logging
      and metric computations. None to remove logging.
  :param eval_every: the frequency of the calls to `eval` inside the
      training loop. -1 disables the evaluation. 0 means `eval` is called
      only at the end of the learning experience. Values >0 mean that
      `eval` is called every `eval_every` experiences and at the end of
      the learning experience.
  :param peval_mode: one of {'experience', 'iteration'}. Decides whether
      the periodic evaluation during training should execute every
      `eval_every` experience or iterations (Default='experience').
docstr_tok: [":","param","model",":","PyTorch","model",".",":","param","optimizer",":","PyTorch","optimizer",".",":","param","criterion",":","loss","function",".",":","param","mem_size",":","int",":","Fixed","memory","size",":","param","batch_size_mem",":","int",":","Size","of","the","batch","sampled","from","the","buffer",":","param","alpha",":","float",":","Hyperparameter","weighting","the","MSE","loss",":","param","beta",":","float",":","Hyperparameter","weighting","the","CE","loss",",","when","more","than","0",",","DER++","is","used","instead","of","DER",":","param","transforms",":","Callable",":","Transformations","to","use","for","both","the","dataset","and","the","buffer","data",",","on","top","of","already","existing","test","transformations",".","If","any","supplementary","transformations","are","applied","to","the","input","data",",","it","will","be","overwritten","by","this","argument",":","param","train_mb_size",":","mini-batch","size","for","training",".",":","param","train_passes",":","number","of","training","passes",".",":","param","eval_mb_size",":","mini-batch","size","for","eval",".",":","param","device",":","PyTorch","device","where","the","model","will","be","allocated",".",":","param","plugins",":","(","optional",")","list","of","StrategyPlugins",".",":","param","evaluator",":","(","optional",")","instance","of","EvaluationPlugin","for","logging","and","metric","computations",".","None","to","remove","logging",".",":","param","eval_every",":","the","frequency","of","the","calls","to","`","eval","`","inside","the","training","loop",".","-1","disables","the","evaluation",".","0","means","`","eval","`","is","called","only","at","the","end","of","the","learning","experience",".","Values",">","0","mean","that","`","eval","`","is","called","every","`","eval_every","`","experiences","and","at","the","end","of","the","learning","experience",".",":","param","peval_mode",":","one","of","{","'experience","'",",","'iteration","'","}",".","Decides","whether","the","periodic","evaluation","during","training","should","execute","every","`","eval_every","`","experience","or","iterations","(","Default='experience","'",")","."]
code: def __init__(
      self,
      model: Module,
      optimizer: Optimizer,
      criterion=CrossEntropyLoss(),
      mem_size: int = 200,
      batch_size_mem: Optional[int] = None,
      alpha: float = 0.1,
      beta: float = 0.5,
      train_mb_size: int = 1,
      train_epochs: int = 1,
      eval_mb_size: Optional[int] = 1,
      device: Union[str, torch.device] = "cpu",
      plugins: Optional[List[SupervisedPlugin]] = None,
      evaluator: Union[
          EvaluationPlugin, Callable[[], EvaluationPlugin]
      ] = default_evaluator,
      eval_every=-1,
      peval_mode="epoch",
  ):
      """
      :param model: PyTorch model.
      :param optimizer: PyTorch optimizer.
      :param criterion: loss function.
      :param mem_size: int       : Fixed memory size
      :param batch_size_mem: int : Size of the batch sampled from the buffer
      :param alpha: float : Hyperparameter weighting the MSE loss
      :param beta: float : Hyperparameter weighting the CE loss,
                           when more than 0, DER++ is used instead of DER
      :param transforms: Callable: Transformations to use for
                                   both the dataset and the buffer data, on
                                   top of already existing
                                   test transformations.
                                   If any supplementary transformations
                                   are applied to the
                                   input data, it will be
                                   overwritten by this argument
      :param train_mb_size: mini-batch size for training.
      :param train_passes: number of training passes.
      :param eval_mb_size: mini-batch size for eval.
      :param device: PyTorch device where the model will be allocated.
      :param plugins: (optional) list of StrategyPlugins.
      :param evaluator: (optional) instance of EvaluationPlugin for logging
          and metric computations. None to remove logging.
      :param eval_every: the frequency of the calls to `eval` inside the
          training loop. -1 disables the evaluation. 0 means `eval` is called
          only at the end of the learning experience. Values >0 mean that
          `eval` is called every `eval_every` experiences and at the end of
          the learning experience.
      :param peval_mode: one of {'experience', 'iteration'}. Decides whether
          the periodic evaluation during training should execute every
          `eval_every` experience or iterations (Default='experience').
      """
      super().__init__(
          model=model,
          optimizer=optimizer,
          criterion=criterion,
          train_mb_size=train_mb_size,
          train_epochs=train_epochs,
          eval_mb_size=eval_mb_size,
          device=device,
          plugins=plugins,
          evaluator=evaluator,
          eval_every=eval_every,
          peval_mode=peval_mode,
      )
      if batch_size_mem is None:
          self.batch_size_mem = train_mb_size
      else:
          self.batch_size_mem = batch_size_mem
      self.mem_size = mem_size
      self.storage_policy = ClassBalancedBufferWithLogits(
          self.mem_size, adaptive_size=True
      )
      self.replay_loader = None
      self.alpha = alpha
      self.beta = beta
  
imports: from collections import defaultdict
  from typing import Callable, Dict, List, Optional, Sequence, Set, SupportsInt, Union
  import torch
  import torch.nn.functional
  from torch.nn import CrossEntropyLoss, Module
  from torch.optim import Optimizer
  from avalanche.benchmarks.utils import make_avalanche_dataset
  from avalanche.benchmarks.utils.data import AvalancheDataset
  from avalanche.benchmarks.utils.data_attribute import TensorDataAttribute
  from avalanche.training.utils import cycle
  from avalanche.core import SupervisedPlugin
  from avalanche.training.plugins.evaluation import EvaluationPlugin, default_evaluator
  from avalanche.training.storage_policy import BalancedExemplarsBuffer, ReservoirSamplingBuffer
  from avalanche.training.templates import SupervisedTemplate
label_desc: Use image node_id 1 to create a new DER object from inherited base classes: SupervisedTemplate with example: obj = DER(model, optimizer, criterion, mem_size, batch_size_mem, alpha, beta, train_mb_size, train_epochs, eval_mb_size, device, plugins, evaluator, eval_every, peval_mode)