-
-
Notifications
You must be signed in to change notification settings - Fork 708
Fix Distributed Initialization by Validating Legacy tcp:// and Updating Tests #3758
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
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1127fd7
Reverted to warn against tcp ip use
TahaZahid05 ec61bd4
Fixed error message and refactored code to avoid using None.
TahaZahid05 65794e1
Merge branch 'master' into fix-torchrun-ci
TahaZahid05 53aa731
Added store support for distributed, fixed messages, and added tests
TahaZahid05 bf344c1
Set USE_LIBUV=0 for windows
TahaZahid05 33770d9
Used argument use_libuv instead
TahaZahid05 963b079
Trying workflow solution
TahaZahid05 55d5ba7
Added store to kwargs
TahaZahid05 d08cd26
Fixed test
TahaZahid05 a0fe019
Merge branch 'master' into fix-torchrun-ci
TahaZahid05 ffcefb4
Skipped test, and reverted wrong distributed tag
TahaZahid05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
@@ -334,7 +335,8 @@ def _test__native_dist_model_create_from_context_set_local_rank(true_conf): | |
| def _test__native_dist_model_create_from_context_no_dist(true_backend, true_device): | ||
| assert _NativeDistModel.create_from_context() is None | ||
|
|
||
| dist.init_process_group(true_backend, "tcp://0.0.0.0:2222", world_size=1, rank=0) | ||
| store = dist.TCPStore("0.0.0.0", 2222, world_size=1, is_master=True) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had a fixture to get a freeport in the conf.py, can we use it here? |
||
| dist.init_process_group(true_backend, store=store, world_size=1, rank=0) | ||
|
Comment on lines
+338
to
+339
|
||
| dist.barrier() | ||
|
|
||
| _test__native_dist_model_create_from_context_no_local_rank() | ||
|
|
@@ -358,7 +360,9 @@ def _test__native_dist_model_create_from_context_no_dist(true_backend, true_devi | |
| def _test__native_dist_model_create_from_context_dist(local_rank, rank, world_size, true_backend, true_device): | ||
| assert _NativeDistModel.create_from_context() is None | ||
|
|
||
| dist.init_process_group(true_backend, "tcp://0.0.0.0:2222", world_size=world_size, rank=rank) | ||
| is_master = rank == 0 | ||
| store = dist.TCPStore("0.0.0.0", 2222, world_size=world_size, is_master=is_master) | ||
| dist.init_process_group(true_backend, store=store, world_size=world_size, rank=rank) | ||
|
Comment on lines
+363
to
+365
|
||
| dist.barrier() | ||
| if torch.cuda.is_available(): | ||
| torch.cuda.set_device(local_rank) | ||
|
|
@@ -397,7 +401,7 @@ def test__native_dist_model_create_no_dist_nccl(clean_env): | |
|
|
||
|
|
||
| @pytest.mark.distributed | ||
| @pytest.mark.parametrize("init_method", [None, "tcp://0.0.0.0:22334", "FILE"]) | ||
| @pytest.mark.parametrize("init_method", [None, "FILE"]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of removing a test, let's do store arg instead |
||
| def test__native_dist_model_create_dist_gloo_1(init_method, get_fixed_dirname, local_rank, world_size): | ||
| if init_method == "FILE": | ||
| init_method = f"file://{get_fixed_dirname('native_dist_model_create_dist_gloo_1')}/shared" | ||
|
|
@@ -418,7 +422,7 @@ def test__native_dist_model_create_dist_gloo_2(local_rank, world_size): | |
|
|
||
| @pytest.mark.distributed | ||
| @pytest.mark.skipif(torch.cuda.device_count() < 1, reason="Skip if no GPU") | ||
| @pytest.mark.parametrize("init_method", [None, "tcp://0.0.0.0:22334", "FILE"]) | ||
| @pytest.mark.parametrize("init_method", [None, "FILE"]) | ||
| def test__native_dist_model_create_dist_nccl_1(init_method, get_fixed_dirname, local_rank, world_size): | ||
| if init_method == "FILE": | ||
| init_method = f"file://{get_fixed_dirname('native_dist_model_create_dist_nccl_1')}/shared" | ||
|
|
@@ -444,7 +448,9 @@ def test__native_dist_model_create_dist_nccl_2(local_rank, world_size): | |
| def test__native_dist_model_warning_index_less_localrank(local_rank, world_size): | ||
| assert _NativeDistModel.create_from_context() is None | ||
|
|
||
| dist.init_process_group("nccl", "tcp://0.0.0.0:2222", world_size=world_size, rank=local_rank) | ||
| is_master = local_rank == 0 | ||
| store = dist.TCPStore("0.0.0.0", 2222, world_size=world_size, is_master=is_master) | ||
| dist.init_process_group("nccl", store=store, world_size=world_size, rank=local_rank) | ||
|
Comment on lines
+451
to
+453
|
||
| dist.barrier() | ||
| # We deliberately incorrectly set cuda device to 0 | ||
| torch.cuda.set_device(0) | ||
|
|
@@ -496,7 +502,7 @@ def _test__native_dist_model_spawn(backend, num_workers_per_machine, device, ini | |
|
|
||
| @pytest.mark.distributed | ||
| @pytest.mark.skipif("WORLD_SIZE" in os.environ, reason="Skip if launched as multiproc") | ||
| @pytest.mark.parametrize("init_method", [None, "CUSTOM_ADDR_PORT", "env://", "tcp://0.0.0.0:22334", "FILE"]) | ||
| @pytest.mark.parametrize("init_method", [None, "CUSTOM_ADDR_PORT", "env://", "FILE"]) | ||
| def test__native_dist_model_spawn_gloo(init_method, dirname): | ||
| spawn_kwargs = {} | ||
|
|
||
|
|
@@ -532,7 +538,7 @@ def test__native_dist_model_spawn_gloo(init_method, dirname): | |
| @pytest.mark.distributed | ||
| @pytest.mark.skipif("WORLD_SIZE" in os.environ, reason="Skip if launched as multiproc") | ||
| @pytest.mark.skipif(torch.cuda.device_count() < 1, reason="Skip if no GPU") | ||
| @pytest.mark.parametrize("init_method", [None, "CUSTOM_ADDR_PORT", "tcp://0.0.0.0:22334", "FILE"]) | ||
| @pytest.mark.parametrize("init_method", [None, "CUSTOM_ADDR_PORT", "FILE"]) | ||
| def test__native_dist_model_spawn_nccl(init_method, dirname): | ||
| spawn_kwargs = {} | ||
|
|
||
|
|
@@ -720,3 +726,30 @@ def test__setup_ddp_vars_from_slurm_env_bad_configs(): | |
| "SLURM_JOB_ID": "12345", | ||
| } | ||
| _setup_ddp_vars_from_slurm_env(environ) | ||
|
|
||
|
|
||
| def test__native_dist_model_tcp_init_method_error(): | ||
| with pytest.raises(ValueError, match="will hang. To fix this, please configure MASTER_ADDR"): | ||
| _NativeDistModel.create_from_backend(backend="gloo", init_method="tcp://10.1.1.20:23456", rank=0, world_size=1) | ||
|
|
||
|
|
||
| @pytest.mark.skipif(sys.platform.startswith("win"), reason="Skip on Windows due to TCPStore libuv bugs") | ||
| @pytest.mark.parametrize( | ||
| "backend,device", | ||
| [ | ||
| ("gloo", torch.device("cpu")), | ||
| pytest.param( | ||
| "nccl", | ||
| torch.device("cuda:0"), | ||
| marks=pytest.mark.skipif(torch.cuda.device_count() < 1, reason="Skip if no GPU"), | ||
| ), | ||
| ], | ||
| ) | ||
| def test__native_dist_model_store_init(clean_env, backend, device): | ||
| store = dist.TCPStore("0.0.0.0", 2222, world_size=1, is_master=True) | ||
|
|
||
| model = _NativeDistModel.create_from_backend(backend=backend, store=store, rank=0, world_size=1) | ||
| assert model.backend() == backend | ||
| assert model.get_world_size() == 1 | ||
| assert model.get_rank() == 0 | ||
| dist.destroy_process_group() | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There is no change in this, let's revert the code formatting.