Skip to content

feat: polish PagedAttention and batch generation - #10

Merged
Brooooooklyn merged 1 commit into
mainfrom
01-26-feat_polish_pagedattention_and_bach_generation
Jan 27, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
01-26-feat_polish_pagedattention_and_bach_generation

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor

Note

Introduces core and tooling upgrades alongside broader test coverage.

  • Core (Rust/TS): adds MxArray.from_bfloat16/from_float16, repeat_along_axis, item_at_float32_2d; new memory controls (set_cache_limit, compile_clear_cache, check_memory_safety, enhanced heavy_cleanup); exposes left-padding helpers; attention VJP benchmarks added

  • Storage: replaces libsql with sqlx and integrates new mlx-db crate; OutputStore schema/metrics expanded (e.g., stdAdvantage)

  • Generation/Training: batch/parallel generation tests and GRPO autograd/gradient accumulation updates; API renames (modelConfig→modelName, maxNewTokens→maxCompletionLength); PagedAttention tests scaffolded

  • Tooling: migrates test runner to Vite+ (vite-plus/test), adds Yarn catalog aliases; cleans up configs and submodule URL

  • Docs: Vite+ usage guide appended to CLAUDE.md

Written by Cursor Bugbot for commit cdfbe69. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings January 27, 2026 11:19
@coderabbitai

coderabbitai Bot commented Jan 27, 2026

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 173 files, which is 23 over the limit of 150.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances PagedAttention and batch generation with several key improvements: direct bf16/f16 loading for 2x memory savings, batched forward pass kernel for parallel generation, improved numerical stability in loss computation, and migration to a shared database library (mlx-db).

Changes:

  • Added direct bf16/f16 loading support in safetensors to eliminate intermediate f32 conversion
  • Implemented batched forward pass kernel with array-based RoPE offsets for true parallel batch generation
  • Refactored cross-entropy loss to use log_softmax directly for better bf16 stability
  • Migrated database operations to shared mlx-db crate with sqlx
  • Removed PagedAttentionLayer wrapper in favor of direct Metal kernel usage

Reviewed changes

