Skip to content

chore(claude): learn from #237#241

Closed
claude[bot] wants to merge 1 commit into
mainfrom
claude/learn-from-237
Closed

chore(claude): learn from #237#241
claude[bot] wants to merge 1 commit into
mainfrom
claude/learn-from-237

Conversation

@claude
Copy link
Copy Markdown
Contributor

@claude claude Bot commented May 4, 2026

What this does

Adds a fourth hard rule to CLAUDE.md about isolating construction-time RNG draws — the durable lesson from the review on #237.

The reviewer on #237 flagged that model.resize_token_embeddings in ensure_loc_tokens random-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 a torch.random.fork_rng snapshot + fixed _LOC_EMBEDDING_INIT_SEED re-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 fresh nn.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 at tokenizer_utils.py::ensure_loc_tokens as the canonical shape.

No stale rules were spotted in the #237 diff (CLAUDE.md does not reference the deleted pixmo.py or 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.md is clean.

How to checkout & try? (for the reviewer)

gh pr checkout <this-pr>
git diff main -- CLAUDE.md

Checklist

  • I have added Google-style docstrings to important functions and ensured function parameters are typed.
  • My PR includes policy-related changes.
    • If the above is checked: I have run the GPU pytests (pytest -m "gpu") and regression tests.

🤖 Generated with Claude Code

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>
@shuheng-liu
Copy link
Copy Markdown
Member

Doesn't worth an entry in CLAUDE.md

@shuheng-liu shuheng-liu closed this May 4, 2026
@shuheng-liu shuheng-liu deleted the claude/learn-from-237 branch May 5, 2026 03:27
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