avalanche.training.plugins.RARPlugin

class avalanche.training.plugins.RARPlugin(batch_size_mem: int, mem_size: int = 200, opt_lr: float = 0.1, name_ext_layer: str | None = None, use_adversarial_replay: bool = True, beta_coef: float = 0.4, decay_factor_fgsm: float = 1.0, epsilon_fgsm: float = 0.0314, iter_fgsm: int = 2, storage_policy: ReservoirSamplingBuffer | None = None)[source]

Retrospective Adversarial Replay for Continual Learning https://openreview.net/forum?id=XEoih0EwCwL Continual learning is an emerging research challenge in machine learning that addresses the problem where models quickly fit the most recently trained-on data and are prone to catastrophic forgetting due to distribution shifts — it does this by maintaining a small historical replay buffer in replay-based methods. To avoid these problems, this paper proposes a method, ``Retrospective Adversarial Replay (RAR)’’, that synthesizes adversarial samples near the forgetting boundary. RAR perturbs a buffered sample towards its nearest neighbor drawn from the current task in a latent representation space. By replaying such samples, we are able to refine the boundary between previous and current tasks, hence combating forgetting and reducing bias towards the current task. To mitigate the severity of a small replay buffer, we develop a novel MixUp-based strategy to increase replay variation by replaying mixed augmentations. Combined with RAR, this achieves a holistic framework that helps to alleviate catastrophic forgetting. We show that this excels on broadly-used benchmarks and outperforms other continual learning baselines especially when only a small buffer is used. We conduct a thorough ablation study over each key component as well as a hyperparameter sensitivity analysis to demonstrate the effectiveness and robustness of RAR.

__init__(batch_size_mem: int, mem_size: int = 200, opt_lr: float = 0.1, name_ext_layer: str | None = None, use_adversarial_replay: bool = True, beta_coef: float = 0.4, decay_factor_fgsm: float = 1.0, epsilon_fgsm: float = 0.0314, iter_fgsm: int = 2, storage_policy: ReservoirSamplingBuffer | None = None)[source]
Parameters:
  • batch_size_mem – Size of the batch sampled from the bigger buffer

  • mem_size – Fixed memory size

  • opt_lr – Learning rate of the internal optimizer

  • name_ext_layer – Name of the layer to extract features

  • use_adversarial_replay – Boolean to use or not RAR

  • beta_coef – float: coef between RAR and Buffer

  • decay_factor_fgsm – Decay factor of FGSM

  • epsilon_fgsm – Epsilon for FGSM

  • iter_fgsm – Number of iterations of FGSM

  • storage_policy – Storage Policy used for the buffer

Methods

__init__(batch_size_mem[, mem_size, opt_lr, ...])

param batch_size_mem:

Size of the batch sampled from

after_backward(strategy, *args, **kwargs)

Called after criterion.backward() by the BaseTemplate.

after_eval(strategy, *args, **kwargs)

Called after eval by the BaseTemplate.

after_eval_dataset_adaptation(strategy, ...)

Called after eval_dataset_adaptation by the BaseTemplate.

after_eval_exp(strategy, *args, **kwargs)

Called after eval_exp by the BaseTemplate.

after_eval_forward(strategy, *args, **kwargs)

Called after model.forward() by the BaseTemplate.

after_eval_iteration(strategy, *args, **kwargs)

Called after the end of an iteration by the BaseTemplate.

after_forward(strategy, *args, **kwargs)

Called after model.forward() by the BaseTemplate.

after_train_dataset_adaptation(strategy, ...)

Called after train_dataset_adapatation by the BaseTemplate.

after_training(strategy, *args, **kwargs)

Called after train by the BaseTemplate.

after_training_epoch(strategy, *args, **kwargs)

Called after train_epoch by the BaseTemplate.

after_training_exp(strategy, **kwargs)

Called after train_exp by the BaseTemplate.

after_training_iteration(strategy, *args, ...)

Called after the end of a training iteration by the BaseTemplate.

after_update(strategy, *args, **kwargs)

Called after optimizer.update() by the BaseTemplate.

before_backward(strategy, **kwargs)

Before the backward function in the training process.

before_eval(strategy, *args, **kwargs)

Called before eval by the BaseTemplate.

before_eval_dataset_adaptation(strategy, ...)

Called before eval_dataset_adaptation by the BaseTemplate.

before_eval_exp(strategy, *args, **kwargs)

Called before eval_exp by the BaseTemplate.

before_eval_forward(strategy, *args, **kwargs)

Called before model.forward() by the BaseTemplate.

before_eval_iteration(strategy, *args, **kwargs)

Called before the start of a training iteration by the BaseTemplate.

before_forward(strategy, *args, **kwargs)

Called before model.forward() by the BaseTemplate.

before_train_dataset_adaptation(strategy, ...)

Called before train_dataset_adapatation by the BaseTemplate.

before_training(strategy, *args, **kwargs)

Called before train by the BaseTemplate.

before_training_epoch(strategy, *args, **kwargs)

Called before train_epoch by the BaseTemplate.

before_training_exp(strategy[, num_workers, ...])

Dataloader to build batches containing examples from both memories and the training dataset

before_training_iteration(strategy, *args, ...)

Called before the start of a training iteration by the BaseTemplate.

before_update(strategy, *args, **kwargs)

Called before optimizer.update() by the BaseTemplate.

get_buffer_batch()

Auxiliary function to obtained the next batch

mifgsm_attack(input, data_grad)

FGSM - This function generate the perturbation to the input.

Attributes

supports_distributed

A flag describing whether this plugin supports distributed training.