Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions tests/accelerators/test_accelerator_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_accelerator_choice_cpu(tmpdir):

@pytest.mark.parametrize(("num_processes", "num_nodes"), ([(1, 1), (1, 2), (2, 1), (2, 2)]))
def test_accelerator_choice_ddp_cpu(tmpdir, num_processes: int, num_nodes: int):
trainer = Trainer(fast_dev_run=True, accelerator="ddp_cpu", num_processes=num_processes, num_nodes=num_nodes)
trainer = Trainer(fast_dev_run=True, strategy="ddp_cpu", num_processes=num_processes, num_nodes=num_nodes)
assert isinstance(trainer.accelerator, CPUAccelerator)
no_spawn = num_processes == 1 and num_nodes > 1
assert isinstance(trainer.training_type_plugin, DDPPlugin if no_spawn else DDPSpawnPlugin)
Expand All @@ -68,7 +68,7 @@ def test_accelerator_choice_ddp_cpu(tmpdir, num_processes: int, num_nodes: int):
@mock.patch("torch.cuda.device_count", return_value=2)
@mock.patch("torch.cuda.is_available", return_value=True)
def test_accelerator_choice_ddp(cuda_available_mock, device_count_mock):
trainer = Trainer(fast_dev_run=True, accelerator="ddp", gpus=1)
trainer = Trainer(fast_dev_run=True, strategy="ddp", gpus=1)
assert isinstance(trainer.accelerator, GPUAccelerator)
assert isinstance(trainer.training_type_plugin, DDPPlugin)
assert isinstance(trainer.training_type_plugin.cluster_environment, LightningEnvironment)
Expand All @@ -78,7 +78,7 @@ def test_accelerator_choice_ddp(cuda_available_mock, device_count_mock):
@mock.patch("torch.cuda.device_count", return_value=2)
@mock.patch("torch.cuda.is_available", return_value=True)
def test_accelerator_choice_ddp_spawn(cuda_available_mock, device_count_mock):
trainer = Trainer(fast_dev_run=True, accelerator="ddp_spawn", gpus=1)
trainer = Trainer(fast_dev_run=True, strategy="ddp_spawn", gpus=1)
assert isinstance(trainer.accelerator, GPUAccelerator)
assert isinstance(trainer.training_type_plugin, DDPSpawnPlugin)
assert isinstance(trainer.training_type_plugin.cluster_environment, LightningEnvironment)
Expand Down Expand Up @@ -109,7 +109,7 @@ def on_fit_start(self, trainer, pl_module):
raise SystemExit()

model = BoringModel()
trainer = Trainer(fast_dev_run=True, accelerator="ddp", gpus=2, callbacks=[CB()])
trainer = Trainer(fast_dev_run=True, strategy="ddp", gpus=2, callbacks=[CB()])

with pytest.raises(SystemExit):
trainer.fit(model)
Expand Down Expand Up @@ -141,7 +141,7 @@ def on_fit_start(self, trainer, pl_module):
raise SystemExit()

model = BoringModel()
trainer = Trainer(fast_dev_run=True, accelerator="ddp2", gpus=2, callbacks=[CB()])
trainer = Trainer(fast_dev_run=True, strategy="ddp2", gpus=2, callbacks=[CB()])

with pytest.raises(SystemExit):
trainer.fit(model)
Expand Down Expand Up @@ -172,7 +172,7 @@ def on_fit_start(self, trainer, pl_module):
raise SystemExit()

model = BoringModel()
trainer = Trainer(fast_dev_run=True, accelerator="ddp", gpus=2, callbacks=[CB()])
trainer = Trainer(fast_dev_run=True, strategy="ddp", gpus=2, callbacks=[CB()])

with pytest.raises(SystemExit):
trainer.fit(model)
Expand Down Expand Up @@ -203,7 +203,7 @@ def on_fit_start(self, trainer, pl_module):
raise SystemExit()

model = BoringModel()
trainer = Trainer(fast_dev_run=True, accelerator="ddp2", gpus=2, callbacks=[CB()])
trainer = Trainer(fast_dev_run=True, strategy="ddp2", gpus=2, callbacks=[CB()])

with pytest.raises(SystemExit):
trainer.fit(model)
Expand All @@ -225,7 +225,7 @@ def on_fit_start(self, trainer, pl_module):
raise SystemExit()

model = BoringModel()
trainer = Trainer(fast_dev_run=True, accelerator="ddp_cpu", num_processes=2, callbacks=[CB()])
trainer = Trainer(fast_dev_run=True, strategy="ddp_cpu", num_processes=2, callbacks=[CB()])

