TypeError: __init__() got an unexpected keyword argument 'checkpoint_callback'

I had a well-functioning notebook that run all the code perfectly up until this point. I didn’t change anything, but suddenly I got an error when executing the training process:

trainer = pl.Trainer(
  logger=logger,
  checkpoint_callback=checkpoint_callback,
  callbacks=[early_stopping_callback],
  max_epochs=N_EPOCHS,
  gpus=1,
  progress_bar_refresh_rate=30
)

Error:

TypeError                                 Traceback (most recent call last)
<ipython-input-48-3b8eeab1e1d5> in <module>()
      5   max_epochs=N_EPOCHS,
      6   gpus=1,
----> 7   progress_bar_refresh_rate=30
      8 )

/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/argparse.py in insert_env_defaults(self, *args, **kwargs)
    343 
    344         # all args were already moved to kwargs
--> 345         return fn(self, **kwargs)
    346 
    347     return cast(_T, insert_env_defaults)

TypeError: __init__() got an unexpected keyword argument 'checkpoint_callback'

I can’t figure out what is wrong. Can anyone help me?

A link to the notebook with full code: Google Colab

If you’ve restarted and reinstalled pytorch-lightning, it’s possible you’ve updated the library to a newer version.

Take a look at pytorch-lightning’s Trainer API. The checkpoint_callback argument is now a class property:

The first ModelCheckpoint callback in the Trainer.callbacks list, or None if it doesn’t exist.

Try appending the checkpoint_callback to the list passed into the callbacks argument, like so:

trainer = pl.Trainer(
  logger=logger,
  callbacks=[early_stopping_callback, checkpoint_callback],
  max_epochs=N_EPOCHS,
  gpus=1,
  progress_bar_refresh_rate=30
)

Then, if needed, you can retrieve the callback with checkpoint_callback = trainer.checkpoint_callback.

1 Like

I wasn’t aware of the change with the update! Thank you. Your suggestion did fix the issue with checkpoint_callback but a new problem occurred referring to the same line:

trainer = pl.Trainer(
  logger=logger,
  callbacks=[early_stopping_callback, checkpoint_callback],
  max_epochs=N_EPOCHS,
  gpus=1,
  progress_bar_refresh_rate=30
)

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-05e0ea4feadc> in <module>()
      4   max_epochs=N_EPOCHS,
      5   gpus=1,
----> 6   progress_bar_refresh_rate=30
      7 )

/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/argparse.py in insert_env_defaults(self, *args, **kwargs)
    343 
    344         # all args were already moved to kwargs
--> 345         return fn(self, **kwargs)
    346 
    347     return cast(_T, insert_env_defaults)

TypeError: __init__() got an unexpected keyword argument 'progress_bar_refresh_rate'

I realized that I don’t even need the progress_bar_refresh_rate=30 line.

How do remove this though? Isn’t it stored in a pytorch-lightning file that we can’t access from Colab?