Logo
1.0.0

Get Started

  • Install and Setup
  • Tutorial
  • Load Custom Scenarios

Datasets

  • Datasets for Node-Level Problems
  • Datasets for Link-Level Problems
  • Datasets for Graph-Level Problems

Scenarios

  • Common framework
  • Node-level problems
  • Link-level problems
  • Graph-level problems

Trainer

  • Common framework
  • Node-level problems
  • Link-level problems
    • LCTrainer
      • LCTrainer.afterInference()
      • LCTrainer.beforeInference()
      • LCTrainer.inference()
      • LCTrainer.initTrainingStates()
      • LCTrainer.predictionFormat()
      • LCTrainer.prepareLoader()
      • LCTrainer.processAfterEachIteration()
      • LCTrainer.processAfterTraining()
      • LCTrainer.processBeforeTraining()
      • LCTrainer.processEvalIteration()
      • LCTrainer.processTrainIteration()
      • LCTrainer.processTrainingLogs()
      • LCTrainer.run()
    • LPTrainer
      • LPTrainer.afterInference()
      • LPTrainer.beforeInference()
      • LPTrainer.inference()
      • LPTrainer.initTrainingStates()
      • LPTrainer.predictionFormat()
      • LPTrainer.prepareLoader()
      • LPTrainer.processAfterEachIteration()
      • LPTrainer.processAfterTraining()
      • LPTrainer.processBeforeTraining()
      • LPTrainer.processEvalIteration()
      • LPTrainer.processTrainIteration()
      • LPTrainer.processTrainingLogs()
      • LPTrainer.run()
  • Graph-level problems

Continual Learning Methods

  • Bare Model
  • LwF
  • EWC
  • MAS
  • GEM
  • TWP
  • ER-GNN
  • ContinualGNN
  • PackNet
  • Piggyback
  • HAT

Evaluator

  • Basic Performance Metrics
  • Metrics for CL

Utils

  • AdaptiveLinear
BeGin
  • Link-level problems
  • View page source

Link-level problems

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

The trainer for handling link classification (LC).

Base:

BaseTrainer

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.

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).

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).

predictionFormat(results)[source]

The helper function for formatting the prediction results before feeding the results to evaluator.

Parameters:

results (dict) – the dictionary containing the prediction results.

prepareLoader(_curr_dataset, curr_training_states)[source]

The event function to generate dataloaders from the given dataset for the current task.

Parameters:
  • curr_dataset (object) – The dataset for the current task. Its type is dgl.graph for node-level and link-level problem, and dgl.data.DGLDataset for graph-level problem.

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

Returns:

A tuple containing three dataloaders. The trainer considers the first dataloader, second dataloader, and third dataloader as dataloaders for training, validation, and test, respectively.

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.

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.

Note

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

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]

The event function to execute some processes before training.

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.

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

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

Returns:

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

processTrainIteration(model, optimizer, _curr_batch, training_states)[source]

The event function to handle every training iteration.

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.

Returns:

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

processTrainingLogs(task_id, epoch_cnt, val_metric_result, train_stats, val_stats)[source]

(Optional) The event function to output the training logs.

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

  • epoch_cnt (int) – the index of the current epoch

  • val_metric_result (object) – the validation performance computed by the evaluator

  • train_stats (dict) – the reduced dictionary containg the final training outcomes.

  • val_stats (dict) – the reduced dictionary containg the final validation outcomes.

run(epoch_per_task=1)[source]

Run the overall process of graph continual learning optimization.

Parameters:

epoch_per_task (int) – maximum number of training epochs for each task

Returns:

The base trainer returns the dictionary containing the evaluation results on validation and test dataset. And each trainer for specific problem processes the results and outputs the matrix-shaped results for performances and the final evaluation metrics, such as AP, AF, INT, and FWT.

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

The trainer for handling link prediction (LP).

Base:

BaseTrainer

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.

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).

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).

predictionFormat(results)[source]

The helper function for formatting the prediction results before feeding the results to evaluator.

Parameters:

results (dict) – the dictionary containing the prediction results.

prepareLoader(curr_dataset, curr_training_states)[source]

The event function to generate dataloaders from the given dataset for the current task.

Parameters:
  • curr_dataset (object) – The dataset for the current task. Its type is dgl.graph for node-level and link-level problem, and dgl.data.DGLDataset for graph-level problem.

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

Returns:

A tuple containing three dataloaders. The trainer considers the first dataloader, second dataloader, and third dataloader as dataloaders for training, validation, and test, respectively.

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.

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.

Note

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

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]

The event function to execute some processes before training.

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.

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

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

Returns:

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

processTrainIteration(model, optimizer, _curr_batch, training_states)[source]

The event function to handle every training iteration.

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.

Returns:

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

processTrainingLogs(task_id, epoch_cnt, val_metric_result, train_stats, val_stats)[source]

(Optional) The event function to output the training logs.

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

  • epoch_cnt (int) – the index of the current epoch

  • val_metric_result (object) – the validation performance computed by the evaluator

  • train_stats (dict) – the reduced dictionary containg the final training outcomes.

  • val_stats (dict) – the reduced dictionary containg the final validation outcomes.

run(epoch_per_task=1)[source]

Run the overall process of graph continual learning optimization.

Parameters:

epoch_per_task (int) – maximum number of training epochs for each task

Returns:

The base trainer returns the dictionary containing the evaluation results on validation and test dataset. And each trainer for specific problem processes the results and outputs the matrix-shaped results for performances and the final evaluation metrics, such as AP, AF, INT, and FWT.

Previous Next

© Copyright Anonymous.

Built with Sphinx using a theme provided by Read the Docs.