chore(claude): learn from #237#241
Closed
claude[bot] wants to merge 1 commit into
Closed
Conversation
Add hard rule #4 on isolating construction-time RNG draws. Reviewer feedback on #237 flagged that `model.resize_token_embeddings` in `ensure_loc_tokens` consumes from the active torch RNG, so the 1024 new Gemma 3 embedding rows would couple to whatever build-order state the caller is in — a silent ordering hazard for hard rule #3 (deterministic seeded reruns). The fix landed as a `fork_rng` snapshot + fixed `_LOC_EMBEDDING_INIT_SEED` around the resize. Lift the pattern into CLAUDE.md so the next contributor adding a similar init-time RNG-consuming helper knows the shape and the rationale. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
|
Doesn't worth an entry in CLAUDE.md |
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.
What this does
Adds a fourth hard rule to
CLAUDE.mdabout isolating construction-time RNG draws — the durable lesson from the review on #237.The reviewer on #237 flagged that
model.resize_token_embeddingsinensure_loc_tokensrandom-inits 1024 new Gemma 3 embedding rows from the active torch RNG, making policy construction depend on whatever RNG state the caller happened to be in. That's a "new ordering hazard for CLAUDE.md hard rule #3" — a refactor that reordered construction or added a new call site would silently break determinism without changing any user-visible config. The fix landed in #237 as atorch.random.fork_rngsnapshot + fixed_LOC_EMBEDDING_INIT_SEEDre-seed around the resize, with a regression test (test_ensure_loc_tokens_does_not_perturb_caller_rng) and a reproducibility test (test_ensure_loc_tokens_resize_is_seed_independent).The same pattern applies to any future helper that draws from the global RNG during model
__init__: a freshnn.init.*on a new sub-module,torch.randn(...)for a buffer, etc. The new rule lifts the precedent into the hard-rules list and points attokenizer_utils.py::ensure_loc_tokensas the canonical shape.No stale rules were spotted in the #237 diff (CLAUDE.md does not reference the deleted
pixmo.pyor any of the touched grounding/pi05/pi06 internals).How it was tested
Documentation-only edit — no code, tests, or build artefacts touched.
pre-commit run --files CLAUDE.mdis clean.How to checkout & try? (for the reviewer)
Checklist
🤖 Generated with Claude Code