Copilot reviewed 97 out of 174 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/mlx-sys/src/lib.rs Added FFI bindings for bf16/f16 array creation and batched forward pass
crates/mlx-sys/mlx Updated MLX submodule commit reference
crates/mlx-sys/build.rs Added rerun trigger for mlx submodule changes
crates/mlx-db/src/writer.rs New shared database writer operations using sqlx
crates/mlx-db/src/schema.rs Database schema with migration support and new logs table
crates/mlx-db/src/lib.rs Main library exports for shared database functionality
crates/mlx-db/src/error.rs Database error types using thiserror
crates/mlx-db/src/connection.rs Async and sync database connection wrappers
crates/mlx-db/Cargo.toml Dependencies for new mlx-db crate
crates/mlx-core/src/utils/safetensors.rs Direct bf16/f16 loading without f32 conversion
crates/mlx-core/src/transformer/rotating_kv_cache.rs Fixed edge case for rotating cache concatenation
crates/mlx-core/src/transformer/paged_attention.rs Simplified to re-exports from mlx-paged-attn
crates/mlx-core/src/transformer/mod.rs Removed PagedAttentionLayer from exports
crates/mlx-core/src/transformer/block.rs Updated to use PagedKVCache Metal kernels directly
crates/mlx-core/src/transformer/batch_kv_cache.rs Added methods for batched forward pass integration
crates/mlx-core/src/tools/mod.rs Added JSON sanitization for control characters
crates/mlx-core/src/sft/engine.rs Improved parameter reuse and memory management
crates/mlx-core/src/sft/autograd.rs Fixed scope for better memory cleanup
crates/mlx-core/src/output_store/writer.rs Delegated to mlx-db for database operations
crates/mlx-core/src/output_store/types.rs NAPI wrappers for mlx-db types
crates/mlx-core/src/output_store/mod.rs Simplified module documentation
crates/mlx-core/src/nn/losses.rs Switched to log_softmax for better bf16 stability
crates/mlx-core/src/lib.rs Added initialization comment
crates/mlx-core/src/grpo/loss.rs Added chunking configuration options
crates/mlx-core/src/grpo/autograd.rs Implemented chunked autograd and selective log-softmax
crates/mlx-core/src/convert.rs Added support for sharded model loading
crates/mlx-core/src/array/mod.rs Added bf16/f16 creation, memory utilities, and helper methods
crates/mlx-core/src/array/mask.rs Removed unnecessary NAPI annotation
crates/mlx-core/benches/attention_vjp_bench.rs New attention VJP performance benchmarks
crates/mlx-core/Cargo.toml Added mlx-db dependency and benchmark configuration
test/utils/xml-parser.test.ts Updated test import to vite-plus
test/utils/rewards.test.ts Removed reward function tests (file deleted)
test/utils/dataset.test.ts Updated test imports and removed expectedAnswer assertion
test/tsconfig.json Changed to noEmit mode for tests
test/training/basic-training.test.ts Updated test import to vite-plus
test/trainers/* Updated all test imports to vite-plus
test/tools/chat.test.ts Updated test import to vite-plus
test/tokenization/qwen3-tokenizer.test.ts Updated test import to vite-plus
test/test-utils.ts Updated test import to vite-plus
test/paged-attention/* New test files for PagedAttention (currently skipped)
test/models/* Updated test imports to vite-plus
test/core/* Updated all test imports to vite-plus
README.md Updated code formatting in examples
Cargo.toml Added mlx-db workspace member and sqlx dependency
CLAUDE.md Updated documentation and added Vite+ section
.yarnrc.yml Added vite-plus catalog configuration
.oxfmtrc.json Removed formatter configuration (delegated to Vite+)
.gitmodules Changed MLX submodule URL to mlx-node fork

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Brooooooklyn
Brooooooklyn force-pushed the 01-26-feat_polish_pagedattention_and_bach_generation branch from a4fec37 to cdfbe69 Compare January 27, 2026 14:33
@Brooooooklyn
Brooooooklyn merged commit ad5e4ca into main Jan 27, 2026
@Brooooooklyn
Brooooooklyn deleted the 01-26-feat_polish_pagedattention_and_bach_generation branch January 27, 2026 14:56
Brooooooklyn added a commit that referenced this pull request Apr 11, 2026
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Introduces core and tooling upgrades alongside broader test coverage.
> 
> - **Core (Rust/TS)**: adds `MxArray.from_bfloat16/from_float16`,
`repeat_along_axis`, `item_at_float32_2d`; new memory controls
(`set_cache_limit`, `compile_clear_cache`, `check_memory_safety`,
enhanced `heavy_cleanup`); exposes left-padding helpers; attention VJP
benchmarks added
> - **Storage**: replaces `libsql` with `sqlx` and integrates new
`mlx-db` crate; OutputStore schema/metrics expanded (e.g.,
`stdAdvantage`)
> - **Generation/Training**: batch/parallel generation tests and GRPO
autograd/gradient accumulation updates; API renames
(`modelConfig`→`modelName`, `maxNewTokens`→`maxCompletionLength`);
PagedAttention tests scaffolded
> - **Tooling**: migrates test runner to Vite+ (`vite-plus/test`), adds
Yarn catalog aliases; cleans up configs and submodule URL
> 
> - *Docs*: Vite+ usage guide appended to CLAUDE.md
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
cdfbe69. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Brooooooklyn added a commit that referenced this pull request Jul 28, 2026
…loc; add persist env override

D (REGRESSION): the cold-cache restore bound used a flat +4096 header allowance,
but the safetensors header carries 1+2*num_layers tensor descriptors and grows
O(layers), overrunning 4096 at ~24 layers (block_size=16). Every real Qwen3
depth (28/32/40/64) had its persisted blocks rejected as oversized "corruption"
on restart, silently disabling persistence. Replace the flat constant with a
shared header_overhead(num_layers) = (1+2*num_layers)*256 + 1024 + 15 helper,
mirrored by both encoded_len and max_encoded_len_for_pool (256 B/descriptor
upper-bounds the ~140 B worst case). Also guard decode_block: reject when
(2*num_layers+1) != tensors.len() before Vec::with_capacity, closing the
~206 GB forged-metadata OOM (the read cap alone didn't bound a metadata-driven
allocation). Deep-layer bound-mirror + tensor-count-guard regression tests added.

#8: implement the spec-mandated persistence env override (spec:80 "config + env
override"). Read MLX_PERSIST_PAGED_CACHE at the native load boundary with
precedence env > config aliases > false, so a direct library caller can enable
persistence without a config field. Documented in docs/perf.md.

#10 (doc): correct the load-window comment — the three identity snapshots close
the atomic-rename race but a coordinated local ABA swap remains an accepted
residual (the sound fix needs fd-coupled fingerprinting, out of scope).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VKtaz9j1ih1YtSPBf5TtQm
Brooooooklyn added a commit that referenced this pull request Jul 28, 2026
…loc; add persist env override

D (REGRESSION): the cold-cache restore bound used a flat +4096 header allowance,
but the safetensors header carries 1+2*num_layers tensor descriptors and grows
O(layers), overrunning 4096 at ~24 layers (block_size=16). Every real Qwen3
depth (28/32/40/64) had its persisted blocks rejected as oversized "corruption"
on restart, silently disabling persistence. Replace the flat constant with a
shared header_overhead(num_layers) = (1+2*num_layers)*256 + 1024 + 15 helper,
mirrored by both encoded_len and max_encoded_len_for_pool (256 B/descriptor
upper-bounds the ~140 B worst case). Also guard decode_block: reject when
(2*num_layers+1) != tensors.len() before Vec::with_capacity, closing the
~206 GB forged-metadata OOM (the read cap alone didn't bound a metadata-driven
allocation). Deep-layer bound-mirror + tensor-count-guard regression tests added.

#8: implement the spec-mandated persistence env override (spec:80 "config + env
override"). Read MLX_PERSIST_PAGED_CACHE at the native load boundary with
precedence env > config aliases > false, so a direct library caller can enable
persistence without a config field. Documented in docs/perf.md.

#10 (doc): correct the load-window comment — the three identity snapshots close
the atomic-rename race but a coordinated local ABA swap remains an accepted
residual (the sound fix needs fd-coupled fingerprinting, out of scope).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VKtaz9j1ih1YtSPBf5TtQm
Brooooooklyn added a commit that referenced this pull request Jul 28, 2026
…loc; add persist env override

D (REGRESSION): the cold-cache restore bound used a flat +4096 header allowance,
but the safetensors header carries 1+2*num_layers tensor descriptors and grows
O(layers), overrunning 4096 at ~24 layers (block_size=16). Every real Qwen3
depth (28/32/40/64) had its persisted blocks rejected as oversized "corruption"
on restart, silently disabling persistence. Replace the flat constant with a
shared header_overhead(num_layers) = (1+2*num_layers)*256 + 1024 + 15 helper,
mirrored by both encoded_len and max_encoded_len_for_pool (256 B/descriptor
upper-bounds the ~140 B worst case). Also guard decode_block: reject when
(2*num_layers+1) != tensors.len() before Vec::with_capacity, closing the
~206 GB forged-metadata OOM (the read cap alone didn't bound a metadata-driven
allocation). Deep-layer bound-mirror + tensor-count-guard regression tests added.

#8: implement the spec-mandated persistence env override (spec:80 "config + env
override"). Read MLX_PERSIST_PAGED_CACHE at the native load boundary with
precedence env > config aliases > false, so a direct library caller can enable
persistence without a config field. Documented in docs/perf.md.

#10 (doc): correct the load-window comment — the three identity snapshots close
the atomic-rename race but a coordinated local ABA swap remains an accepted
residual (the sound fix needs fd-coupled fingerprinting, out of scope).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VKtaz9j1ih1YtSPBf5TtQm
Brooooooklyn added a commit that referenced this pull request Nov 12, 2026
Stage S10 of the Splash int8 KV alignment (stack #344). Base: S9 (#367).

Qwen3.5 dense and MoE paged prefill chunks (fresh, first or cache hit)
and MTP / DFlash2 verify blocks now store their rows into the pool
first, then attend **in place** over the pool pages. This uses one new
split + reduce kernel, on int8 and bf16 pages. Splash:
`QwenTarget::addPrefillMixer`, `ops/PagedAttention`.

```
before:  chunk ──► gather pool rows to a dense bf16 copy ──► MLX SDPA ──► store
         first chunk: SDPA over its in-flight bf16 rows
after:   chunk ──► store into pages ──► paged_prefill_attention (splits) ──► in-order reduce
         every chunk reads its own rows back as stored (int8 on an int8 pool)
```

## Kernel
(`crates/mlx-paged-attn/metal/attention/paged_prefill_attention.metal`)
- Splash's tile: 8 rows with the query group fused,
`SPLASH_ATTENTION_TILE_PARTS` (a group of 16 runs as 2 parts), per-tile
`causal_end` and visible pages, f32 partials, and a reduce that sums
splits in a fixed order.
- One 32-token Splash page = two 16-token mlx-node blocks. Keys are
staged per page in threadgroup memory (vLLM key layout). Values are read
in place. Queries are staged KV-head-major before the kernel.
- Splits: prefill uses the Splash 1.6 rule
`clamp(ceil((history+rows)/32)/pagesPerSplit, shared, most)`. Verify
uses `clamp(ceil(pages/16), 32, 128)`. Pages per split comes from
`KernelCalibration::of`: 32, or 64 on non-M5 GPUs with ≤ 10 cores. With
no core count reported, 32 cores are assumed.
- MPP (Metal 4 tensor ops) on every GPU family. 24 instances: groups {4,
6, 8, 16} × D {128, 256} × {int8, bf16}, plus the reduces. Built at the
26.2 target with no `-std` flag.
- No GPU floor. Splash starts at Apple9 for its whole engine
(`DeviceCapabilities::gpuClass`), not for this kernel, and mlx-node
supports M1+. M1/M2 take the Apple9 pages-per-split row. A pipeline that
does not build fails the turn loudly, with the kernel and the Apple GPU
family named.

## Changes in the model
- A new `PagedPass {Decode, Prefill, Verify}` replaces `is_prefill` /
`cached_prefix_len`.
- The workspace is one buffer per adapter, shared by all full-attention
layers (Splash's one arena).
- Deleted: the gather + MLX SDPA cache-hit route, the first-chunk
in-flight SDPA, the cache-hit mode / plan / headroom logic,
`PrefillSdpaKernels`, `estimate_paged_pool_sdpa_bytes_with_portable`,
the int8 varlen estimate, the int8 branch of `gather_kv_dense_range`,
`mlx_segmented_sdpa_forward`.
- The adapter's one workspace is plain scratch (Splash `RuntimeArenas`
`AttentionPartials`): `release_request` and `clear_native_graph_state`
drop it, so a failed turn's unevaluated graph never reaches the next
launch.
- Pools zero-fill their planes on create and on grow, as Splash's
buffers come back zeroed.
- A pool load needs a geometry with a kernel instance (Splash: "no
paged-attention kernel for layout"). Small test fixtures move to 8/2
heads with D 128.

## Memory plan
The prefill attention term is now Splash's tensors for one lane: the
workspace bound + query staging + output + the chunk's K/V rows. It has
no history term.

| plan | before | after |
|---|---|---|
| prefill attention, 2,048 rows / 8-row verify | (gather term, grows
with history) | 109,445,120 / 25,886,720 B |
| M3 Pro bf16 window | 48,601 | 54,425 |
| 27B int8 + DFlash2 window | 94,201 | 98,297 |
| serial MTP window | – | 57,337 |

The verify arm also charges the prefill-sized workspace the adapter
keeps through every verify (Splash `fixedRuntimeBytes` sums the prefill
and decode arenas): 35B-A3B + DFlash2 lane 179,257,344 → 196,165,632 B
at every window; the 27B only moves at window 512.

The window grows because the gather term is gone. Splash has no such
term. The term-by-term check against Splash's arenas
(`RuntimeArenas.cpp`, `PagedAttention.cpp`) found one undercharge, the
chunk's K/V rows, which is now charged. The remaining gaps are
structural and documented: 4-lane query padding (3.5 MB), the fixed
prefill arena vs per-graph MLX scratch, and the lane / staging
differences owned by S4, S13 and S17.

## Tests
- `paged_prefill_attention` (kernel vs an f64 reference over the stored
rows, every query head, int8 and bf16, gqa 4/8/16, (P, T) incl. (0,
2048), (30720, 2048), (70000, 547), (70000, 9));
`paged_attention_reads_its_own_rows_back`;
`verify_takes_the_verify_split_rule` (dense + MoE);
`pool_attention_term_is_the_splash_workspace`;
`pool_needs_a_prefill_kernel_geometry`;
`a_paged_prefill_pipeline_failure_names_the_gpu_family`;
`verify_transient_charges_the_held_prefill_workspace` (V1);
`a_reset_drops_the_held_prefill_workspace` (WS1).
- Named mutations, each red when on and green when off (`MUTATIONS.md`):
own chunk read in flight (O1), off-by-one `causal_end`, splits =
`shared`, interleaved head grouping (B1, missed by a first/last-head
check), K/V charge dropped (K1), Apple9 floor restored (A1, red under
`MLX_METAL_GPU_ARCH=applegpu_g13s`), and re-runs of every re-pinned plan
test (`G`, `A0`, `S0`, `PB`, `CF`, `AU`, `D0`, `T0`, `ST`).
- `cargo fmt --check`, `cargo clippy --all-targets -D warnings`, `cargo
test -p mlx-paged-attn` (all binaries), `bridge_metallib_names` (24
names, 24 pipelines on M5), `yarn build:native`, `yarn typecheck`:
clean. mlx-core `--lib` (`RUST_TEST_THREADS=1`): 4,756 passed, 0 failed.
- With `MLX_METAL_GPU_ARCH=applegpu_g13s` (M1 routing) on
`models::qwen3_5`: 572 passed, 1 failed. The failure is
`dflash2::tests::merged_draft_projections_match_separate_bits` (#183
merged draft projections). S10 does not touch it: its 5% element bound
does not hold for the gen-13/14 MLX kernels.

## Gaps
- The kernel has not run on real M1/M2 hardware (LIVE L6). The
pages-per-split row for M1/M2 is not measured.
- K staging takes about 29 KiB of threadgroup memory, where Splash uses
about 13 KiB. Read the speed gates with this in mind.
- AR decode keeps the old decode kernel, and continuous-batching verify
keeps the varlen kernel. DFlash2 and AR tokens can therefore differ at
bf16 ties. Two DFlash2-vs-AR token checks became cursor checks (MoE
every-keep) or run-vs-run checks (dense parked resume).
- The flat full-attention path is unchanged. It is deleted in the next
stage (RULES #10).
- `qwen35_paged_prefill_operator_bench.rs` still benchmarks the deleted
routes. `docs/mlx-fork.md` uses it as an MLX D256 benchmark.

## Not in this PR (live, not run)
- L1 teacher-forced KL / top-1, int8 vs bf16 pages; L2 cold 8K and 72K
prefill time + peak memory vs S9; L3 one 64-row and one 256-row chunk
after 64K; L4 DFlash2 decode / verify speed (≥ 0.95× S9); L5 M3/M4; L6
M1/M2 pipelines and numbers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Brooooooklyn added a commit that referenced this pull request Nov 12, 2026
Stage S10f of the Splash int8 KV alignment (stack #344). Base: S10
(#368).

On Metal, every Qwen3.5 dense and MoE inference turn now runs on the
block-paged pool, as in Splash. Splash has one KV store (pages) and no
flat full-attention lane, so this PR deletes ours (RULES #10).

```
before (Metal):
  load ── use_block_paged_cache / MLX_QWEN35_PAGED_OVERRIDE / sym8 pin / CLEF
           ├─ pool    ──► paged AR, MTP, DFlash2, images
           └─ no pool ──► flat AR, flat MTP (eager verify), flat int8 KVCache
  generate(), calibration, MoE training generation ──► flat caches (int8 at head 256)
  memory plan: pool lane + FlatInput lane

after (Metal):
  load ── a paged kernel for the layout? ── yes ──► pool: AR, MTP, DFlash2, images, eval, calibration
                                         └─ no  ──► the load fails ("no paged-attention kernel for layout")
  off Metal (CUDA preview): no pool, bf16 autoregressive turns only, int8 refused
  training generation: bf16 flat K/V (dense and MoE)
  memory plan: pool lane only
```

## Changes
- Every Apple GPU family gets the pool. A layout with no paged-attention
kernel fails the load (Splash: "no paged-attention kernel for layout").
Shipped layouts fit: 0.8B (8/2, D256), 27B (24/4, D256), 35B-A3B (16/2,
D256).
- Off Metal the load has no pool. It serves bf16 autoregressive turns.
Speculative plans need the pool, so MTP falls back to AR there. int8 and
images are refused.
- The flat AR hooks refuse a Metal load ("the flat KV lane serves only
loads off Metal").
- Paged Q/K/V are cast to the pool's io dtype. sym8, f16 and f32
checkpoints now write the pool.
- Images: both media plans admit only what the load has (encoder,
processor, pool). A no-pool load refuses images at admission, before
render.
- Eval and calibration share one prefill helper that runs on the pool.
Calibration amax is taken on the pool path.
- The int8 default applies only where the pool has kernels.
- MoE training generation uses bf16 K/V (it used int8 flat K/V).
- `use_block_paged_cache` is gone from both configs. An old `false` in a
saved config is an unknown key and is ignored.
- The server host no longer clones qwen3_5 configs to force a paging
key. `pagedModelTypes` defaults to none.
- The layer-cache full-attention snapshot is a placeholder. Replay skips
the full-attention shell.
- Docs, README, CLI help and CI lists updated.

## Deleted
- Flat turn cores (`flat_turn.rs`, dense and MoE), the MoE flat
`paged_turn.rs` router, `run_speculative_turn` and the desync overrides.
- Flat MTP arms (owner `None`), `eager_verify_step`, the tape forward,
`chunked_prefill_with_hidden`.
- `generate()` / `generate_sync` and their generation types (dense and
MoE), with `qwen3_5-generation.test.ts`.
- The int8 flat `KVCache` format, `forward_int8_cached`,
`segmented_sdpa_int8` (+ `_with_route`), `segmented_int8_covers`, the
int8 schedule variants, the C forced-route entry.
- `use_block_paged_cache`, `resolve_qwen35_paged_default`,
`MLX_QWEN35_PAGED_OVERRIDE`, the sym8 pins.
- Memory plan `FlatInput`, `LaneKv::Flat`, copy bytes,
`MemoryPlan.flat`, `flat_lane_transient`.
- `QWEN35_PAGED_MODEL_TYPES`, `DEFAULT_PAGED_MODEL_TYPES`.
- Tests of deleted code: 4 paged-vs-flat parity binaries (dense, MoE,
text, VLM), `kv_int8_tests.rs`, two `stream_progress_tests.rs`, flat
cases in `layer_cache` and planner tests.
- 104 files, +2,152 / −14,054.

## Tests
- New: `metal_load_has_no_flat_lane` (dense + MoE),
`geometry_without_a_kernel_fails_the_load`,
`off_metal_load_serves_bf16_autoregressive_turns`,
`mixed_paged_operands_take_the_pool_dtype`,
`f32_checkpoint_chats_on_the_pool`, `sym8_estimate_plans_the_pool`,
`calibration_reads_the_pool`,
`image_turn_without_a_pool_is_refused_at_admission`,
`unset_kv_format_defaults_to_int8_only_where_the_pool_has_kernels`.
- Named mutations, each red when on and green when off (`MUTATIONS.md`):
N1 pool backend off, N2 flat lane allowed on Metal, N4 geometry error
falls back to no pool, N5 MTP plan without a pool, N6 no-pool int8
refusal dropped, N7 mixed Q/K/V uncast, N8 estimate re-pins sym8, N9
calibration through the flat hook, N11 images admitted without a pool,
N12 int8 default ignores the pool gate, F1 / D1 uniform f32 Q/K/V
uncast, E1 amax collector disarmed before the pool prefill.
- Follow-up (local Codex): a calibration row shorter than one block on
an f32 / f16 dense checkpoint reached a bf16-only `debug_assert` in
`project_last_token_logits_with_full_hidden`. The assert now checks that
`final_norm` keeps the residual's dtype. Test
`f32_checkpoint_calibrates_a_short_row_on_the_pool`, mutation CA2
(bf16-only assert back) red. `models::qwen3_5` 418,
`models::qwen3_5_moe` 133, `calibration` 29 passed; fmt and clippy
clean.
- Final gate on this head:
- `cargo fmt --check`, `cargo clippy --workspace --all-targets -D
warnings`: clean.
- `cargo test -p mlx-paged-attn`: 17 binaries, 332 passed, 0 failed, 13
ignored.
- mlx-core `--lib` (`RUST_TEST_THREADS=1`): 4,730 passed, 0 failed, 220
ignored.
  - `qwen3_5_moe_mtp_synthetic`: 1 passed, not skipped.
- `yarn build:native` (`index.d.cts` unchanged), `tsc -b --force`:
clean.
- TS: `grpo-qwen35`, `qwen3_5-config`, `paged-config-override`,
`inference-host`: 4 files, 93 passed. `vp lint --type-aware
--type-check` and `vp fmt --check` on the 10 touched TS files: clean.
  - `git grep MLX_MUT`: 0.

## Gaps
- A CLEF decision load builds no pool (as before) and `decide_clef` runs
the flat forward. It serves decisions, not chat; a chat turn on it is
refused on Metal.
- Off Metal the window is no longer bounded by a memory plan. It falls
back to the trained window or `--max-context`.
- GRPO / SFT rollout generation keeps a flat bf16 full-attention
forward. Splash has no training.
- The int8 segmented-SDPA C++ kernels are reached only from
`paged_int8_read.rs`, as a reference.
- `shared_command_dispatch_orders_family_operations_stats_and_reset` no
longer checks the effect of its first command (its `history_len > 0`
holds from setup).
- One old plan doc (`docs/superpowers/plans/2026-06-16-...`) still names
`MLX_QWEN35_PAGED_OVERRIDE` and `MLX_QWEN35_FORCE_EAGER`.

## Not in this PR (live, not run)
- L1 27B dense on the pool: AR, DFlash2, MTP, 2-turn chat each (paged,
int8, cached tokens, MTP cycles).
- L2 35B-A3B MoE MTP on the pool.
- L3 image turn on the pool (qwen3.5-0.8b).
- L4 GRPO smoke on a tiny qwen3_5, dense + MoE, from the live build.
- L5 a `use_block_paged_cache: false` view and
`MLX_QWEN35_PAGED_OVERRIDE=0` both load on the pool.
- L6 sym8 checkpoint on the pool.
- L7 calibration on the pool (`calibrate.test.ts`).
- L8 f16 checkpoint on the pool (bf16 pool, no dtype error).
- L9 M1 / M2: no such Mac here.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants