Skip to content

Remove legacy version check for lightning_utilities >= 0.10 #20823

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ node_modules/
**/events.out.tfevents.*
examples/**/*.png

# instalation artifacts
# installation artifacts
requirements/base.txt

# CI
Expand Down
2 changes: 0 additions & 2 deletions src/lightning/fabric/utilities/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@
_TORCH_LESS_EQUAL_2_6 = compare_version("torch", operator.le, "2.6.0")

_PYTHON_GREATER_EQUAL_3_10_0 = (sys.version_info.major, sys.version_info.minor) >= (3, 10)

_UTILITIES_GREATER_EQUAL_0_10 = compare_version("lightning_utilities", operator.ge, "0.10.0")
34 changes: 2 additions & 32 deletions src/lightning/fabric/utilities/rank_zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

import logging
import os
from functools import wraps
from typing import Callable, Optional, TypeVar, overload
from typing import Optional

import lightning_utilities.core.rank_zero as rank_zero_module

Expand All @@ -29,9 +28,6 @@
rank_zero_info,
rank_zero_warn,
)
from typing_extensions import ParamSpec

from lightning.fabric.utilities.imports import _UTILITIES_GREATER_EQUAL_0_10

rank_zero_module.log = logging.getLogger(__name__)

Expand All @@ -48,33 +44,7 @@ def _get_rank() -> Optional[int]:
return None


if not _UTILITIES_GREATER_EQUAL_0_10:
T = TypeVar("T")
P = ParamSpec("P")

@overload
def rank_zero_only(fn: Callable[P, T]) -> Callable[P, Optional[T]]:
"""Rank zero only."""

@overload
def rank_zero_only(fn: Callable[P, T], default: T) -> Callable[P, T]:
"""Rank zero only."""

def rank_zero_only(fn: Callable[P, T], default: Optional[T] = None) -> Callable[P, Optional[T]]:
@wraps(fn)
def wrapped_fn(*args: P.args, **kwargs: P.kwargs) -> Optional[T]:
rank = getattr(rank_zero_only, "rank", None)
if rank is None:
raise RuntimeError("The `rank_zero_only.rank` needs to be set before use")
if rank == 0:
return fn(*args, **kwargs)
return default

return wrapped_fn

rank_zero_module.rank_zero_only.rank = getattr(rank_zero_module.rank_zero_only, "rank", _get_rank() or 0)
else:
rank_zero_only = rank_zero_module.rank_zero_only
rank_zero_only = rank_zero_module.rank_zero_only

# add the attribute to the function but don't overwrite in case Trainer has already set it
rank_zero_only.rank = getattr(rank_zero_only, "rank", _get_rank() or 0)
Expand Down
Loading