Skip to content

Conversation

@xush6528
Copy link
Contributor

@xush6528 xush6528 commented Nov 13, 2019

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

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]
xush6528 added a commit that referenced this pull request Nov 13, 2019
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]
xush6528 added a commit that referenced this pull request Nov 13, 2019
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]
xush6528 added a commit that referenced this pull request Nov 13, 2019
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:
Copy link
Contributor

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?

Copy link
Contributor Author

@xush6528 xush6528 Nov 14, 2019

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_tests

when
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

jit does this by adding a test_jit.py in the torch/test folder and then import other tests from there. I wonder if we should do the same.

cc @yf225 @ezyang @suo

@mrshenli mrshenli requested a review from ezyang November 14, 2019 00:23
@mrshenli
Copy link
Contributor

I tagged @ezyang because this PR touches run_test.py that might affect other modules test. Please let us know if we should keep the same convention as test_jit.py and only add minimum changes to run_test.py.


class ProcessGroupRpcAgentMixin(object):
@property
def rpc_backend_name(self):
Copy link
Contributor

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.

Copy link
Contributor Author

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]
xush6528 added a commit that referenced this pull request Nov 14, 2019
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]
)

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

@ezyang ezyang left a 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]
xush6528 added a commit that referenced this pull request Nov 14, 2019
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]
@xush6528
Copy link
Contributor Author

  • Replaced TestConfig with RpcAgentTestFixture. Because, TestConfig assumes test config passed from Environment Vars (strings). String type is not sufficient if we want to configure with typed objects like RpcAgentOptions.

@ezyang ezyang self-requested a review November 15, 2019 21:52
@ezyang
Copy link
Contributor

ezyang commented Nov 15, 2019

New structure looks fine. Did you want me to review the mixin code too, or are others getting it?

@xush6528
Copy link
Contributor Author

Thanks @ezyang. No other actions needed at the moment.

@xush6528
Copy link
Contributor Author

xush6528 commented Nov 15, 2019

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]
xush6528 added a commit that referenced this pull request Nov 16, 2019
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
@xush6528 xush6528 changed the title Refactoring torch.distributed.rpc tests to have Mixins and Fixtures Add RpcAgentTestFixture to extract duplicate code Nov 16, 2019
@xush6528 xush6528 requested a review from mrshenli November 16, 2019 06:55
Copy link
Contributor

@mrshenli mrshenli left a 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
Copy link
Contributor

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
Copy link
Contributor

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]
xush6528 added a commit that referenced this pull request Nov 18, 2019
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
@mrshenli
Copy link
Contributor

Shall we remove this line in the PR description as it is no longer relevant?

Also, with more fixtures and mixins, moved tests into sub-folders.

@xush6528
Copy link
Contributor Author

@mrshenli Removed.

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 8dd6705.


WINDOWS_BLACKLIST = [
'distributed',
'rpc_fork',
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@ezyang
Copy link
Contributor

ezyang commented Nov 19, 2019

For future reference, if you identify that the PR broke a build, you should revert it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants