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

Finish PR #2432: Imagenet example updates + basic testing #2889

Merged
merged 23 commits into from
Aug 9, 2020

Conversation

awaelchli
Copy link
Contributor

What does this PR do?

Finishes an old PR #2432 by @ruotianluo

  • standardize with other examples
  • a test that runs for 1 epoch making sure the script can run
  • simplifications

@awaelchli awaelchli added bug Something isn't working example docs Documentation related labels Aug 8, 2020
@awaelchli awaelchli added this to the 0.9.0 milestone Aug 8, 2020
@mergify mergify bot requested a review from a team August 8, 2020 16:20
@pep8speaks
Copy link

pep8speaks commented Aug 8, 2020

Hello @awaelchli! Thanks for updating this PR.

Line 209:35: W503 line break before binary operator

Comment last updated at 2020-08-09 02:48:45 UTC

@awaelchli awaelchli changed the title Finish PR #2432: Imagenet example updates + testing Finish PR #2432: Imagenet example updates + basic testing Aug 8, 2020
@codecov
Copy link

codecov bot commented Aug 8, 2020

Codecov Report

Merging #2889 into master will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff           @@
##           master   #2889   +/-   ##
======================================
  Coverage      90%     90%           
======================================
  Files          79      79           
  Lines        7236    7236           
======================================
  Hits         6530    6530           
  Misses        706     706           

@awaelchli awaelchli closed this Aug 8, 2020
@Borda Borda reopened this Aug 8, 2020
@Borda
Copy link
Member

Borda commented Aug 8, 2020

You can still use this one... =)

ruotianluo and others added 5 commits August 8, 2020 20:14
…when ddp (#2432)

* fix imagenet example: lr_scheduler, loader workers, batch size when ddp

* Fix evaluation for imagenet example

* add imagenet example test

* cleanup

* gpu

* add imagenet example evluation test

* fix test output

* test is fixed in master, remove unecessary hack

* CHANGE

* Apply suggestions from code review

Co-authored-by: Jirka <jirka@pytorchlightning.ai>
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
@awaelchli awaelchli marked this pull request as ready for review August 9, 2020 02:55
Copy link
Contributor

@nateraw nateraw left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 Nice work as always, Adrian.

with mock.patch("argparse._sys.argv", ["any.py"] + cli_args):
run_cli()


# @pytest.mark.parametrize('cli_args', ['--max_epochs 1 --max_steps 3 --num_nodes 1 --gpus 2'])
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove these comments if we don't need them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was wondering myself. They are outdated and have to be rewritten anyway if we ever get multi-node ddp testing.

@@ -1,13 +1,27 @@
"""
This example is largely adapted from https://github.com/pytorch/examples/blob/master/imagenet/main.py

Copy link
Contributor

Choose a reason for hiding this comment

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

This is great info, thanks.

@mergify mergify bot requested a review from a team August 9, 2020 07:53
@ananyahjha93 ananyahjha93 added the ready PRs ready to be merged label Aug 9, 2020
@williamFalcon williamFalcon merged commit 6ad2718 into master Aug 9, 2020
@Borda Borda deleted the imagenet_example branch August 9, 2020 10:31
@ruotianluo
Copy link
Contributor

It seems the current --evaluate won't load the checkpoint from --resume_from_checkpoint, right?

I saw in the doc:

# (4) test with an explicit model (will use this model and not load a checkpoint)
traiener.test(model)

@awaelchli
Copy link
Contributor Author

oh yes, I think you are right. Would you like to send a PR?

@ruotianluo
Copy link
Contributor

I am not sure what is the most elegant solution:
One possibility would just be:

model.load_state_dict(torch.load(args.resume_from_checkpoint, map_location=''cpu)['state_dict'])

But I think it's too ugly.

@awaelchli
Copy link
Contributor Author

we could simply pass the checkpoint path to .test
trainer.test(model, ckpt_path="...") # default is ckpt_path="best", but that's not available
what do you think?

@awaelchli
Copy link
Contributor Author

ok, correction, then trainer.test(ckpt_path="...") without model? :)

@ruotianluo
Copy link
Contributor

Doesn't that assume trainer already has the model? My understanding, if you want to use this, you have to run it after trainer.fit(model) otherwise trainer doesn't know what is the model.

@awaelchli
Copy link
Contributor Author

awaelchli commented Sep 20, 2020

we could load the state at the beginning, like basically as you proposed, but with all additional params

if args.evaluate:
    model = ImageNetLightningModel.load_from_checkpoint(path, map_location=...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docs Documentation related example ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants