I’m having a bit of trouble using callbacks/ implementing them so was hoping someone here could help. Basically trying to add L1loss, which looks like this:
class L1Loss(LearnerCallback):
def __init__(self, learn, lr=1e-2):
super().__init__(learn)
self.l1_lr = lr
def on_backward_end(self, **kwargss):
breakpoint()
optimizer = self.learn.opt.opt
for group in optimizer.param_groups():
for param in group['params']:
sign = param.data / (torch.abs(param.data) + 1e-9)
param.data = param.data - self.l1_lr * sign
However when I try to fit the function I get the error TypeError: on_train_begin() missing 1 required positional argument: 'self'
.
My learning bit looks like follows:
learner = Learner(db,
model,
loss_func=F.mse_loss,
wd=0,
callbacks=[L1Loss])
learner.fit(20)
A minimal working example with toy data can be found here in this colab notebook.
Am I supposed to use the @dataclass
decorator? Any thoughts would be highly appreciated.