8000 Support both train / eval modes for ModuleInfo by jbschlosser · Pull Request #78735 · pytorch/pytorch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support both train / eval modes for ModuleInfo #78735

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

Closed
wants to merge 5 commits into from

Conversation

jbschlosser
Copy link
Contributor
@jbschlosser jbschlosser commented Jun 2, 2022

Stack from ghstack:

This PR enhances the tests in test/test_modules.py to be run across train / eval modes. It makes the following changes:

  • Adds a required training arg to ModuleInfo.module_inputs_func - this allows those functions to generate sample module inputs based on the training mode.
  • Updates the @modules decorator to additionally pass a training arg to test functions.
    • The training arg values to pass can be customized via TrainEvalMode e.g. @modules(..., train_eval_mode=TrainEvalMode.train_only). Supported modes are train_only, eval_only, and train_and_eval.
    • Tests that use the decorator in test/test_modules.py have been updated. They now ingest the training arg, pass it to the module_inputs_func, and set the training mode for instantiated module instances with m.train(training). There's almost certainly a way to do this with less boilerplate.
  • Adds a new train_and_eval_differ option to ModuleInfo for indicating whether a specific module cares about the training mode.
    • If this is False, tests are generated just for a single mode. This avoids pointlessly running tests twice when the training mode setting doesn't matter.
    • Adds a new test in test/test_modules.py to verify that train_and_eval_differ is set correctly. It does this by instantiating each module, deleting the training attribute, and then running the forward pass. If the forward pass references training, it will throw an AttributeError, indicating that train_and_eval_differ=True should be set.

@facebook-github-bot
Copy link
Contributor
facebook-github-bot commented Jun 2, 2022

🔗 Helpful links

✅ No Failures (46 Pending)

As of commit 6d46096 (more details on the Dr. CI page):

Expand to see more

💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

jbschlosser added a commit that referenced this pull request Jun 2, 2022
ghstack-source-id: 160cd20
Pull Request resolved: #78735
This PR enhances the tests in `test/test_modules.py` to be run across train / eval modes. It allows sample inputs to be generated based on the mode under test (useful if e.g. if a certain sample should only be used during eval mode).

[ghstack-poisoned]
@jbschlosser jbschlosser requested review from albanD and removed request for ngimel June 7, 2022 22:18
This PR enhances the tests in `test/test_modules.py` to be run across train / eval modes. It makes the following changes:
* Adds a required `training` arg to `ModuleInfo.module_inputs_func` - this allows those functions to generate sample module inputs based on the training mode.
* Updates the `modules` decorator to additionally pass a `training` arg to test functions.
    * The `training` arg values to pass can be customized via `TrainEvalMode` e.g. `modules(..., train_eval_mode=TrainEvalMode.train_only)`. Supported modes are `train_only`, `eval_only`, and `train_and_eval`.
    * Tests that use the decorator in `test/test_modules.py` have been updated. They now ingest the `training` arg, pass it to the `module_inputs_func`, and set the training mode for instantiated module instances with `m.train(training)`. There's almost certainly a way to do this with less boilerplate.
* Adds a new `train_and_eval_differ` option to `ModuleInfo` for indicating whether a specific module cares about the training mode.
    * If this is `False`, tests are generated just for training by default. This avoids pointlessly running tests twice when the training mode setting doesn't matter.
    * Adds a new test in `test/test_modules.py` to verify that `train_and_eval_differ` is set correctly. It does this by instantiating each module, deleting the `training` attribute, and then running the forward pass. If the forward pass references `training`, it will throw an `AttributeError`, indicating that `train_and_eval_differ=True` should be set.

[ghstack-poisoned]
jbschlosser added a commit that referenced this pull request Jun 7, 2022
ghstack-source-id: 2204243
Pull Request resolved: #78735
Copy link
Collaborator
@albanD albanD left a comment

Choose a reason for hiding this comment

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

SGTM!
Just minor comments

Copy link
Contributor Author
@jbschlosser jbschlosser left a comment

Choose a reason for hiding this comment

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

@albanD Before I can merge this, it looks like I need a way to skip a test for eval mode only.

I have a working fix that can skip based on anything passed to the test - going to add a commit earlier in the PR stack that adds this

This PR enhances the tests in `test/test_modules.py` to be run across train / eval modes. It makes the following changes:
* Adds a required `training` arg to `ModuleInfo.module_inputs_func` - this allows those functions to generate sample module inputs based on the training mode.
* Updates the `modules` decorator to additionally pass a `training` arg to test functions.
    * The `training` arg values to pass can be customized via `TrainEvalMode` e.g. `modules(..., train_eval_mode=TrainEvalMode.train_only)`. Supported modes are `train_only`, `eval_only`, and `train_and_eval`.
    * Tests that use the decorator in `test/test_modules.py` have been updated. They now ingest the `training` arg, pass it to the `module_inputs_func`, and set the training mode for instantiated module instances with `m.train(training)`. There's almost certainly a way to do this with less boilerplate.
* Adds a new `train_and_eval_differ` option to `ModuleInfo` for indicating whether a specific module cares about the training mode.
    * If this is `False`, tests are generated just for a single mode. This avoids pointlessly running tests twice when the training mode setting doesn't matter.
    * Adds a new test in `test/test_modules.py` to verify that `train_and_eval_differ` is set correctly. It does this by instantiating each module, deleting the `training` attribute, and then running the forward pass. If the forward pass references `training`, it will throw an `AttributeError`, indicating that `train_and_eval_differ=True` should be set.

