PackNet

PackNet is a parameter-isolation-based continual learning method which prevents forgetting by learning binary masks of network parameters for each task. For the details, see the original paper.

Node-level Problems

class NCTaskILPackNetTrainer(model, scenario, optimizer_fn, loss_fn, device, **kwargs)[source]
afterInference(results, model, optimizer, _curr_batch, training_states, use_mask=True)[source]

The event function to execute some processes right after the inference step (for training). We recommend performing backpropagation in this event function.

In this function, PackNet weights gradients of parametrs according to ‘packnet_masks’. For this, Packnet additionally needs ‘use_mask’ parameter.

Parameters:
  • results (dict) – the returned dictionary from the event function inference.

  • model (torch.nn.Module) – the current trained model.

  • optimizer (torch.optim.Optimizer) – the current optimizer function.

  • curr_batch (object) – the data (or minibatch) for the current iteration.

  • curr_training_states (dict) – the dictionary containing the current training states.

  • use_mask (bool) – whether model masks weights of the model.

Returns:

A dictionary containing the information from the results.

inference(model, _curr_batch, training_states)[source]

The event function to execute inference step.

For task-IL, we need to additionally consider task information for the inference step.

Parameters:
  • model (torch.nn.Module) – the current trained model.

  • curr_batch (object) – the data (or minibatch) for the current iteration.

  • curr_training_states (dict) – the dictionary containing the current training states.

Returns:

A dictionary containing the inference results, such as prediction result and loss.

initTrainingStates(scenario, model, optimizer)[source]

The event function to initialize the dictionary for storing training states (i.e., intermedeiate results).

Parameters:
Returns:

Initialized training state (dict).

processBeforeTraining(task_id, curr_dataset, curr_model, curr_optimizer, curr_training_states)[source]

The event function to execute some processes before training.

PackNet masks the parameters of the model depending on the current magnitude of parameters in this function.

Parameters:
  • task_id (int) – the index of the current task

  • curr_dataset (object) – The dataset for the current task.

  • curr_model (torch.nn.Module) – the current trained model.

  • curr_optimizer (torch.optim.Optimizer) – the current optimizer function.

  • curr_training_states (dict) – the dictionary containing the current training states.

processEvalIteration(model, _curr_batch, use_mask=True)[source]

The event function to handle every evaluation iteration.

We need to extend the base function since the output format is slightly different from the base trainer.

PackNet additionally needs ‘use_mask’ parameter.

Parameters:
  • model (torch.nn.Module) – the current trained model.

  • curr_batch (object) – the data (or minibatch) for the current iteration.

  • use_mask (bool) – whether model masks weights of the model.

Returns:

A dictionary containing the outcomes (stats) during the evaluation iteration.

processTrainIteration(model, optimizer, _curr_batch, training_states, use_mask=True)[source]

The event function to handle every training iteration.

PackNet additionally needs ‘use_mask’ parameter.

Parameters:
  • model (torch.nn.Module) – the current trained model.

  • optimizer (torch.optim.Optimizer) – the current optimizer function.

  • curr_batch (object) – the data (or minibatch) for the current iteration.

  • curr_training_states (dict) – the dictionary containing the current training states.

  • use_mask (bool) – whether model masks weights of the model.

Returns:

A dictionary containing the outcomes (stats) during the training iteration.