Skip to content

fix: rank=0 falsy-value in ParameterServer.__init__ - #99

Open
Jackie2049 wants to merge 1 commit into
MoonshotAI:mainfrom
Jackie2049:fix/rank-zero-falsy
Open

fix: rank=0 falsy-value in ParameterServer.__init__#99
Jackie2049 wants to merge 1 commit into
MoonshotAI:mainfrom
Jackie2049:fix/rank-zero-falsy

Conversation

@Jackie2049

Copy link
Copy Markdown

Problem

In ParameterServer.__init__(), rank=0 is falsy in Python, so rank or int(os.environ["RANK"]) always evaluates to the environment variable. If RANK is not set in the calling process (common in standalone/debug/test setups), a KeyError is raised despite the caller explicitly passing rank=0.

Fix

Replace the falsy or guard with an explicit None check:

self._rank = rank if rank is not None else int(os.environ["RANK"])

Key Change

File Line Change
checkpoint_engine/ps.py 191 rank or int(os.environ["RANK"])rank if rank is not None else int(os.environ["RANK"])

Testing

Unit tests for rank=0, rank=None, and rank=5 all pass on 8×RTX 4090 (56/56).

`self._rank = rank or int(os.environ["RANK"])` evaluates `rank=0` as
falsy, so a rank-0 process always falls back to the environment variable.
If `RANK` is unset in that process, it raises `KeyError` instead of using
the zero passed by the caller.

Fix: use `rank if rank is not None else ...` — only fall back to the
env when the caller explicitly passes `None`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant