Skip to content

0.3.2a3: compile segment-mode cluster locality, recover from a failed compile trace - #55

Merged
FonaTech merged 2 commits into
devfrom
long-context-0.3.2a3
Nov 10, 2026
Merged

FonaTech merged 2 commits into
devfrom
long-context-0.3.2a3

Conversation

@FonaTech

@FonaTech FonaTech commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Fixes three kernel problems found while benchmarking the 50M and 30M multilingual configs on the real corpus.

  • cluster_locality_mode="segment" could not be compiled: the loss built document ids with NumPy on a traced array. CHRONOS_MLX_COMPILE=on raised, and auto crashed on the next mx.eval. It now uses segment_ids_mx(input_ids, chunk=window) with static shapes. Ids equal the NumPy rule on 300 random batches; the loss matches the Torch reference within 1.7e-5.
  • A failed compile trace left tracers in the weights, RNG key and router outputs, and the eager fallback then trained on them. CompiledStep now snapshots and restores them; the RNG stream continues exactly.
  • Token ids beyond vocab_size are rejected with a ValueError before MLX reads the embedding table. MLX does not bounds-check gathers, so such ids crashed the process at random. This was the cause of the intermittent crash in test_mlx_training_six_stage_loss_paths (about 1 run in 2 on CPU, also on clean dev): its GRPO stage tokenizes with the bundled 6,400-token tokenizer while the model had vocab_size=64. The test now uses 6400 and passes 25 of 25 runs.

Tests: tests/test_segment_compile.py (5 cases, 4 fail on 0.3.2a2) and tests/test_vocab_range_guard.py (3 cases). Local suite with MLX on CPU: 600 passed, 1 skipped. ruff 0.17.4 clean.

🤖 Generated with Claude Code

… compile trace

- cluster_locality_mode="segment" now traces under mx.compile: document ids come from
  segment_ids_mx(input_ids, chunk=window) and the loss uses static shapes (B*S segment
  slots, unused slots weigh 0). Matches the NumPy ids and the Torch loss.
- CompiledStep snapshots weights, RNG key and side outputs before a first trace and
  restores them when the trace fails, so the eager fallback no longer trains on tracers.
- tests/test_segment_compile.py (5 cases; 4 fail on 0.3.2a2).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@FonaTech
FonaTech force-pushed the long-context-0.3.2a3 branch from 4e8dea1 to e32660d Compare November 10, 2026 06:32
MLX does not bounds-check gathers, so an id >= vocab_size read neighbouring memory and
crashed the process at random. run_mlx_stage (every batch, GRPO prompts) and LongRun now
raise a ValueError naming the id range.

test_mlx_training_six_stage_loss_paths crashed about one run in two on CPU, on clean dev
as well: its GRPO stage tokenizes with the bundled 6400-token tokenizer while the model had
vocab_size=64 (ids up to 6170). The test now uses vocab_size=6400 (25/25 runs pass).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@FonaTech
FonaTech merged commit 2c63130 into dev Nov 10, 2026
2 checks passed
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