Skip to content
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

[WIP] Fail more nicely when an error occurs in Fabric.rank_zero_first() #19540

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/lightning/fabric/fabric.py
Expand Up @@ -639,13 +639,22 @@ def rank_zero_first(self, local: bool = False) -> Generator:

"""
rank = self.local_rank if local else self.global_rank
exception: Optional[Exception] = None
with _InfiniteBarrier() as barrier:
if rank > 0:
barrier()
yield

try:
yield
except Exception as e:
exception = e

if rank == 0:
barrier()

if exception is not None:
raise exception

def no_backward_sync(self, module: _FabricModule, enabled: bool = True) -> ContextManager:
r"""Skip gradient synchronization during backward to avoid redundant communication overhead.

Expand Down