clarena.cul_algorithms.independent_unlearn

The submoduule in cul_algorithms for the vanilla unlearning algorithm for independent learning.

 1r"""
 2The submoduule in `cul_algorithms` for the vanilla unlearning algorithm for independent learning.
 3"""
 4
 5__all__ = ["IndependentUnlearn"]
 6
 7import logging
 8
 9from clarena.cl_algorithms import UnlearnableIndependent
10from clarena.cul_algorithms import CULAlgorithm
11
12# always get logger for built-in logging in each module
13pylogger = logging.getLogger(__name__)
14
15
16class IndependentUnlearn(CULAlgorithm):
17    r"""Vanilla unlearning algorithm for independent learning."""
18
19    def __init__(self, model: UnlearnableIndependent) -> None:
20        r"""
21        **Args:**
22        - **model** (`Independent`): the continual learning model (`CLAlgorithm` object which already contains the backbone and heads). It must be `Independent` algorithm.
23        """
24        super().__init__(model=model)
25
26    def unlearn(self) -> None:
27        r"""Unlearn the requested unlearning tasks after training `self.task_id`."""
28
29        for unlearning_task_id in self.unlearning_task_ids:
30
31            self.model.backbones[unlearning_task_id].load_state_dict(
32                self.model.original_backbone_state_dict
33            )
34            self.model.heads.get_head(unlearning_task_id).reset_parameters()
35
36            self.model.backbone_valid_task_ids.remove(unlearning_task_id)
class IndependentUnlearn(clarena.cul_algorithms.base.CULAlgorithm):
17class IndependentUnlearn(CULAlgorithm):
18    r"""Vanilla unlearning algorithm for independent learning."""
19
20    def __init__(self, model: UnlearnableIndependent) -> None:
21        r"""
22        **Args:**
23        - **model** (`Independent`): the continual learning model (`CLAlgorithm` object which already contains the backbone and heads). It must be `Independent` algorithm.
24        """
25        super().__init__(model=model)
26
27    def unlearn(self) -> None:
28        r"""Unlearn the requested unlearning tasks after training `self.task_id`."""
29
30        for unlearning_task_id in self.unlearning_task_ids:
31
32            self.model.backbones[unlearning_task_id].load_state_dict(
33                self.model.original_backbone_state_dict
34            )
35            self.model.heads.get_head(unlearning_task_id).reset_parameters()
36
37            self.model.backbone_valid_task_ids.remove(unlearning_task_id)

Vanilla unlearning algorithm for independent learning.

IndependentUnlearn(model: clarena.cl_algorithms.independent.UnlearnableIndependent)
20    def __init__(self, model: UnlearnableIndependent) -> None:
21        r"""
22        **Args:**
23        - **model** (`Independent`): the continual learning model (`CLAlgorithm` object which already contains the backbone and heads). It must be `Independent` algorithm.
24        """
25        super().__init__(model=model)

Args:

  • model (Independent): the continual learning model (CLAlgorithm object which already contains the backbone and heads). It must be Independent algorithm.
def unlearn(self) -> None:
27    def unlearn(self) -> None:
28        r"""Unlearn the requested unlearning tasks after training `self.task_id`."""
29
30        for unlearning_task_id in self.unlearning_task_ids:
31
32            self.model.backbones[unlearning_task_id].load_state_dict(
33                self.model.original_backbone_state_dict
34            )
35            self.model.heads.get_head(unlearning_task_id).reset_parameters()
36
37            self.model.backbone_valid_task_ids.remove(unlearning_task_id)

Unlearn the requested unlearning tasks after training self.task_id.