-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Add RpcAgentTestFixture to extract duplicate code #29747
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
Conversation
We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) [ghstack-poisoned]
… Fixtures" We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) [ghstack-poisoned]
Pull Request resolved: #29747 We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) ghstack-source-id: 93857085
… Fixtures" We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) [ghstack-poisoned]
Pull Request resolved: #29747 We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) ghstack-source-id: 93859285
… Fixtures" We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) [ghstack-poisoned]
Pull Request resolved: #29747 We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) ghstack-source-id: 93868349
test/run_test.py
Outdated
| for exclude_test in exclude_list: | ||
| for test in tests_copy: | ||
| if test.startswith(exclude_test): | ||
| if test == exclude_test: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why changing this to exact match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice line 85,
WINDOWS_BLACKLIST = [
'distributed', # line 85
'distributed/rpc/process_group/rpc_fork',
]Initially selected_tests is like,
selected_tests = [
'distributed',
'distributed/rpc/process_group/rpc_fork',
]After iterating on exclude_test == 'distributed', selected_tests becomes,
selected_tests = [
'distributed/rpc/process_group/rpc_fork',
]Since the exclude_tests is,
def exclude_tests(exclude_list, selected_tests, exclude_message=None):
tests_copy = selected_tests[:]
for exclude_test in exclude_list:
for test in tests_copy:
if test.startswith(exclude_test):
if exclude_message is not None:
print_to_stderr('Excluding {} {}'.format(test, exclude_message))
selected_tests.remove(test)
return selected_testswhen
test == 'distributed/rpc/process_group/rpc_fork',
and
exclude_test == 'distributed'
It will run selected_tests.remove('distributed'), raising a "list does not contain 'distributed'. " error.
test/run_test.py
Outdated
|
|
||
| for test in selected_tests: | ||
| test_name = 'test_{}'.format(test) | ||
| splits = test.rsplit("/", 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
I tagged @ezyang because this PR touches |
|
|
||
| class ProcessGroupRpcAgentMixin(object): | ||
| @property | ||
| def rpc_backend_name(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will there be any other helper function be added to this class? If this is the only one, this looks like an overkill for just passing a string to a test class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's def rpc_agent_options in the next PR. Adding this Mixin + refactoring for this Mixin is the purpose of this PR.
… Fixtures" We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) [ghstack-poisoned]
… Fixtures" We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) [ghstack-poisoned]
… Fixtures" We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) [ghstack-poisoned]
Pull Request resolved: #29747 We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) ghstack-source-id: 93885275
test/run_test.py
Outdated
| os.environ['PYTHONPATH'] = os.pathsep.join( | ||
| [path for path in [os.environ.get('PYTHONPATH', ''), test_directory] if path] | ||
| ) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is silly and you should just keep all the tests in the top level directory. If you do this, will running tests directly from the directory (without using run_test.py) work? I don't think so! And now you've just made it that much harder for people to run a specific test with, e.g., gdb attached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pietern Agree? Let's put them flatly?
ezyang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm NACK'ing the run_test.py changes. An important invariant I want to hold is that I can run python test/test_foo.py without anything special, and I will run that test. The multi-level folder structure that you've setup here causes this property to no longer hold. I don't think multiple folders is worth losing the invariant.
… Fixtures" We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) [ghstack-poisoned]
Pull Request resolved: #29747 We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) ghstack-source-id: 93890260
… Fixtures" We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) [ghstack-poisoned]
|
|
New structure looks fine. Did you want me to review the mixin code too, or are others getting it? |
|
Thanks @ezyang. No other actions needed at the moment. |
|
I have a conclusion with @pritamdamania87 , we don't want to have differnet Test classes for dirrent RPC backends. We will use trap code to configure 1) which backend the test should us and 2) the RpcAgentOptions to use, so after settingup as a middle step, the test binary still falls to the single test entry class, RpcTest class, DistAutograd class and DistOptimizer class. I will revert most of the refacting in this PR and only leave the TestFixture class as it's the duplicate code extracted from RpcTest class, DistAutograd class and DistOptimizer class. |
… Fixtures" We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) [ghstack-poisoned]
Pull Request resolved: #29747 We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. ProcessGroupRpcAgentTestMixin/ThriftTestRpcAgentTestMixin replace class TestConfig. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) ghstack-source-id: 94014185
mrshenli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RpcAgentTestFixture and code refactoring look good to me!
| import torch.distributed.autograd as dist_autograd | ||
| import torch.distributed.rpc as rpc | ||
| import threading | ||
| from rpc_agent_test_fixture import RpcAgentTestFixture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this line up to put it together with dist_utils?
| import dist_utils | ||
| from dist_utils import dist_init | ||
| from torch.distributed.rpc.internal import PythonUDF, _internal_rpc_pickler | ||
| from rpc_agent_test_fixture import RpcAgentTestFixture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here.
We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) [ghstack-poisoned]
Pull Request resolved: #29747 We plan to introduce different `RpcAgentOption`s, this requires us to allow different tests for differnet `RpcAgent`s to correctly configure the test by bringing in different test mixins. This refactoring PR is empowering this. Also, with more fixtures and mixins, moved tests into sub-folders. ProcessGroupRpcAgentTestMixin/ThriftTestRpcAgentTestMixin replace class TestConfig. Differential Revision: [D5689636](https://our.internmc.facebook.com/intern/diff/D5689636/) ghstack-source-id: 94122697
|
Shall we remove this line in the PR description as it is no longer relevant? |
|
@mrshenli Removed. |
|
This pull request has been merged in 8dd6705. |
|
it looks like this PR broke the windows build? https://ci.pytorch.org/jenkins/job/pytorch-builds/job/pytorch-win-ws2016-cuda9-cudnn7-py3-test2/56195/console - (also looks like the culprit from the CI page - https://ezyang.github.io/pytorch-ci-hud/build/pytorch-master) |
|
|
||
| WINDOWS_BLACKLIST = [ | ||
| 'distributed', | ||
| 'rpc_fork', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason these are removed from the windows blacklist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rohan-varma
Wanted to include changes in #29827 to avoid that PR rebasing again.
I should have removed line 71, 73 too.
|
For future reference, if you identify that the PR broke a build, you should revert it. |
Stack from ghstack:
There are duplicate code for component that rely on RpcAgent. Extract them into a re-usable test fixture class.
Differential Revision: D5689636