Skip to content

0.3.2a1: long-context MLX training - #53

Merged
FonaTech merged 1 commit into
devfrom
long-context-0.3.2a1
Nov 9, 2026
Merged

FonaTech merged 1 commit into
devfrom
long-context-0.3.2a1

Conversation

@FonaTech

@FonaTech FonaTech commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Summary

Long-context MLX training on one Mac. Every switch is off by default, so existing configs and checkpoints behave as before.

  • attention_block_size: blockwise causal attention. A block that ends at its last visible key uses the kernel's "causal" mode with no mask array, which removes the [nH, block, span] score storage from the VJP. One MLA layer at 64k: 148.6 GiB -> 2.5 GiB extra.
  • ce_chunk_size, moe_chunk_tokens: chunked cross-entropy and chunked MoE dispatch, both recomputed in the backward pass.
  • recompute_policy (all|mla|swa|alternate) on MLX and Torch.
  • rope_train_scaling (yarn|linear|ntk), MLX and Torch tables agree to 2e-5.
  • document_masking, reset_router_at_documents, and reset_lookahead_at_documents (own switch for the lookahead terms). Fixes a document-id batch-size mismatch for grouped lookahead.
  • PhaseSpec.seq_len_curriculum and PhaseSpec.pack_sft (SFTRecords.packed_batch).
  • Version 0.3.2a1 and CHANGELOG entry.

Measured (full MLX step, H512, 8 layers, 16 experts top-2, bf16, batch 1, M5 Max)

Context Default long long + recompute
8k 9.9k tok/s, 21.5 GiB 23.3k, 5.55 GiB 19.3k, 2.87 GiB
16k 4.3k, 76.2 GiB 18.1k, 6.76 GiB 15.6k, 4.76 GiB
32k not run (exceeds RAM) 11.7k, 12.7 GiB 9.7k, 8.3 GiB
64k not run (exceeds RAM) 6.6k, 24.5 GiB 5.9k, 15.4 GiB

Test plan

  • tests/test_long_context.py: 38 passed (exactness against the reference paths, Torch parity)
  • Full suite, MLX forced to CPU: 581 passed, 4 skipped (test_mlx_training_six_stage_loss_paths deselected: known MLX CPU segfault)
  • Full suite, no-MLX CI simulation: 422 passed, 63 skipped
  • ruff 0.17.4 clean
  • CI on the PR

🤖 Generated with Claude Code

…oE, recompute policy, RoPE scaling, packing)

Blockwise causal attention (full-causal blocks use the kernel's causal mode),
chunked cross-entropy, chunked MoE dispatch, selective recompute policy on MLX
and Torch, training-time RoPE scaling (yarn/linear/ntk), document masking with a
separate lookahead document switch, a pretrain length curriculum and SFT packing.
All switches default to off. 64k full-model step: 24.5 GiB extra peak at 6.6k tok/s.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@FonaTech
FonaTech merged commit 8ce2b8d into dev Nov 9, 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