-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Multinode on MPS #15748
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
Merged
Merged
Multinode on MPS #15748
Changes from 14 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
f880c73
Fix restarting attribute for lr finder
justusschock c13c1a6
update lite executor
justusschock 8fceed0
update trainer executor
justusschock 13cb379
update spawn executor
justusschock 49b20b3
add multinode component tests
justusschock f80f95b
add testing helpers
justusschock 07ad6aa
add lite tests
justusschock a1b2e61
add trainer tests
justusschock e59cbba
Merge branch 'master' into fix/multinod_mps
justusschock 21231c1
Revert "Fix restarting attribute for lr finder"
justusschock fdaee38
Merge remote-tracking branch 'origin/fix/multinod_mps' into fix/multi…
justusschock 0b3157a
update changelog
justusschock b1709f0
Merge branch 'master' into fix/multinod_mps
justusschock cb98589
update skip reasons
justusschock 0e7acf0
skipif
Borda e4dde73
update skip conditions to only use L.lite and L.pytorch if available
justusschock b64b19e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e0989d0
typo
justusschock 29ae553
fix ci
justusschock be15c13
Update src/lightning_app/CHANGELOG.md
justusschock 7b93a09
test workflow
justusschock 2ac55e4
update trainer
justusschock f87fc0e
update workflow
justusschock 5760141
Merge branch 'master' into fix/multinod_mps
justusschock e4911e6
update tests
justusschock 44fe438
Update ci-app-tests.yml
justusschock 31ee30b
Update tests/tests_app/components/multi_node/test_lite.py
awaelchli f598ecb
debug
awaelchli 7914c33
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1365d90
debug
awaelchli d0db952
Merge remote-tracking branch 'origin/fix/multinod_mps' into fix/multi…
awaelchli a794104
update executors to work with standalone and unified
justusschock 1dfe1df
Merge branch 'master' into fix/multinod_mps
justusschock 4bb8580
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bfd8845
add reason for skipif
justusschock 269952d
Merge branch 'master' into fix/multinod_mps
awaelchli 5295c45
update test
justusschock b9af23d
update test
justusschock bb73075
update test
justusschock 7eeb773
update test
justusschock cfe9226
update test
justusschock 4934ac1
update test
justusschock 63d40b5
Merge branch 'master' into fix/multinod_mps
justusschock 5cb2f45
Merge branch 'master' into fix/multinod_mps
justusschock 2563a8e
Merge branch 'master' into fix/multinod_mps
justusschock 279ac50
Merge branch 'master' into fix/multinod_mps
awaelchli f0a83e8
Merge branch 'master' into fix/multinod_mps
Borda 95efc21
Merge branch 'master' into fix/multinod_mps
Borda 9d69ce1
Apply suggestions from code review
Borda ae285c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6e0e00b
ll
Borda 24ca54f
switch skipif
Borda 935a162
.
Borda 0c0aa6d
another
Borda 733b6f3
Merge branch 'master' into fix/multinod_mps
Borda 13e832c
Merge branch 'master' into fix/multinod_mps
Borda c24e1a0
Apply suggestions from code review
Borda ee0f19a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import os | ||
from copy import deepcopy | ||
from functools import partial | ||
from unittest import mock | ||
|
||
import pytest | ||
from lightning_utilities.core.imports import module_available | ||
from tests_app.helpers.utils import no_warning_call | ||
|
||
import lightning as L | ||
from lightning_app.components.multi_node.lite import _LiteRunExecutor | ||
|
||
|
||
def dummy_callable(**kwargs): | ||
ll = L.lite.LightningLite(**kwargs) | ||
return ll._all_passed_kwargs | ||
|
||
|
||
def dummy_init(self, **kwargs): | ||
self._all_passed_kwargs = kwargs | ||
|
||
|
||
def _get_args_after_tracer_injection(**kwargs): | ||
with mock.patch.object(L.lite.LightningLite, "__init__", dummy_init): | ||
ret_val = _LiteRunExecutor.run( | ||
local_rank=0, | ||
work_run=partial(dummy_callable, **kwargs), | ||
main_address="1.2.3.4", | ||
main_port=5, | ||
node_rank=6, | ||
num_nodes=7, | ||
nprocs=8, | ||
) | ||
env_vars = deepcopy(os.environ) | ||
return ret_val, env_vars | ||
|
||
|
||
@pytest.mark.skipif(not module_available("lightning.lite"), reason="Lightning.lite not available") | ||
@pytest.mark.skipif(not L.lite.accelerators.MPSAccelerator.is_available(), reason="mps not available") | ||
@pytest.mark.parametrize("accelerator_given,accelerator_expected", [("cpu", "cpu"), ("auto", "cpu"), ("gpu", "cpu")]) | ||
def test_lite_run_executor_mps_forced_cpu(accelerator_given, accelerator_expected): | ||
warning_str = ( | ||
r"Forcing accelerator=cpu as other accelerators \(specifically MPS\) are not supported " | ||
+ "by PyTorch for distributed training on mps capable devices" | ||
) | ||
if accelerator_expected != accelerator_given: | ||
warning_context = pytest.warns(UserWarning, match=warning_str) | ||
else: | ||
warning_context = no_warning_call(match=warning_str + "*") | ||
|
||
with warning_context: | ||
ret_val, env_vars = _get_args_after_tracer_injection(accelerator=accelerator_given) | ||
assert ret_val["accelerator"] == accelerator_expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args_given,args_expected", | ||
[ | ||
( | ||
{ | ||
"devices": 1, | ||
"num_nodes": 1, | ||
"accelerator": "gpu", | ||
}, | ||
{"devices": 8, "num_nodes": 7, "accelerator": "auto"}, | ||
), | ||
({"strategy": "ddp_spawn"}, {"strategy": "ddp"}), | ||
({"strategy": "ddp_sharded_spawn"}, {"strategy": "ddp_sharded"}), | ||
], | ||
) | ||
def test_trainer_run_executor_arguments_choices(args_given: dict, args_expected: dict): | ||
|
||
# ddp with mps devices not available (tested separately, just patching here for cross-os testing of other args) | ||
if L.lite.accelerators.MPSAccelerator.is_available(): | ||
args_expected["accelerator"] = "cpu" | ||
|
||
ret_val, env_vars = _get_args_after_tracer_injection(**args_given) | ||
|
||
for k, v in args_expected.items(): | ||
assert ret_val[k] == v | ||
|
||
assert env_vars["MASTER_ADDR"] == "1.2.3.4" | ||
assert env_vars["MASTER_PORT"] == "5" | ||
assert env_vars["GROUP_RANK"] == "6" | ||
assert env_vars["RANK"] == str(0 + 6 * 8) | ||
assert env_vars["LOCAL_RANK"] == "0" | ||
assert env_vars["WORLD_SIZE"] == str(7 * 8) | ||
assert env_vars["LOCAL_WORLD_SIZE"] == "8" | ||
assert env_vars["TORCHELASTIC_RUN_ID"] == "1" | ||
assert env_vars["LT_CLI_USED"] == "1" | ||
|
||
|
||
def test_lite_run_executor_invalid_strategy_instances(): | ||
with pytest.raises(ValueError, match="DDP Spawned strategies aren't supported yet."): | ||
_, _ = _get_args_after_tracer_injection(strategy=L.lite.strategies.DDPSpawnStrategy()) | ||
|
||
with pytest.raises(ValueError, match="DDP Spawned strategies aren't supported yet."): | ||
_, _ = _get_args_after_tracer_injection(strategy=L.lite.strategies.DDPSpawnShardedStrategy()) |
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import os | ||
from copy import deepcopy | ||
from functools import partial | ||
from unittest import mock | ||
|
||
import pytest | ||
from lightning_utilities.core.imports import module_available | ||
from tests_app.helpers.utils import no_warning_call | ||
|
||
import lightning as L | ||
from lightning_app.components.multi_node.trainer import _LightningTrainerRunExecutor | ||
|
||
|
||
def dummy_callable(**kwargs): | ||
t = L.pytorch.Trainer(**kwargs) | ||
return t._all_passed_kwargs | ||
|
||
|
||
def dummy_init(self, **kwargs): | ||
self._all_passed_kwargs = kwargs | ||
|
||
|
||
def _get_args_after_tracer_injection(**kwargs): | ||
with mock.patch.object(L.pytorch.Trainer, "__init__", dummy_init): | ||
ret_val = _LightningTrainerRunExecutor.run( | ||
local_rank=0, | ||
work_run=partial(dummy_callable, **kwargs), | ||
main_address="1.2.3.4", | ||
main_port=5, | ||
node_rank=6, | ||
num_nodes=7, | ||
nprocs=8, | ||
) | ||
env_vars = deepcopy(os.environ) | ||
return ret_val, env_vars | ||
|
||
|
||
@pytest.mark.skipif(not module_available("lightning.pytorch"), reason="lightning.pytorch not available") | ||
@pytest.mark.skipif( | ||
not L.pytorch.accelerators.MPSAccelerator.is_available(), reason="MPS not available but required for this test" | ||
) | ||
@pytest.mark.parametrize("accelerator_given,accelerator_expected", [("cpu", "cpu"), ("auto", "cpu"), ("gpu", "cpu")]) | ||
def test_trainer_run_executor_mps_forced_cpu(accelerator_given, accelerator_expected): | ||
warning_str = ( | ||
r"Forcing accelerator=cpu as other accelerators \(specifically MPS\) are not supported " | ||
+ "by PyTorch for distributed training on mps capable devices" | ||
) | ||
if accelerator_expected != accelerator_given: | ||
warning_context = pytest.warns(UserWarning, match=warning_str) | ||
else: | ||
warning_context = no_warning_call(match=warning_str + "*") | ||
|
||
with warning_context: | ||
ret_val, env_vars = _get_args_after_tracer_injection(accelerator=accelerator_given) | ||
assert ret_val["accelerator"] == accelerator_expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args_given,args_expected", | ||
[ | ||
( | ||
{ | ||
"devices": 1, | ||
"num_nodes": 1, | ||
"accelerator": "gpu", | ||
}, | ||
{"devices": 8, "num_nodes": 7, "accelerator": "auto"}, | ||
Borda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
), | ||
({"strategy": "ddp_spawn"}, {"strategy": "ddp"}), | ||
({"strategy": "ddp_sharded_spawn"}, {"strategy": "ddp_sharded"}), | ||
], | ||
) | ||
def test_trainer_run_executor_arguments_choices(args_given: dict, args_expected: dict): | ||
|
||
# ddp with mps devices not available (tested separately, just patching here for cross-os testing of other args) | ||
if L.pytorch.accelerators.MPSAccelerator.is_available(): | ||
args_expected["accelerator"] = "cpu" | ||
|
||
ret_val, env_vars = _get_args_after_tracer_injection(**args_given) | ||
|
||
for k, v in args_expected.items(): | ||
assert ret_val[k] == v | ||
|
||
assert env_vars["MASTER_ADDR"] == "1.2.3.4" | ||
assert env_vars["MASTER_PORT"] == "5" | ||
assert env_vars["GROUP_RANK"] == "6" | ||
assert env_vars["RANK"] == str(0 + 6 * 8) | ||
assert env_vars["LOCAL_RANK"] == "0" | ||
assert env_vars["WORLD_SIZE"] == str(7 * 8) | ||
assert env_vars["LOCAL_WORLD_SIZE"] == "8" | ||
assert env_vars["TORCHELASTIC_RUN_ID"] == "1" | ||
|
||
|
||
def test_trainer_run_executor_invalid_strategy_instances(): | ||
with pytest.raises(ValueError, match="DDP Spawned strategies aren't supported yet."): | ||
_, _ = _get_args_after_tracer_injection(strategy=L.pytorch.strategies.DDPSpawnStrategy()) | ||
|
||
with pytest.raises(ValueError, match="DDP Spawned strategies aren't supported yet."): | ||
_, _ = _get_args_after_tracer_injection(strategy=L.pytorch.strategies.DDPSpawnShardedStrategy()) |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import re | ||
from contextlib import contextmanager | ||
from typing import Optional, Type | ||
|
||
import pytest | ||
|
||
|
||
@contextmanager | ||
def no_warning_call(expected_warning: Type[Warning] = UserWarning, match: Optional[str] = None): | ||
with pytest.warns(None) as record: | ||
yield | ||
|
||
if match is None: | ||
try: | ||
w = record.pop(expected_warning) | ||
except AssertionError: | ||
# no warning raised | ||
return | ||
else: | ||
for w in record.list: | ||
if w.category is expected_warning and re.compile(match).search(w.message.args[0]): | ||
break | ||
else: | ||
return | ||
|
||
msg = "A warning" if expected_warning is None else f"`{expected_warning.__name__}`" | ||
raise AssertionError(f"{msg} was raised: {w}") |
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.
Uh oh!
There was an error while loading. Please reload this page.