Seed all four RNGs on cold start to match checkpoint coverage#60
Open
Seed all four RNGs on cold start to match checkpoint coverage#60
Conversation
_set_seed() only called torch.manual_seed, leaving Python random and NumPy's legacy global RNG uninitialized. Warm resume restores all four generators (python, numpy, torch_cpu, torch_cuda) via get_rng_state, so cold-start runs had strictly weaker reproducibility than resumed ones. Any code path using random.random() or np.random.rand() on rank >0 picked up process-level entropy rather than the configured seed. Also fix a latent flake in test_perfect_model_low_loss: the test relied on sum(embed(0)) landing positive by luck from global RNG state. Zero the embedding and set row 0 to ones so the assertion is deterministic regardless of test ordering.
Naeemkh
requested changes
Apr 22, 2026
Member
Naeemkh
left a comment
There was a problem hiding this comment.
Not sure if importing with _ is a good idea. Please double check.
|
|
||
| import logging | ||
| import os | ||
| import random as _random |
| import random as _random | ||
| from datetime import timedelta | ||
|
|
||
| import numpy as _np |
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
_set_seed, addrandom.seed(effective_seed)andnumpy.random.seed(effective_seed)so Python'srandomand NumPy's legacy global RNG are deterministic on cold start. The checkpoint path already captures and restores both, so warm resume is no longer stricter than cold start.torch.cuda.manual_seedfortorch.cuda.manual_seed_allto cover every visible device, not just the current one.Drive-by:
tests/unit/test_eval.py::TestRunEval::test_perfect_model_low_lossrelied onsum(embed(0))landing positive from inherited global RNG state. Zero the embedding and set row 0 to ones so the assertion is deterministic regardless of test ordering.Closes #59
Test plan
uv run pytest tests/unit/test_distributed_seed.py tests/unit/test_eval.py -v.