with pytest.raises(SystemExit):
trainer.fit(model)
Expand Down Expand Up @@ -256,7 +256,7 @@ def on_fit_start(self, trainer, pl_module):
raise SystemExit()

model = BoringModel()
trainer = Trainer(fast_dev_run=True, accelerator="ddp", gpus=1, callbacks=[CB()])
trainer = Trainer(fast_dev_run=True, strategy="ddp", gpus=1, callbacks=[CB()])

with pytest.raises(SystemExit):
trainer.fit(model)
Expand Down Expand Up @@ -285,7 +285,7 @@ def on_fit_start(self, trainer, pl_module):
raise SystemExit()

model = BoringModel()
trainer = Trainer(fast_dev_run=True, accelerator="ddp_cpu", num_processes=1, callbacks=[CB()])
trainer = Trainer(fast_dev_run=True, strategy="ddp_cpu", num_processes=1, callbacks=[CB()])

with pytest.raises(SystemExit):
trainer.fit(model)
Expand Down Expand Up @@ -315,21 +315,21 @@ def on_fit_start(self, trainer, pl_module):
raise SystemExit()

model = BoringModel()
trainer = Trainer(fast_dev_run=True, accelerator="ddp_cpu", num_processes=2, callbacks=[CB()])
trainer = Trainer(fast_dev_run=True, strategy="ddp_cpu", num_processes=2, callbacks=[CB()])

with pytest.raises(SystemExit):
trainer.fit(model)


@RunIf(special=True)
def test_accelerator_choice_ddp_cpu_and_plugin(tmpdir):
"""Test that accelerator="ddp_cpu" can work together with an instance of DDPPlugin."""
"""Test that strategy="ddp_cpu" can work together with an instance of DDPPlugin."""
_test_accelerator_choice_ddp_cpu_and_plugin(tmpdir, ddp_plugin_class=DDPPlugin)


@RunIf(special=True)
def test_accelerator_choice_ddp_cpu_and_plugin_spawn(tmpdir):
"""Test that accelerator="ddp_cpu" can work together with an instance of DDPPSpawnPlugin."""
"""Test that strategy="ddp_cpu" can work together with an instance of DDPPSpawnPlugin."""
_test_accelerator_choice_ddp_cpu_and_plugin(tmpdir, ddp_plugin_class=DDPSpawnPlugin)


Expand All @@ -340,7 +340,7 @@ def _test_accelerator_choice_ddp_cpu_and_plugin(tmpdir, ddp_plugin_class):
default_root_dir=tmpdir,
plugins=[ddp_plugin_class(find_unused_parameters=True)],
fast_dev_run=True,
accelerator="ddp_cpu",
strategy="ddp_cpu",
num_processes=2,
)
assert isinstance(trainer.training_type_plugin, ddp_plugin_class)
Expand Down Expand Up @@ -374,7 +374,7 @@ def creates_processes_externally(self) -> bool:
return True

trainer = Trainer(
default_root_dir=tmpdir, plugins=[CustomCluster()], fast_dev_run=True, accelerator="ddp_cpu", num_processes=2
default_root_dir=tmpdir, plugins=[CustomCluster()], fast_dev_run=True, strategy="ddp_cpu", num_processes=2
)
assert isinstance(trainer.accelerator, CPUAccelerator)
assert isinstance(trainer.training_type_plugin, DDPPlugin)
Expand Down Expand Up @@ -598,7 +598,7 @@ def test_accelerator_gpu_with_gpus_priority():
def test_validate_accelerator_and_devices():

with pytest.raises(MisconfigurationException, match="You passed `devices=2` but haven't specified"):
Trainer(accelerator="ddp_cpu", devices=2)
Trainer(strategy="ddp_cpu", devices=2)


def test_set_devices_if_none_cpu():
Expand Down Expand Up @@ -630,7 +630,7 @@ def test_unsupported_distrib_types_on_cpu(training_type):


def test_accelerator_ddp_for_cpu(tmpdir):
trainer = Trainer(accelerator="ddp", num_processes=2)
trainer = Trainer(strategy="ddp", num_processes=2)
assert isinstance(trainer.accelerator, CPUAccelerator)
assert isinstance(trainer.training_type_plugin, DDPPlugin)

