Skip to content

Error messages for unsupported Trainer attributes #15059

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 34 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6dc7542
Revert "Remove deprecated device attributes from Trainer (#14829)"
awaelchli Oct 10, 2022
a3243ef
update
awaelchli Oct 10, 2022
66dff01
reset
awaelchli Oct 10, 2022
af00bf0
reset changelog
awaelchli Oct 10, 2022
dda8d75
fix
awaelchli Oct 10, 2022
ac03cfd
use_amp
awaelchli Oct 10, 2022
0300483
use amp
awaelchli Oct 10, 2022
c5089ea
Merge branch 'master' into feature/remove/trainer-attrs
awaelchli Oct 10, 2022
1231cf9
more
awaelchli Oct 10, 2022
1bb640d
x
awaelchli Oct 10, 2022
f53cffd
more
awaelchli Oct 10, 2022
955e014
Introduce the graveyard
carmocca Oct 10, 2022
24465fd
WIP
carmocca Oct 10, 2022
1665aa1
Merge branch 'feat/graveyard' into feature/remove/trainer-attrs
awaelchli Oct 10, 2022
ce118dc
trainer graveyard
awaelchli Oct 10, 2022
fd1188f
graveyard for module
awaelchli Oct 10, 2022
e9ed4db
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2022
ba7c48e
methods
awaelchli Oct 10, 2022
4d62492
Merge branch 'feature/remove/trainer-methods' into feature/remove/tra…
awaelchli Oct 10, 2022
421482a
methods
awaelchli Oct 10, 2022
4165239
methods
awaelchli Oct 10, 2022
6a8fc4d
imports stuff
awaelchli Oct 10, 2022
ad66015
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2022
b96efda
Merge branch 'master' into feature/remove/trainer-attrs
awaelchli Oct 11, 2022
47d6a1b
Merge branch 'master' into feature/remove/trainer-attrs
awaelchli Oct 11, 2022
599b012
fix graveyard
awaelchli Oct 11, 2022
1d17906
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2022
239daea
unused import
awaelchli Oct 11, 2022
afd967e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2022
6034dd9
Update src/pytorch_lightning/_graveyard/__init__.py
justusschock Oct 11, 2022
1b21e30
comment for borda
awaelchli Oct 11, 2022
a7ef8dc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2022
14a1969
ain't nobody got time for this
awaelchli Oct 11, 2022
ed07b5a
I'm done. stupid nonsense
awaelchli Oct 11, 2022
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
14 changes: 14 additions & 0 deletions src/pytorch_lightning/core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,20 @@ def loggers(self) -> List[Logger]:
"""Reference to the list of loggers in the Trainer."""
return self.trainer.loggers if self._trainer else []

@property
def use_amp(self) -> bool:
raise AttributeError(
"`LightningModule.use_amp` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.amp_backend`.",
)

@use_amp.setter
def use_amp(self, use_amp: bool) -> None:
raise AttributeError(
"`LightningModule.use_amp` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.amp_backend`.",
)

def _call_batch_hook(self, hook_name: str, *args: Any) -> Any:
if self._trainer:
datahook_selector = self._trainer._data_connector._datahook_selector
Expand Down
49 changes: 49 additions & 0 deletions src/pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,55 @@ def logged_metrics(self) -> _OUT_DICT:
def progress_bar_metrics(self) -> _PBAR_DICT:
return self._logger_connector.progress_bar_metrics

@property
def gpus(self) -> Optional[Union[List[int], str, int]]:
raise AttributeError(
"`Trainer.gpus` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.num_devices` or `Trainer.device_ids` to get device information instead."
)

@property
def root_gpu(self) -> Optional[int]:
raise AttributeError(
"`Trainer.root_gpu` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.strategy.root_device.index` instead."
)

@property
def tpu_cores(self) -> int:
raise AttributeError(
"`Trainer.tpu_cores` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.num_devices` instead."
)

@property
def ipus(self) -> int:
raise AttributeError(
"`Trainer.ipus` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.num_devices` instead."
)

@property
def num_gpus(self) -> int:
raise AttributeError(
"`Trainer.num_gpus` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.num_devices` instead."
)

@property
def devices(self) -> int:
raise AttributeError(
"`Trainer.devices` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.num_devices` or `Trainer.device_ids` to get device information instead."
)

@property
def use_amp(self) -> bool:
raise AttributeError(
"`Trainer.use_amp` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.amp_backend`.",
)

@property
def _results(self) -> Optional[_ResultCollection]:
active_loop = self._active_loop
Expand Down
30 changes: 30 additions & 0 deletions tests/tests_pytorch/deprecated_api/test_remove_2-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,33 @@ def test_v2_0_0_deprecated_mc_save_checkpoint():
match=r"ModelCheckpoint.save_checkpoint\(\)` was deprecated in v1.6 and is no longer supported as of 1.8.",
):
mc.save_checkpoint(trainer)


@pytest.mark.parametrize("attribute", ["gpus", "num_gpus", "root_gpu", "devices", "tpu_cores", "ipus"])
def test_v2_0_0_trainer_unsupported_device_attributes(attribute):
trainer = Trainer()
with pytest.raises(
AttributeError, match=f"`Trainer.{attribute}` was deprecated in v1.6 and is no longer accessible as of v1.8."
):
getattr(trainer, attribute)


def test_v2_0_0_unsupported_use_amp():
trainer = Trainer()
with pytest.raises(
AttributeError, match=f"`Trainer.use_amp` was deprecated in v1.6 and is no longer accessible as of v1.8."
):
_ = trainer.use_amp

model = BoringModel()
with pytest.raises(
AttributeError,
match=f"`LightningModule.use_amp` was deprecated in v1.6 and is no longer accessible as of v1.8.",
):
_ = model.use_amp

with pytest.raises(
AttributeError,
match=f"`LightningModule.use_amp` was deprecated in v1.6 and is no longer accessible as of v1.8.",
):
model.use_amp = False