Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkpointing with lightning module subclasses does not save subclass hyperparameters #119

Open
cnellington opened this issue Aug 18, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@cnellington
Copy link
Owner

To reproduce:

  contextualized_model = ContextualizedRegression(
      C.shape[-1], 
      X.shape[-1], 
      Y.shape[-1],
      **subtype_kwargs
  )
  train_dataset = contextualized_model.dataloader(C, X, Y, batch_size=10)
  checkpoint_callback = ModelCheckpoint(
      monitor="val_loss", 
  )
  trainer = RegressionTrainer(
      max_epochs=10, 
      callbacks=[checkpoint_callback]
  )
  trainer.fit(contextualized_model, train_dataset)
  contextualized_model = ContextualizedRegression.load_from_checkpoint(checkpoint_callback.best_model_path)

Workaround with torch state_dict:

contextualized_model = # instantiate contextualized_model with same kwargs
best_checkpoint = torch.load(checkpoint_callback.best_model_path)
contextualized_model.load_state_dict(best_checkpoint['state_dict'])
@cnellington cnellington added the bug Something isn't working label Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant