Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions avalanche/training/plugins/ewc.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def after_training_exp(self, strategy, **kwargs):
strategy.experience.dataset,
strategy.device,
strategy.train_mb_size,
kwargs["num_workers"],
)
self.update_importances(importances, exp_counter)
self.saved_params[exp_counter] = copy_params_dict(strategy.model)
Expand All @@ -129,7 +130,8 @@ def after_training_exp(self, strategy, **kwargs):
del self.saved_params[exp_counter - 1]

def compute_importances(
self, model, criterion, optimizer, dataset, device, batch_size
self, model, criterion, optimizer, dataset, device, batch_size,
num_workers
):
"""
Compute EWC importance matrix for each parameter
Expand All @@ -152,12 +154,15 @@ def compute_importances(

# list of list
importances = zerolike_params_dict(model)

collate_fn = (
dataset.collate_fn if hasattr(dataset, "collate_fn") else None
)
dataloader = DataLoader(
dataset, batch_size=batch_size, collate_fn=collate_fn
dataset, batch_size=batch_size, collate_fn=collate_fn,
num_workers=num_workers
)

for i, batch in enumerate(dataloader):
# get only input, target and task_id from the batch
x, y, task_labels = batch[0], batch[1], batch[-1]
Expand Down