unlearning done
This commit is contained in:
@@ -16,12 +16,20 @@ class Strategy:
|
||||
self.log_file = Path(f"reports/{self.strategy_name}/metrics.txt")
|
||||
Util._initialize_log_file(log_file= self.log_file)
|
||||
|
||||
def apply(self, model: nn.Module, forget_loader: DataLoader, retain_loader: DataLoader) -> nn.Module:
|
||||
def set_target_class(self, target_class_index: int):
|
||||
"""Dynamically switch the unlearning target without retraining."""
|
||||
self.target_class_index = target_class_index
|
||||
|
||||
|
||||
def apply(self, model: nn.Module, dataset) -> nn.Module:
|
||||
"""
|
||||
Wraps the unlearning execution with automated timing and strategy-specific logging.
|
||||
DO NOT override this method in subclasses. Override _run instead.
|
||||
"""
|
||||
start_time = time.perf_counter()
|
||||
|
||||
|
||||
retain_loader, forget_loader = self._split_data(dataset)
|
||||
|
||||
# Execute core unlearning logic
|
||||
processed_model = self._run(model, forget_loader, retain_loader)
|
||||
@@ -41,4 +49,12 @@ class Strategy:
|
||||
|
||||
def _run(self, model: nn.Module, forget_loader: DataLoader, retain_loader: DataLoader) -> nn.Module:
|
||||
"""Subclasses implement their core unlearning logic here."""
|
||||
raise NotImplementedError
|
||||
raise NotImplementedError
|
||||
|
||||
'''
|
||||
different strategies split data in to different partitions differently.
|
||||
So a strategy will implement its own and since this part is startegy specific.
|
||||
not all should compute it the same.
|
||||
'''
|
||||
def _split_data(self,dataset):
|
||||
pass
|
||||
Reference in New Issue
Block a user