Pytorch-lightning: Callback derived class is called without module argument

Created on 9 Mar 2020  路  1Comment  路  Source: PyTorchLightning/pytorch-lightning

馃悰 Bug

The class Callback(abc.ABC) API expects trainer and sometimes pl_module to be supplied. E.g.:

def on_init_start(self, trainer):
    pass

See the definition

However, the caller TrainerCallbackHookMixin calls the callback methods without the module argument. E.g.:

for callback in self.callbacks:
     callback.on_init_start(self)  # self is Trainer / TrainerCallbackHookMixin

See the calls

To Reproduce

Follow the documentation for callbacks

and expect similar output

Traceback (most recent call last):
  File "./train_encdec_pl.py", line 33, in <module>
    callbacks=[SavePredictionCB])
  File "/workspace/oplatek/code/demo/venv/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 239, in __init__
    self.on_init_start()
  File "/workspace/oplatek/code/demo/venv/lib/python3.6/site-packages/pytorch_lightning/trainer/callback_hook.py", line 18, in on_init_start
    callback.on_init_start(self)
TypeError: on_init_start() missing 1 required positional argument: 'trainer'
bug / fix help wanted

Most helpful comment

The issue is incorrectly described i.e. non-existant:

The problem was in my setup:

I used

trainer = Trainer(callbacks=[SavePredictionCB],  ....)   # class instead of an instance

instead of

trainer = Trainer(callbacks=[SavePredictionCB()],  ...)

>All comments

The issue is incorrectly described i.e. non-existant:

The problem was in my setup:

I used

trainer = Trainer(callbacks=[SavePredictionCB],  ....)   # class instead of an instance

instead of

trainer = Trainer(callbacks=[SavePredictionCB()],  ...)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

monney picture monney  路  3Comments

edenlightning picture edenlightning  路  3Comments

baeseongsu picture baeseongsu  路  3Comments

mmsamiei picture mmsamiei  路  3Comments

williamFalcon picture williamFalcon  路  3Comments