Fix distributed deadlock when wandb.init hangs on rank 0#249
Open
Fix distributed deadlock when wandb.init hangs on rank 0#249
Conversation
If rank 0's wandb.init() hangs (dead wandb-service daemon, missing API key, or unreachable wandb.ai), the other ranks race ahead into the next collective — the Gloo new_group() inside dcp.async_save during fwd_state.save(state0) — and the whole job deadlocks. The hang surfaces as ranks 1..N stuck on a collective rather than rank 0 stuck in wandb, which is maximally misleading. Two changes: * bergson/utils/logging.py: bound wandb.init via WANDB__SERVICE_WAIT=30 and WANDB_INIT_TIMEOUT=60 (os.environ.setdefault, user-overridable), and catch wandb.init failures so we degrade to a no-op log_fn with a UserWarning instead of propagating. A broken wandb setup now means "no logging" instead of "hang the run". * bergson/magic/cli.py: dist.barrier() right after the rank-0-only wandb_log_fn call. The barrier doesn't fix a hung wandb but ensures the hang attributes to rank 0 inside wandb instead of ranks 1..N stuck on a Gloo collective. Verified by failure injection (WANDB_API_KEY=bogus_test_key) on an 8-GPU magic run: wandb.init raises AuthenticationError, the warning fires, and training proceeds to completion. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
f3f0eef to
fdd2a74
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
If wandb.init failed, a bergson run would stall with uninformative logs. Two changes
wandb.initviaWANDB__SERVICE_WAIT=30/WANDB_INIT_TIMEOUT=60defaults (user-overridable), and degrade to a no-oplog_fnwith aUserWarningifwandb.initfails — a broken wandb setup means "no logging" instead of "hang the run".dist.barrier()right after the rank-0-onlywandb_log_fncall inbergson/magic/cli.py worker(...)so a future hungwandb.initattributes to rank 0 inside wandb instead of ranks 1..N stuck on the next Gloo collective (dist.new_groupinsidefwd_state.save).The second part might be excessively defensive.
Test plan
pytest tests/test_log_fn.py -v— 4/4 pass, including newtest_wandb_log_fn_falls_back_when_init_failspytest tests/test_magic.py— 3/3 pass (single-process path where the new barrier is a no-op)WANDB_API_KEY=bogus_test_key bergson magic configs/...→UserWarningfires from rank 0, run completes cleanly🤖 Generated with Claude Code, edited by David