Skip to content

Commit 2e3d85a

Browse files
carmoccaBorda
andauthored
Remove deprecated rank zero utilities (#14471)
Co-authored-by: Jirka Borovec <[email protected]>
1 parent 626827c commit 2e3d85a

File tree

6 files changed

+28
-99
lines changed

6 files changed

+28
-99
lines changed

src/pytorch_lightning/CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
110110
- Removed deprecated support for old torchtext versions ([#14375](https://github.com/Lightning-AI/lightning/pull/14375))
111111

112112

113+
- Remove the deprecated ([#14471](https://github.com/Lightning-AI/lightning/pull/14471))
114+
* `pytorch_lightning.utilities.distributed.rank_zero_only` in favor of `pytorch_lightning.utilities.rank_zero.rank_zero_only`
115+
* `pytorch_lightning.utilities.distributed.rank_zero_debug` in favor of `pytorch_lightning.utilities.rank_zero.rank_zero_debug`
116+
* `pytorch_lightning.utilities.distributed.rank_zero_info` in favor of `pytorch_lightning.utilities.rank_zero.rank_zero_info`
117+
* `pytorch_lightning.utilities.warnings.rank_zero_warn` in favor of `pytorch_lightning.utilities.rank_zero.rank_zero_warn`
118+
* `pytorch_lightning.utilities.warnings.rank_zero_deprecation` in favor of `pytorch_lightning.utilities.rank_zero.rank_zero_deprecation`
119+
* `pytorch_lightning.utilities.warnings.LightningDeprecationWarning` in favor of `pytorch_lightning.utilities.rank_zero.LightningDeprecationWarning`
120+
121+
113122
- Removed deprecated `Trainer.num_processes` attribute in favour of `Trainer.num_devices` ([#14423](https://github.com/Lightning-AI/lightning/pull/14423))
114123

115124

@@ -634,7 +643,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
634643
- Deprecated `pytorch_lightning.utilities.distributed.rank_zero_info` in favor of `pytorch_lightning.utilities.rank_zero.rank_zero_info` ([#11747](https://github.com/Lightning-AI/lightning/pull/11747))
635644
- Deprecated `pytorch_lightning.utilities.warnings.rank_zero_warn` in favor of `pytorch_lightning.utilities.rank_zero.rank_zero_warn` ([#11747](https://github.com/Lightning-AI/lightning/pull/11747))
636645
- Deprecated `pytorch_lightning.utilities.warnings.rank_zero_deprecation` in favor of `pytorch_lightning.utilities.rank_zero.rank_zero_deprecation` ([#11747](https://github.com/Lightning-AI/lightning/pull/11747))
637-
- Deprecated `pytorch_lightning.utilities.warnings.LightningDeprecationWarning` in favor of `pytorch_lightning.utilities.rank_zero.LightningDeprecationWarning`
646+
- Deprecated `pytorch_lightning.utilities.warnings.LightningDeprecationWarning` in favor of `pytorch_lightning.utilities.rank_zero.LightningDeprecationWarning` ([#11747](https://github.com/Lightning-AI/lightning/pull/11747))
638647
- Deprecated `on_pretrain_routine_start` and `on_pretrain_routine_end` callback hooks in favor of `on_fit_start` ([#11794](https://github.com/Lightning-AI/lightning/pull/11794))
639648
- Deprecated `LightningModule.on_pretrain_routine_start` and `LightningModule.on_pretrain_routine_end` hooks in favor of `on_fit_start` ([#12122](https://github.com/Lightning-AI/lightning/pull/12122))
640649
- Deprecated `agg_key_funcs` and `agg_default_func` parameters from `LightningLoggerBase` ([#11871](https://github.com/Lightning-AI/lightning/pull/11871))

src/pytorch_lightning/loggers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import numpy as np
1818

1919
import pytorch_lightning.loggers.logger as logger
20-
from pytorch_lightning.utilities.warnings import rank_zero_deprecation
20+
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation
2121

2222

2323
def rank_zero_experiment(fn: Callable) -> Callable:

src/pytorch_lightning/strategies/parallel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
get_default_process_group_backend_for_device,
3131
ReduceOp,
3232
)
33-
from pytorch_lightning.utilities.warnings import rank_zero_deprecation
33+
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation
3434

3535

3636
class ParallelStrategy(Strategy, ABC):

src/pytorch_lightning/utilities/distributed.py

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323

2424
import pytorch_lightning as pl
2525
from pytorch_lightning.utilities.imports import _HPU_AVAILABLE, _TPU_AVAILABLE
26-
from pytorch_lightning.utilities.rank_zero import rank_zero_debug as new_rank_zero_debug
2726
from pytorch_lightning.utilities.rank_zero import rank_zero_only # noqa: F401
28-
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation
29-
from pytorch_lightning.utilities.rank_zero import rank_zero_info as new_rank_zero_info
27+
from pytorch_lightning.utilities.rank_zero import rank_zero_debug, rank_zero_deprecation, rank_zero_info
3028

3129
if _TPU_AVAILABLE:
3230
import torch_xla.core.xla_model as xm
@@ -160,7 +158,7 @@ def sync_ddp(result: Tensor, group: Optional[Any] = None, reduce_op: Optional[Un
160158
is_hpu_backend = os.environ.get("HCCL_DISTRIBUTED_BACKEND") == "1"
161159
if is_hpu_backend:
162160
if (result.type() == "torch.LongTensor") or (result.type() == "torch.hpu.LongTensor"):
163-
new_rank_zero_info("Long tensor unsupported on HPU, casting to float")
161+
rank_zero_info("Long tensor unsupported on HPU, casting to float")
164162
result = result.float()
165163

166164
# sync all processes before reduction
@@ -312,12 +310,12 @@ def register_ddp_comm_hook(
312310
ddp_comm_hook: Callable = ddp_comm_hook
313311

314312
if ddp_comm_wrapper is not None:
315-
new_rank_zero_info(
313+
rank_zero_info(
316314
f"DDP comm wrapper is provided, apply {ddp_comm_wrapper.__qualname__}({ddp_comm_hook.__qualname__})."
317315
)
318316
ddp_comm_hook = ddp_comm_wrapper(ddp_comm_hook)
319317

320-
new_rank_zero_debug(f"Registering DDP comm hook: {ddp_comm_hook.__qualname__}.")
318+
rank_zero_debug(f"Registering DDP comm hook: {ddp_comm_hook.__qualname__}.")
321319
model.register_comm_hook(state=ddp_comm_state, hook=ddp_comm_hook) # type: ignore[operator]
322320

323321

@@ -374,7 +372,7 @@ def init_dist_connection(
374372
torch.distributed.init_process_group(torch_distributed_backend, rank=global_rank, world_size=world_size, **kwargs)
375373

376374
# on rank=0 let everyone know training is starting
377-
new_rank_zero_info(
375+
rank_zero_info(
378376
f"{'-' * 100}\n"
379377
f"distributed_backend={torch_distributed_backend}\n"
380378
f"All distributed processes registered. Starting with {world_size} processes\n"
@@ -402,21 +400,3 @@ def _collect_states_on_rank_zero(state: Dict[str, Any]) -> Dict[int, Any]:
402400
if not distributed_available():
403401
return {0: state}
404402
return {rank: _broadcast_object_list(state, rank) for rank in range(torch.distributed.get_world_size())}
405-
406-
407-
def rank_zero_info(*args: Any, **kwargs: Any) -> Any:
408-
rank_zero_deprecation(
409-
"pytorch_lightning.utilities.distributed.rank_zero_info has been deprecated in v1.6"
410-
" and will be removed in v1.8."
411-
" Use the equivalent function from the pytorch_lightning.utilities.rank_zero module instead."
412-
)
413-
return new_rank_zero_info(*args, **kwargs)
414-
415-
416-
def rank_zero_debug(*args: Any, **kwargs: Any) -> Any:
417-
rank_zero_deprecation(
418-
"pytorch_lightning.utilities.distributed.rank_zero_debug has been deprecated in v1.6"
419-
" and will be removed in v1.8."
420-
" Use the equivalent function from the pytorch_lightning.utilities.rank_zero module instead."
421-
)
422-
return new_rank_zero_debug(*args, **kwargs)

src/pytorch_lightning/utilities/warnings.py

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
"""Warning-related utilities."""
15-
1615
import warnings
1716
from typing import Any
1817

19-
from pytorch_lightning.utilities.rank_zero import LightningDeprecationWarning as NewLightningDeprecationWarning
20-
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation as new_rank_zero_deprecation
21-
from pytorch_lightning.utilities.rank_zero import rank_zero_info as new_rank_zero_info
22-
from pytorch_lightning.utilities.rank_zero import rank_zero_warn as new_rank_zero_warn
18+
from pytorch_lightning.utilities.rank_zero import (
19+
LightningDeprecationWarning,
20+
rank_zero_deprecation,
21+
rank_zero_info,
22+
rank_zero_warn,
23+
)
2324

2425
# enable our warnings
25-
warnings.simplefilter("default", category=NewLightningDeprecationWarning)
26+
27+
warnings.simplefilter("default", category=LightningDeprecationWarning)
2628

2729

2830
class PossibleUserWarning(UserWarning):
@@ -33,42 +35,14 @@ class WarningCache(set):
3335
def warn(self, message: str, stacklevel: int = 5, **kwargs: Any) -> None:
3436
if message not in self:
3537
self.add(message)
36-
new_rank_zero_warn(message, stacklevel=stacklevel, **kwargs)
38+
rank_zero_warn(message, stacklevel=stacklevel, **kwargs)
3739

3840
def deprecation(self, message: str, stacklevel: int = 5, **kwargs: Any) -> None:
3941
if message not in self:
4042
self.add(message)
41-
new_rank_zero_deprecation(message, stacklevel=stacklevel, **kwargs)
43+
rank_zero_deprecation(message, stacklevel=stacklevel, **kwargs)
4244

4345
def info(self, message: str, stacklevel: int = 5, **kwargs: Any) -> None:
4446
if message not in self:
4547
self.add(message)
46-
new_rank_zero_info(message, stacklevel=stacklevel, **kwargs)
47-
48-
49-
def rank_zero_warn(*args: Any, **kwargs: Any) -> Any:
50-
new_rank_zero_deprecation(
51-
"pytorch_lightning.utilities.warnings.rank_zero_warn has been deprecated in v1.6"
52-
" and will be removed in v1.8."
53-
" Use the equivalent function from the pytorch_lightning.utilities.rank_zero module instead."
54-
)
55-
return new_rank_zero_warn(*args, **kwargs)
56-
57-
58-
def rank_zero_deprecation(*args: Any, **kwargs: Any) -> Any:
59-
new_rank_zero_deprecation(
60-
"pytorch_lightning.utilities.warnings.rank_zero_deprecation has been deprecated in v1.6"
61-
" and will be removed in v1.8."
62-
" Use the equivalent function from the pytorch_lightning.utilities.rank_zero module instead."
63-
)
64-
return new_rank_zero_deprecation(*args, **kwargs)
65-
66-
67-
class LightningDeprecationWarning(NewLightningDeprecationWarning):
68-
def __init__(self, *args: Any, **kwargs: Any) -> None:
69-
new_rank_zero_deprecation(
70-
"pytorch_lightning.utilities.warnings.LightningDeprecationWarning has been deprecated in v1.6"
71-
" and will be removed in v1.8."
72-
" Use the equivalent class from the pytorch_lightning.utilities.rank_zero module instead."
73-
)
74-
super().__init__(*args, **kwargs)
48+
rank_zero_info(message, stacklevel=stacklevel, **kwargs)

tests/tests_pytorch/deprecated_api/test_remove_1-8.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -275,40 +275,6 @@ def on_pretrain_routine_end(self, *args, **kwargs):
275275
trainer.fit(model)
276276

277277

278-
def test_v1_8_0_rank_zero_imports():
279-
280-
import warnings
281-
282-
from pytorch_lightning.utilities.distributed import rank_zero_debug, rank_zero_info
283-
from pytorch_lightning.utilities.warnings import LightningDeprecationWarning, rank_zero_deprecation, rank_zero_warn
284-
285-
with pytest.deprecated_call(
286-
match="pytorch_lightning.utilities.distributed.rank_zero_debug has been deprecated in v1.6"
287-
" and will be removed in v1.8."
288-
):
289-
rank_zero_debug("foo")
290-
with pytest.deprecated_call(
291-
match="pytorch_lightning.utilities.distributed.rank_zero_info has been deprecated in v1.6"
292-
" and will be removed in v1.8."
293-
):
294-
rank_zero_info("foo")
295-
with pytest.deprecated_call(
296-
match="pytorch_lightning.utilities.warnings.rank_zero_warn has been deprecated in v1.6"
297-
" and will be removed in v1.8."
298-
):
299-
rank_zero_warn("foo")
300-
with pytest.deprecated_call(
301-
match="pytorch_lightning.utilities.warnings.rank_zero_deprecation has been deprecated in v1.6"
302-
" and will be removed in v1.8."
303-
):
304-
rank_zero_deprecation("foo")
305-
with pytest.deprecated_call(
306-
match="pytorch_lightning.utilities.warnings.LightningDeprecationWarning has been deprecated in v1.6"
307-
" and will be removed in v1.8."
308-
):
309-
warnings.warn("foo", LightningDeprecationWarning, stacklevel=5)
310-
311-
312278
def test_v1_8_0_on_before_accelerator_backend_setup(tmpdir):
313279
class TestCallback(Callback):
314280
def on_before_accelerator_backend_setup(self, *args, **kwargs):

0 commit comments

Comments
 (0)