-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Changes from all 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 a3243ef
update
awaelchli 66dff01
reset
awaelchli af00bf0
reset changelog
awaelchli dda8d75
fix
awaelchli ac03cfd
use_amp
awaelchli 0300483
use amp
awaelchli c5089ea
Merge branch 'master' into feature/remove/trainer-attrs
awaelchli 1231cf9
more
awaelchli 1bb640d
x
awaelchli f53cffd
more
awaelchli 955e014
Introduce the graveyard
carmocca 24465fd
WIP
carmocca 1665aa1
Merge branch 'feat/graveyard' into feature/remove/trainer-attrs
awaelchli ce118dc
trainer graveyard
awaelchli fd1188f
graveyard for module
awaelchli e9ed4db
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ba7c48e
methods
awaelchli 4d62492
Merge branch 'feature/remove/trainer-methods' into feature/remove/tra…
awaelchli 421482a
methods
awaelchli 4165239
methods
awaelchli 6a8fc4d
imports stuff
awaelchli ad66015
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b96efda
Merge branch 'master' into feature/remove/trainer-attrs
awaelchli 47d6a1b
Merge branch 'master' into feature/remove/trainer-attrs
awaelchli 599b012
fix graveyard
awaelchli 1d17906
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 239daea
unused import
awaelchli afd967e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6034dd9
Update src/pytorch_lightning/_graveyard/__init__.py
justusschock 1b21e30
comment for borda
awaelchli a7ef8dc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 14a1969
ain't nobody got time for this
awaelchli ed07b5a
I'm done. stupid nonsense
awaelchli 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
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 | ||
justusschock marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import pytorch_lightning._graveyard.training_type # noqa: F401 |
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,191 @@ | ||
# 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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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: | ||
# Remove in v2.0.0 | ||
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 |
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,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") |
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.