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

Add trainer.predict(ckpt_path) #7430

Merged
merged 7 commits into from
May 12, 2021
Merged

Add trainer.predict(ckpt_path) #7430

merged 7 commits into from
May 12, 2021

Conversation

carmocca
Copy link
Contributor

@carmocca carmocca commented May 7, 2021

What does this PR do?

Fixes #7226 (comment)

Also fixes a bug where predict_loop.on_trainer_init() was never called.

Question

Should this go into 1.3.x? It could be considered a bug (it's inconsistent with the rest of the trainer fns)

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

@carmocca carmocca added the feature Is an improvement or enhancement label May 7, 2021
@carmocca carmocca self-assigned this May 7, 2021
@codecov
Copy link

codecov bot commented May 7, 2021

Codecov Report

Merging #7430 (1861ed6) into master (8cdbd03) will decrease coverage by 0%.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #7430   +/-   ##
======================================
- Coverage      92%     92%   -0%     
======================================
  Files         199     199           
  Lines       13067   13072    +5     
======================================
- Hits        11997   11990    -7     
- Misses       1070    1082   +12     

Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch !

# links data to the trainer
self.data_connector.attach_data(model, predict_dataloaders=dataloaders, datamodule=datamodule)

if not model_provided:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use model directly. No need for model_provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? We use it also in validate and test

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tchaton it canot as you do the mapping after it... I quess

CHANGELOG.md Outdated Show resolved Hide resolved
pytorch_lightning/trainer/trainer.py Show resolved Hide resolved
pytorch_lightning/trainer/trainer.py Show resolved Hide resolved
# links data to the trainer
self.data_connector.attach_data(model, predict_dataloaders=dataloaders, datamodule=datamodule)

if not model_provided:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tchaton it canot as you do the mapping after it... I quess

@mergify mergify bot added the has conflicts label May 7, 2021
@mergify mergify bot removed the has conflicts label May 7, 2021
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
@carmocca carmocca added the ready PRs ready to be merged label May 11, 2021
Comment on lines +643 to +645
trainer_fn = getattr(trainer, fn)
path_attr = f"{fn}{'d' if fn == 'validate' else 'ed'}_ckpt_path"
assert getattr(trainer, path_attr) is None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels fragile. can we be more explicit here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test length would grow considerably (might as well split it into 3 tests then) if we don't use getattr. I know dynamic is ugly but I'd rather have a concise test

@carmocca carmocca merged commit 072ad52 into master May 12, 2021
@carmocca carmocca deleted the feat/predict-ckpt-path branch May 12, 2021 23:50
@carmocca carmocca added this to the v1.4 milestone May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants