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 30 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
15 changes: 15 additions & 0 deletions src/pytorch_lightning/_graveyard/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

import pytorch_lightning._graveyard.trainer # noqa: F401
import pytorch_lightning._graveyard.training_type # noqa: F401
32 changes: 32 additions & 0 deletions src/pytorch_lightning/_graveyard/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

from pytorch_lightning import LightningModule


def _use_amp(_: LightningModule) -> 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 _use_amp_setter(_: LightningModule, __: 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`.",
)


LightningModule.use_amp = property(fget=_use_amp, fset=_use_amp_setter)
171 changes: 171 additions & 0 deletions src/pytorch_lightning/_graveyard/trainer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

from typing import Any, Optional

from pytorch_lightning import Trainer


def _gpus(_: Trainer) -> None:
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."
)


def _root_gpu(_: Trainer) -> None:
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."
)


def _tpu_cores(_: Trainer) -> None:
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."
)


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


def _num_gpus(_: Trainer) -> None:
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."
)


def _devices(_: Trainer) -> None:
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."
)


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


def _weights_save_path(_: Trainer) -> None:
raise AttributeError("`Trainer.weights_save_path` was deprecated in v1.6 and is no longer accessible as of v1.8.")


def _lightning_optimizers(_: Trainer) -> None:
raise AttributeError(
"`Trainer.lightning_optimizers` was deprecated in v1.6 and is no longer accessible as of v1.8."
)


def _should_rank_save_checkpoint(_: Trainer) -> None:
raise AttributeError(
"`Trainer.should_rank_save_checkpoint` was deprecated in v1.6 and is no longer accessible as of v1.8.",
)


def _validated_ckpt_path(_: Trainer) -> None:
raise AttributeError(
"The `Trainer.validated_ckpt_path` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.ckpt_path` instead."
)


def _validated_ckpt_path_setter(_: Trainer, __: Optional[str]) -> None:
raise AttributeError(
"The `Trainer.validated_ckpt_path` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.ckpt_path` instead."
)


def _tested_ckpt_path(_: Trainer) -> None:
raise AttributeError(
"The `Trainer.tested_ckpt_path` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.ckpt_path` instead."
)


def _tested_ckpt_path_setter(_: Trainer, __: Optional[str]) -> None:
raise AttributeError(
"The `Trainer.tested_ckpt_path` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.ckpt_path` instead."
)


def _predicted_ckpt_path(_: Trainer) -> None:
raise AttributeError(
"The `Trainer.predicted_ckpt_path` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.ckpt_path` instead."
)


def _predicted_ckpt_path_setter(_: Trainer, __: Optional[str]) -> None:
raise AttributeError(
"The `Trainer.predicted_ckpt_path` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `Trainer.ckpt_path` instead."
)


def _verbose_evaluate(_: Trainer) -> None:
raise AttributeError(
"The `Trainer.verbose_evaluate` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `trainer.{validate,test}_loop.verbose` instead.",
)


def _verbose_evaluate_setter(_: Trainer, __: bool) -> None:
raise AttributeError(
"The `Trainer.verbose_evaluate` was deprecated in v1.6 and is no longer accessible as of v1.8."
" Please use `trainer.{validate,test}_loop.verbose` instead.",
)


def _run_stage(_: Trainer) -> None:
raise NotImplementedError(
"`Trainer.run_stage` was deprecated in v1.6 and is no longer supported as of v1.8."
" Please use `Trainer.{fit,validate,test,predict}` instead."
)


def _call_hook(_: Trainer, *__: Any, **___: Any) -> Any:
raise NotImplementedError("`Trainer.call_hook` was deprecated in v1.6 and is no longer supported as of v1.8.")


# Properties/Attributes
Trainer.gpus = property(_gpus)
Trainer.root_gpu = property(_root_gpu)
Trainer.tpu_cores = property(_tpu_cores)
Trainer.ipus = property(_ipus)
Trainer.num_gpus = property(_num_gpus)
Trainer.devices = property(_devices)
Trainer.use_amp = property(_use_amp)
Trainer.weights_save_path = property(_weights_save_path)
Trainer.lightning_optimizers = property(_lightning_optimizers)
Trainer.should_rank_save_checkpoint = property(_should_rank_save_checkpoint)
Trainer.validated_ckpt_path = property(fget=_validated_ckpt_path, fset=_validated_ckpt_path_setter)
Trainer.tested_ckpt_path = property(fget=_tested_ckpt_path, fset=_tested_ckpt_path_setter)
Trainer.predicted_ckpt_path = property(fget=_predicted_ckpt_path, fset=_predicted_ckpt_path_setter)
Trainer.verbose_evaluate = property(fget=_verbose_evaluate, fset=_verbose_evaluate_setter)


# Methods
Trainer.run_stage = _run_stage
Trainer.call_hook = _call_hook
14 changes: 14 additions & 0 deletions src/pytorch_lightning/_graveyard/training_type.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

import sys
from typing import Any

Expand Down
Empty file.
31 changes: 31 additions & 0 deletions tests/tests_pytorch/graveyard/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
import pytest

from pytorch_lightning.demos.boring_classes import BoringModel


def test_v2_0_0_lightning_module_unsupported_use_amp():
model = BoringModel()
with pytest.raises(
AttributeError,
match="`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="`LightningModule.use_amp` was deprecated in v1.6 and is no longer accessible as of v1.8.",
):
model.use_amp = False
77 changes: 77 additions & 0 deletions tests/tests_pytorch/graveyard/test_trainer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

import pytest

from pytorch_lightning import Trainer


@pytest.mark.parametrize(
"attribute",
[
"gpus",
"num_gpus",
"root_gpu",
"devices",
"tpu_cores",
"ipus",
"use_amp",
"weights_save_path",
"lightning_optimizers",
"should_rank_save_checkpoint",
"validated_ckpt_path",
"tested_ckpt_path",
"predicted_ckpt_path",
"verbose_evaluate",
],
)
def test_v2_0_0_unsupported_getters(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)


@pytest.mark.parametrize(
"attribute",
[
"validated_ckpt_path",
"tested_ckpt_path",
"predicted_ckpt_path",
"verbose_evaluate",
],
)
def test_v2_0_0_unsupported_setters(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."
):
setattr(trainer, attribute, None)


def test_v2_0_0_unsupported_run_stage():
trainer = Trainer()
with pytest.raises(
NotImplementedError, match="`Trainer.run_stage` was deprecated in v1.6 and is no longer supported as of v1.8."
):
trainer.run_stage()


def test_v2_0_0_unsupported_call_hook():
trainer = Trainer()
with pytest.raises(
NotImplementedError, match="`Trainer.call_hook` was deprecated in v1.6 and is no longer supported as of v1.8."
):
trainer.call_hook("test_hook")