Search code examples
pythonerror-handlingnlppytorchpytorch-lightning

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


I'm getting this error message:

TypeError                                 Traceback (most recent call last)
<ipython-input-41-2892cdd4e738> in <module>()
      5   max_epochs=N_EPOCHS,
      6   gpus=1, #GPU
----> 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'

... when I run this chunk:

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

The 'checkpoint_callback' is defined like this:

checkpoint_callback = ModelCheckpoint(
  dirpath="checkpoints",
  filename="best-checkpoint",
  save_top_k=1,
  verbose=True,
  monitor="val_loss",
  mode="min"
)

I can't figure out what's causing the error - can anyone help me?

View full source code here: https://colab.research.google.com/drive/1hT7PDVb0oGSpLejMGFBMWzRKTPwsSwwS?usp=sharing


Solution

  • As I am looking into pytorch_lightning github, I do not see checkpoint_callback variable in init (https://github.com/Lightning-AI/lightning/blob/master/src/pytorch_lightning/trainer/trainer.py)

    Are you sure thats how it's called? What do you want to achieve by passing this checkpoint_callback?

    //edit: I think you just have to append checkpoint_callback to callbacks list