Error messages for unsupported Trainer attributes (#15059)
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com> Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
This commit is contained in:
parent
c5cc2b0888
commit
f1509537ec
|
@ -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
|
||||
import pytorch_lightning._graveyard.training_type # noqa: F401
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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")
|
Loading…
Reference in New Issue