fix(league): use nnx.clone so frozen snapshots are isolated from source#17
Merged
Conversation
clone_frozen_model used nnx.split + nnx.merge, which round-tripped the source's Variable wrappers into the new model. A later nnx.update on the source would rewrite the arrays inside those shared wrappers, so the "frozen" snapshot silently tracked the latest weights and league play degenerated into self-play against the current model. Switch to nnx.clone (default variables=True), which produces independent Variable wrappers backed by the same (immutable) JAX arrays. Source mutations no longer leak into the snapshot. Replace the strict-xfail marker with a now-passing equivalent and add a regression test through the production entry point (add_from_model) to pin that archived entries stay isolated too. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Fixes the array-sharing bug documented in #12.
clone_frozen_modelused
nnx.split+nnx.merge, which round-tripped the source'sVariablewrappers into the new model. A laternnx.updateon thesource would rewrite the arrays inside those shared wrappers, so the
"frozen" snapshot silently tracked the latest weights — and league
play degenerated into self-play against the current model.
Switch to
nnx.clone(defaultvariables=True), which createsindependent
Variablewrappers backed by the same (immutable) JAXarrays. Source mutations no longer leak into the snapshot. Flax's
own docstring example for
nnx.clonematches our exact scenario(mutate source bias, assert clone unaffected).
Tests
equivalent.
test_add_from_model_archives_isolated_snapshotexercises theproduction entry point (
add_from_model) and pins that archivedleague entries stay isolated too.
uv run pytest tests/→ 212 passed, 2 skipped, 1xfailed (the remaining xfailed is the unrelated value-loss
broadcast bug fixed by fix(rl): reshape mask to match values in value_loss_fn #16).
Test plan
uv run pytest tests/test_league_freeze_isolation.py -v— all 3 passuv run pytest tests/— full suite green🤖 Generated with Claude Code