Skip to content

fix(league): use nnx.clone so frozen snapshots are isolated from source#17

Merged
NorbertRop merged 1 commit into
mainfrom
fix/league-clone-array-sharing
May 25, 2026
Merged

fix(league): use nnx.clone so frozen snapshots are isolated from source#17
NorbertRop merged 1 commit into
mainfrom
fix/league-clone-array-sharing

Conversation

@NorbertRop
Copy link
Copy Markdown
Contributor

Summary

Fixes the array-sharing bug documented in #12. 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 creates
independent Variable wrappers backed by the same (immutable) JAX
arrays. Source mutations no longer leak into the snapshot. Flax's
own docstring example for nnx.clone matches our exact scenario
(mutate source bias, assert clone unaffected).

Tests

Test plan

  • uv run pytest tests/test_league_freeze_isolation.py -v — all 3 pass
  • uv run pytest tests/ — full suite green

🤖 Generated with Claude Code

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>
@NorbertRop NorbertRop merged commit 75ec63f into main May 25, 2026
1 check passed
@NorbertRop NorbertRop deleted the fix/league-clone-array-sharing branch May 26, 2026 12:02
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