PI-GNN

PI-GNN is a parameter-isolation-based continual learning method. For the details, see the original paper.

Node-level Problems

class NCClassILPIGNNMinibatchTrainer(model, scenario, optimizer_fn, loss_fn, device, **kwargs)[source]
afterInference(results, model, optimizer, _curr_batch, training_states)[source]

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

PI-GNN additionally computes the loss from the buffered nodes and applies it to backpropagation in parameter-isolation phase.

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.

Returns

A dictionary containing the information from the results.

beforeInference(model, optimizer, _curr_batch, training_states)[source]

The event function to execute some processes right before inference (for training).

Before training, PI-GNN needs to freeze parameters from the past tasks in parameter-isolation phase.

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.

initTrainingStates(scenario, model, optimizer)[source]

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

Parameters
  • scenario (begin.scenarios.common.BaseScenarioLoader) – the given ScenarioLoader to the trainer

  • model (torch.nn.Module) – the given model to the trainer

  • optmizer (torch.optim.Optimizer) – the optimizer generated from the given optimizer_fn

Returns

Initialized training state (dict).

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

The event function to execute some processes after training the current task.

PI-GNN samples the instances in the training dataset for the future tasks.

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.

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

PI-GNN requires extending the network before running each task.

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.

class NCClassILPIGNNTrainer(model, scenario, optimizer_fn, loss_fn, device, **kwargs)[source]
afterInference(results, model, optimizer, _curr_batch, training_states)[source]

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

PI-GNN additionally computes the loss from the buffered nodes and applies it to backpropagation in parameter-isolation phase.

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.

Returns

A dictionary containing the information from the results.

beforeInference(model, optimizer, _curr_batch, training_states)[source]

The event function to execute some processes right before inference (for training).

Before training, PI-GNN needs to freeze parameters from the past tasks in parameter-isolation phase.

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.

inference(model, _curr_batch, training_states)[source]

The event function to execute 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
  • scenario (begin.scenarios.common.BaseScenarioLoader) – the given ScenarioLoader to the trainer

  • model (torch.nn.Module) – the given model to the trainer

  • optmizer (torch.optim.Optimizer) – the optimizer generated from the given optimizer_fn

Returns

Initialized training state (dict).

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

The event function to execute some processes after training the current task.

PI-GNN samples the instances in the training dataset for the future tasks.

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.

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

PI-GNN requires extending the network before running each task.

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.

class NCDomainILPIGNNTrainer(model, scenario, optimizer_fn, loss_fn, device, **kwargs)[source]

This trainer has the same behavior as NCClassILPIGNNTrainer.

class NCTaskILPIGNNTrainer(model, scenario, optimizer_fn, loss_fn, device, **kwargs)[source]
afterInference(results, model, optimizer, _curr_batch, training_states)[source]

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

PI-GNN additionally computes the loss from the buffered nodes and applies it to backpropagation in parameter-isolation phase.

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.

Returns

A dictionary containing the information from the results.

beforeInference(model, optimizer, _curr_batch, training_states)[source]

The event function to execute some processes right before inference (for training).

Before training, PI-GNN needs to freeze parameters from the past tasks in parameter-isolation phase.

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.

inference(model, _curr_batch, training_states)[source]

The event function to execute 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
  • scenario (begin.scenarios.common.BaseScenarioLoader) – the given ScenarioLoader to the trainer

  • model (torch.nn.Module) – the given model to the trainer

  • optmizer (torch.optim.Optimizer) – the optimizer generated from the given optimizer_fn

Returns

Initialized training state (dict).

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

The event function to execute some processes after training the current task.

PI-GNN samples the instances in the training dataset for the future tasks.

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.

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

PI-GNN requires extending the network before running each task.

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)[source]

The event function to handle every evaluation iteration.

PI-GNN has to use different masks to evaluate the performance for each task.

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

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

  • task_id (int) – the id of a task

Returns

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

class NCTimeILPIGNNTrainer(model, scenario, optimizer_fn, loss_fn, device, **kwargs)[source]
afterInference(results, model, optimizer, _curr_batch, curr_training_states)[source]

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

PI-GNN additionally computes the loss from the buffered nodes and applies it to backpropagation.

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.

Returns

A dictionary containing the information from the results.

beforeInference(model, optimizer, _curr_batch, curr_training_states)[source]

The event function to execute some processes right before inference (for training).

Before training, PI-GNN needs to freeze parameters from the past tasks in parameter-isolation phase.

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.

processAfterEachIteration(curr_model, curr_optimizer, curr_training_states, curr_iter_results)[source]

The event function to execute some processes for every end of each epoch. Whether to continue training or not is determined by the return value of this function. If the returned value is False, the trainer stops training the current model in the current task. For PI-GNN, if the rectify phase ends, we need to move to the parameter-isolation phase.

Note

This function is called for every end of each epoch, and the event function processAfterTraining is called only when the learning on the current task has ended.

Parameters
  • 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.

  • curr_iter_results (dict) – the dictionary containing the training/validation results of the current epoch.

Returns

A boolean value. If the returned value is False, the trainer stops training the current model in the current task.

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

The event function to execute some processes after training the current task.

PI-GNN samples the instances in the training dataset for the future tasks.

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.

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

PI-GNN requires extending the network before running each task.

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.