[ghstack-poisoned]
jbschlosser added a commit that referenced this pull request Jun 8, 2022
ghstack-source-id: e4dc89b
Pull Request resolved: #78735
@jbschlosser
Copy link
Contributor Author

@pytorchbot merge -g

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a merge job. Check the current status here

@github-actions
Copy link
Contributor
github-actions bot commented Jun 8, 2022

Hey @jbschlosser.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

@malfet
Copy link
Contributor
malfet commented Jun 9, 2022

@pytorchbot revert -m "Broke eval tests on Win, 10.2 and ROCM, see https://hud.pytorch.org/pytorch/pytorch/commit/12658fcd5bdf4d2437754633b3fa39ab15d213b9 " -c missingsignal

@pytorch-bot
Copy link
pytorch-bot bot commented Jun 9, 2022

❌ 🤖 pytorchbot command failed:

@pytorchbot revert: error: argument -c/--classification: invalid choice: 'missingsignal' (choose from 'nosignal', 'ignoredsignal', 'landrace', 'weird', 'ghfirst')

usage: @pytorchbot revert -m MESSAGE
                          [-c {nosignal,ignoredsignal,landrace,weird,ghfirst}]

Try @pytorchbot help for more info.

@malfet
Copy link
Contributor
malfet commented Jun 9, 2022

@pytorchbot revert -m "Broke eval tests on Win, 10.2 and ROCM, see https://hud.pytorch.org/pytorch/pytorch/commit/12658fcd5bdf4d2437754633b3fa39ab15d213b9 " -c nosignal

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here

pytorchmergebot added a commit that referenced this pull request Jun 9, 2022
@jbschlosser jbschlosser reopened this Jun 9, 2022
@jbschlosser jbschlosser added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 9, 2022
This PR enhances the tests in `test/test_modules.py` to be run across train / eval modes. It makes the following changes:
* Adds a required `training` arg to `ModuleInfo.module_inputs_func` - this allows those functions to generate sample module inputs based on the training mode.
* Updates the `modules` decorator to additionally pass a `training` arg to test functions.
    * The `training` arg values to pass can be customized via `TrainEvalMode` e.g. `modules(..., train_eval_mode=TrainEvalMode.train_only)`. Supported modes are `train_only`, `eval_only`, and `train_and_eval`.
    * Tests that use the decorator in `test/test_modules.py` have been updated. They now ingest the `training` arg, pass it to the `module_inputs_func`, and set the training mode for instantiated module instances with `m.train(training)`. There's almost certainly a way to do this with less boilerplate.
* Adds a new `train_and_eval_differ` option to `ModuleInfo` for indicating whether a specific module cares about the training mode.
    * If this is `False`, tests are generated just for a single mode. This avoids pointlessly running tests twice when the training mode setting doesn't matter.
    * Adds a new test in `test/test_modules.py` to verify that `train_and_eval_differ` is set correctly. It does this by instantiating each module, deleting the `training` attribute, and then running the forward pass. If the forward pass references `training`, it will throw an `AttributeError`, indicating that `train_and_eval_differ=True` should be set.

[ghstack-poisoned]
jbschlosser added a commit that referenced this pull request Jun 9, 2022
ghstack-source-id: 58125b7
Pull Request resolved: #78735
@jbschlosser jbschlosser added release notes: nn release notes category topic: not user facing topic category labels Jun 9, 2022
@jbschlosser
Copy link
Contributor Author

@pytorchbot merge -a

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a merge job. Check the current status here

@pytorchmergebot
Copy link
Collaborator

Merge failed due to Refusing to merge as mandatory check(s) linux-docs / build-docs (cpp) are pending/not yet run for rule superuser
Raised by https://github.com/pytorch/pytorch/actions/runs/2470378831

@jbschlosser
Copy link
Contributor Author

@pytorchbot merge -a

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a merge job. Check the current status here

facebook-github-bot pushed a commit that referenced this pull request Jun 10, 2022
Summary:
Pull Request resolved: #78735

Approved by: https://github.com/albanD

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/12658fcd5bdf4d2437754633b3fa39ab15d213b9

Reviewed By: osalpekar

Differential Revision: D37025769

Pulled By: jbschlosser

fbshipit-source-id: 4c9c842f4bc6dbed3a37fd464dfbad2fe48bad17
facebook-github-bot pushed a commit that referenced this pull request Jun 10, 2022
Summary:
This reverts commit 12658fc.

Reverted #78735 on behalf of https://github.com/malfet due to Broke eval tests on Win, 10.2 and ROCM, see https://hud.pytorch.org/pytorch/pytorch/commit/12658fcd5bdf4d2437754633b3fa39ab15d213b9

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/854c833f8101b62ccda9198dd0a66555e7caaa69

Reviewed By: osalpekar

Differential Revision: D37030370

Pulled By: osalpekar

fbshipit-source-id: 77810affd0ac9acefd8ea96a3d39781a0d5b9eaa
facebook-github-bot pushed a commit that referenced this pull request Jun 10, 2022
Summary:
Pull Request resolved: #78735

Approved by: https://github.com/albanD

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/70d6446a3def513b8082d243d7996ef86c2787a6

Reviewed By: osalpekar

Differential Revision: D37059361

Pulled By: osalpekar

fbshipit-source-id: a179f93c722112a70bdcecc67f6c5d1c9234eb50
@facebook-github-bot facebook-github-bot deleted the gh/jbschlosser/39/head branch June 13, 2022 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request cla signed Merged release notes: nn release notes category topic: not user facing topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0