Skip to content
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

Deprecate num_processes,gpus, tpu_cores, and ipus from the Trainer constructor #11040

Merged
merged 37 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
212a799
Deprecate num_processes, gpus, tpu_cores, and ipus from the Trainer c…
daniellepintz Dec 11, 2021
5368b14
fix accel_con tests
daniellepintz Dec 15, 2021
5124e3e
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz Dec 22, 2021
841aed7
change removal to 2.0
daniellepintz Dec 22, 2021
ad02054
fix
daniellepintz Dec 22, 2021
ca0b6a2
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz Jan 20, 2022
151da46
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 20, 2022
3186c2c
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz Feb 4, 2022
e87b79d
Merge branch 'accel_con' of github.com:daniellepintz/pytorch-lightnin…
daniellepintz Feb 4, 2022
315b5e9
fix tpu test
daniellepintz Feb 10, 2022
f6819c3
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz Feb 10, 2022
71e8011
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2022
6cb44d6
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz Mar 2, 2022
87accbd
Merge branch 'accel_con' of github.com:daniellepintz/pytorch-lightnin…
daniellepintz Mar 2, 2022
5970989
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 2, 2022
33b959a
fix gpu test
daniellepintz Mar 2, 2022
4ecc5b0
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz Mar 26, 2022
a6ab1a3
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz Mar 27, 2022
38fc4d6
update final tests
daniellepintz Mar 27, 2022
cf1e981
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz Mar 28, 2022
45fbee6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 28, 2022
d792bf2
fix more tests
daniellepintz Mar 28, 2022
369152f
Merge branch 'accel_con' of github.com:daniellepintz/pytorch-lightnin…
daniellepintz Mar 28, 2022
1a07d7b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 28, 2022
f5db9f0
update dep strings
daniellepintz Mar 28, 2022
97fcdc3
update test_combined_data_loader_validation_test
daniellepintz Mar 28, 2022
54d3f15
mock ipus and tpus
daniellepintz Mar 28, 2022
87761f0
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz Mar 29, 2022
69c1756
update to 1.7 and fix test
daniellepintz Mar 29, 2022
99af06c
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz Mar 29, 2022
97ecfa8
fix tests
daniellepintz Mar 29, 2022
5f93ffc
fix test_v2_0_0_deprecated_tpu_cores
daniellepintz Mar 29, 2022
1d477f0
fix test
daniellepintz Mar 29, 2022
b8e00c5
Merge branch 'master' into accel_con
awaelchli Apr 3, 2022
6763a46
add missing deprecation messages in docs
awaelchli Apr 3, 2022
7dc4b50
update usage in nemo examples
awaelchli Apr 3, 2022
45b85b9
merge master
awaelchli Apr 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Deprecated `ModelIO.on_hpc_{save/load}` in favor of `CheckpointHooks.on_{save/load}_checkpoint` ([#10911](https://github.com/PyTorchLightning/pytorch-lightning/pull/10911))


- Deprecated `num_processes`, `gpus`, `tpu_cores,` and `ipus` from the `Trainer` constructor in favor of using the `accelerator` and `devices` arguments ([#11040](https://github.com/PyTorchLightning/pytorch-lightning/pull/11040))


- Deprecated `Trainer.run_stage` in favor of `Trainer.{fit,validate,test,predict}` ([#11000](https://github.com/PyTorchLightning/pytorch-lightning/pull/11000))


Expand Down
27 changes: 24 additions & 3 deletions pytorch_lightning/trainer/connectors/accelerator_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def _check_device_config_and_set_final_flags(
self._devices_flag = devices

# TODO: Delete this method when num_processes, gpus, ipus and tpu_cores gets removed
self._map_deprecated_devices_specfic_info_to_accelerator_and_device_flag(
self._map_deprecated_devices_specific_info_to_accelerator_and_device_flag(
devices, num_processes, gpus, ipus, tpu_cores
)

Expand All @@ -409,15 +409,36 @@ def _check_device_config_and_set_final_flags(
" `accelerator=('auto'|'tpu'|'gpu'|'ipu'|'cpu')` for the devices mapping"
)

def _map_deprecated_devices_specfic_info_to_accelerator_and_device_flag(
def _map_deprecated_devices_specific_info_to_accelerator_and_device_flag(
self,
devices: Optional[Union[List[int], str, int]],
num_processes: Optional[int],
gpus: Optional[Union[List[int], str, int]],
ipus: Optional[int],
tpu_cores: Optional[Union[List[int], str, int]],
) -> None:
"""Sets the `devices_flag` and `accelerator_flag` based on num_processes, gpus, ipus, tpu_cores."""
"""Emit deprecation warnings for num_processes, gpus, ipus, tpu_cores and set the `devices_flag` and
`accelerator_flag`."""
if num_processes:
rank_zero_deprecation(
f"Setting `Trainer(num_processes={num_processes})` is deprecated in v1.6 and will be removed"
f" in v2.0. Please use `Trainer(accelerator='cpu', devices={num_processes})` instead."
)
if gpus:
rank_zero_deprecation(
f"Setting `Trainer(gpus={gpus})` is deprecated in v1.6 and will be removed"
f" in v2.0. Please use `Trainer(accelerator='gpu', devices={gpus})` instead."
daniellepintz marked this conversation as resolved.
Show resolved Hide resolved
)
if tpu_cores:
rank_zero_deprecation(
f"Setting `Trainer(tpu_cores={tpu_cores})` is deprecated in v1.6 and will be removed"
f" in v2.0. Please use `Trainer(accelerator='tpu', devices={tpu_cores})` instead."
daniellepintz marked this conversation as resolved.
Show resolved Hide resolved
)
if ipus:
rank_zero_deprecation(
f"Setting `Trainer(ipus={ipus})` is deprecated in v1.6 and will be removed"
f" in v2.0. Please use `Trainer(accelerator='ipu', devices={ipus})` instead."
)
self._gpus: Optional[Union[List[int], str, int]] = gpus
self._tpu_cores: Optional[Union[List[int], str, int]] = tpu_cores
deprecated_devices_specific_flag = num_processes or gpus or ipus or tpu_cores
Expand Down
24 changes: 20 additions & 4 deletions pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ def __init__(
gradient_clip_algorithm: Optional[str] = None,
process_position: int = 0,
num_nodes: int = 1,
num_processes: Optional[int] = None,
num_processes: Optional[int] = None, # TODO: Remove in 2.0
devices: Optional[Union[List[int], str, int]] = None,
gpus: Optional[Union[List[int], str, int]] = None,
gpus: Optional[Union[List[int], str, int]] = None, # TODO: Remove in 2.0
auto_select_gpus: bool = False,
tpu_cores: Optional[Union[List[int], str, int]] = None,
ipus: Optional[int] = None,
tpu_cores: Optional[Union[List[int], str, int]] = None, # TODO: Remove in 2.0
ipus: Optional[int] = None, # TODO: Remove in 2.0
log_gpu_memory: Optional[str] = None, # TODO: Remove in 1.7
progress_bar_refresh_rate: Optional[int] = None, # TODO: remove in v1.7
enable_progress_bar: bool = True,
Expand Down Expand Up @@ -278,6 +278,10 @@ def __init__(
gpus: Number of GPUs to train on (int) or which GPUs to train on (list or str) applied per node
Default: ``None``.

.. deprecated:: v1.6
``gpus`` has been deprecated in v1.6 and will be removed in v2.0.
Please use ``accelerator='gpu'`` and ``devices=x`` instead.

gradient_clip_val: The value at which to clip gradients. Passing ``gradient_clip_val=None`` disables
gradient clipping. If using Automatic Mixed Precision (AMP), the gradients will be unscaled before.
Default: ``None``.
Expand Down Expand Up @@ -378,6 +382,10 @@ def __init__(
num_processes: Number of processes for distributed training with ``accelerator="cpu"``.
Default: ``1``.

.. deprecated:: v1.6
``num_processes`` has been deprecated in v1.6 and will be removed in v2.0.
Please use ``accelerator='cpu'`` and ``devices=x`` instead.

num_sanity_val_steps: Sanity check runs n validation batches before starting the training routine.
Set it to `-1` to run all batches in all validation dataloaders.
Default: ``2``.
Expand Down Expand Up @@ -418,9 +426,17 @@ def __init__(
tpu_cores: How many TPU cores to train on (1 or 8) / Single TPU to train on (1)
Default: ``None``.

.. deprecated:: v1.6
``tpu_cores`` has been deprecated in v1.6 and will be removed in v2.0.
Please use ``accelerator='tpu'`` and ``devices=x`` instead.

ipus: How many IPUs to train on.
Default: ``None``.

.. deprecated:: v1.6
``ipus`` has been deprecated in v1.6 and will be removed in v2.0.
Please use ``accelerator='ipu'`` and ``devices=x`` instead.

track_grad_norm: -1 no tracking. Otherwise tracks that p-norm. May be set to 'inf' infinity-norm. If using
Automatic Mixed Precision (AMP), the gradients will be unscaled before logging them.
Default: ``-1``.
Expand Down
29 changes: 28 additions & 1 deletion tests/deprecated_api/test_remove_2-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,39 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test deprecated functionality which will be removed in v2.0."""
"""Test deprecated functionality which will be removed in v2.0.0."""
from unittest import mock

import pytest

from pytorch_lightning import Trainer
from tests.callbacks.test_callbacks import OldStatefulCallback
from tests.helpers import BoringModel
from tests.helpers.runif import RunIf


def test_v2_0_0_deprecated_num_processes(tmpdir):
with pytest.deprecated_call(match=r"is deprecated in v1.6 and will be removed in v2.0."):
_ = Trainer(default_root_dir=tmpdir, num_processes=2)


@mock.patch("torch.cuda.is_available", return_value=True)
@mock.patch("torch.cuda.device_count", return_value=2)
def test_v2_0_0_deprecated_gpus(mock_is_available, mock_device_count, tmpdir):
with pytest.deprecated_call(match=r"is deprecated in v1.6 and will be removed in v2.0."):
_ = Trainer(default_root_dir=tmpdir, gpus=2)


@RunIf(tpu=True)
daniellepintz marked this conversation as resolved.
Show resolved Hide resolved
def test_v2_0_0_deprecated_tpu_cores(tmpdir):
with pytest.deprecated_call(match=r"is deprecated in v1.6 and will be removed in v2.0."):
_ = Trainer(default_root_dir=tmpdir, tpu_cores=1)


@RunIf(ipu=True)
def test_v2_0_0_deprecated_ipus(tmpdir):
with pytest.deprecated_call(match=r"is deprecated in v1.6 and will be removed in v2.0."):
_ = Trainer(default_root_dir=tmpdir, ipus=2)


def test_v2_0_resume_from_checkpoint_trainer_constructor(tmpdir):
Expand Down