Pytorch-lightning: Inherit from Callback throws missing Trainer argument

Created on 16 Oct 2020  路  5Comments  路  Source: PyTorchLightning/pytorch-lightning

馃悰 Bug


The PL 1.0.x update has removed the trainer argument from TrainerCallbackHookMixin when calling e.g. callback.on_init_start(self). However, Callback has not been updated for this change. This results in a missing argument trainer.

Please reproduce using the BoringModel and post here


BoringModel colab: https://colab.research.google.com/drive/1i38oUFbnkgmgamMk6Jc4zpc9BrF31ZfE?usp=sharing

To Reproduce


BoringModel

Expected behavior


Not throw an error when using class MyPrintingCallback(Callback)

Actual behavior

TypeError                                 Traceback (most recent call last)

<ipython-input-13-1f9f6fbe4f6c> in <module>()
----> 1 test_x(tmpdir)

3 frames

/usr/local/lib/python3.6/dist-packages/pytorch_lightning/trainer/callback_hook.py in on_init_start(self)
     40         """Called when the trainer initialization begins, model has not yet been set."""
     41         for callback in self.callbacks:
---> 42             callback.on_init_start(self)
     43 
     44     def on_init_end(self):

TypeError: on_init_start() missing 1 required positional argument: 'trainer'

Environment

  • PyTorch Version (e.g., 1.0): 1.0.2
  • OS (e.g., Linux): Google Colab

Additional context

bug / fix help wanted

All 5 comments

possible duplicate of #3813? Not sure if rooted entirely in same issue

Sorry, it seems I didn't save the modifications to show the bug. I was not allowed to save, because I didn't copy the notebook. The link in the original post has been updated.

@NumesSanguis you need to call your custom callback class

        callbacks=[MyPrintingCallback()] # needs ()

@ydcjeff is right, his fix does the trick

Yup, can confirm that this was the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DavidRuhe picture DavidRuhe  路  3Comments

remisphere picture remisphere  路  3Comments

jcreinhold picture jcreinhold  路  3Comments

edenlightning picture edenlightning  路  3Comments

srush picture srush  路  3Comments