Expand Down
2 changes: 1 addition & 1 deletion tests/accelerators/test_tpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def on_train_end(self):
@RunIf(tpu=True)
def test_ddp_cpu_not_supported_on_tpus():
with pytest.raises(MisconfigurationException, match="`accelerator='ddp_cpu'` is not supported on TPU machines"):
Trainer(accelerator="ddp_cpu")
Trainer(strategy="ddp_cpu")


@RunIf(tpu=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/test_amp_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_precision_selection_raises(monkeypatch):
with mock.patch("torch.cuda.device_count", return_value=1), pytest.raises(
MisconfigurationException, match="Sharded plugins are not supported with apex"
):
Trainer(amp_backend="apex", precision=16, gpus=1, accelerator="ddp_fully_sharded")
Trainer(amp_backend="apex", precision=16, gpus=1, strategy="ddp_fully_sharded")

import pytorch_lightning.plugins.precision.apex_amp as apex

Expand Down
22 changes: 11 additions & 11 deletions tests/trainer/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,23 +1149,23 @@ def test_num_sanity_val_steps_neg_one(tmpdir, limit_val_batches):
dict(_distrib_type=None, _device_type=DeviceType.CPU, num_gpus=0, num_processes=1),
),
(
dict(accelerator="ddp", gpus=None),
dict(strategy="ddp", gpus=None),
dict(_distrib_type=None, _device_type=DeviceType.CPU, num_gpus=0, num_processes=1),
),
(
dict(accelerator="ddp", num_processes=2, gpus=None),
dict(strategy="ddp", num_processes=2, gpus=None),
dict(_distrib_type=DistributedType.DDP, _device_type=DeviceType.CPU, num_gpus=0, num_processes=2),
),
(
dict(accelerator="ddp", num_nodes=2, gpus=None),
dict(strategy="ddp", num_nodes=2, gpus=None),
dict(_distrib_type=DistributedType.DDP, _device_type=DeviceType.CPU, num_gpus=0, num_processes=1),
),
(
dict(accelerator="ddp_cpu", num_processes=2, gpus=None),
dict(strategy="ddp_cpu", num_processes=2, gpus=None),
dict(_distrib_type=DistributedType.DDP_SPAWN, _device_type=DeviceType.CPU, num_gpus=0, num_processes=2),
),
(
dict(accelerator="ddp2", gpus=None),
dict(strategy="ddp2", gpus=None),
dict(_distrib_type=None, _device_type=DeviceType.CPU, num_gpus=0, num_processes=1),
),
(
Expand All @@ -1177,15 +1177,15 @@ def test_num_sanity_val_steps_neg_one(tmpdir, limit_val_batches):
dict(_distrib_type=DistributedType.DP, _device_type=DeviceType.GPU, num_gpus=1, num_processes=1),
),
(
dict(accelerator="ddp", gpus=1),
dict(strategy="ddp", gpus=1),
dict(_distrib_type=DistributedType.DDP, _device_type=DeviceType.GPU, num_gpus=1, num_processes=1),
),
(
dict(accelerator="ddp_cpu", num_processes=2, gpus=1),
dict(strategy="ddp_cpu", num_processes=2, gpus=1),
dict(_distrib_type=DistributedType.DDP_SPAWN, _device_type=DeviceType.CPU, num_gpus=0, num_processes=2),
),
(
dict(accelerator="ddp2", gpus=1),
dict(strategy="ddp2", gpus=1),
dict(_distrib_type=DistributedType.DDP2, _device_type=DeviceType.GPU, num_gpus=1, num_processes=1),
),
(
Expand All @@ -1197,15 +1197,15 @@ def test_num_sanity_val_steps_neg_one(tmpdir, limit_val_batches):
dict(_distrib_type=DistributedType.DP, _device_type=DeviceType.GPU, num_gpus=2, num_processes=1),
),
(
dict(accelerator="ddp", gpus=2),
dict(strategy="ddp", gpus=2),
dict(_distrib_type=DistributedType.DDP, _device_type=DeviceType.GPU, num_gpus=2, num_processes=2),
),
(
dict(accelerator="ddp2", gpus=2),
dict(strategy="ddp2", gpus=2),
dict(_distrib_type=DistributedType.DDP2, _device_type=DeviceType.GPU, num_gpus=2, num_processes=1),
),
(
dict(accelerator="ddp2", num_processes=2, gpus=None),
dict(strategy="ddp2", num_processes=2, gpus=None),
dict(_distrib_type=DistributedType.DDP, _device_type=DeviceType.CPU, num_gpus=0, num_processes=2),
),
(
Expand Down