Commit c00c62b
committed
feat(v4): ROI 3.B-F + 3.5.B-D + 3.7 + 5 + 7 + 8 + 9 — all scaffolds + tests
Lands plumbing for every remaining ROI as a runnable scaffold with full
test coverage. Backends that need real Metal/TileLang kernel work delegate
to Path A's pure-MLX reference until the kernel land; the API surface,
status objects, and env override are stable and committed today.
cppmega_v4/_tilelang/_dispatch.py — shared PathStatus + auto_pick infrastructure
mirroring mamba3_path_c's mature pattern.
cppmega_v4/_tilelang/linear_attention_paths.py (ROI 3.B-F):
- Path A: pure-MLX (always available)
- Path B: hand-MSL — scaffold w/ explicit pending reason; fallback Path A
- Path C: TileLang DSL via tilelang.compile — scaffold; checks tilelang import
- Path D: Triton frontend — scaffold; checks triton import
- Path E: vendored mlx-lm PR #1217 — scaffold; checks for vendored module
- gated_delta_recurrent_dispatch + linear_attention_auto_mode_for_inputs +
linear_attention_path_statuses
- Env: CPPMEGA_V4_KERNEL_PATH__LINEAR_ATTENTION={path_a..e,auto}
cppmega_v4/_tilelang/kda_paths.py (ROI 3.5.B-D):
- Same shape as GDN paths but A/B/C/D only (no Path E for KDA)
- Env: CPPMEGA_V4_KERNEL_PATH__KDA={path_a..d,auto}; rejects path_e
cppmega_v4/_tilelang/benchmark_receipt.py (ROI 3.7):
- CellShape + CellReceipt dataclasses; JSON schema matches
reports/raw/cppmega_1b_path_matrix_cells/ shape
- measure_cell(shape) runs forward, records elapsed + backend status
- write_receipt(receipt, out_dir) drops <block>_<path>.json
cppmega_v4/nn/mla_absorb.py (ROI 5):
- absorb_weights(W_UK, W_UV, W_O) -> (W_UK^T, W_UV @ W_O) precompute
- absorbed_mla_decode(q, c_kv, w_uk_abs, w_uv_w_o, ...) — full absorb
path in MLX algebra (per FlashMLA docs/20250422-new-kernel-deep-dive.md)
- standard_mla_decode(...) — non-absorbed oracle for parity
- Numerical parity test: absorbed == standard (atol 1e-4)
cppmega_v4/nn/lightning_indexer.py (ROI 7):
- LightningIndexer module — fp32 scaffold of V3.2 indexer
(deepseek-ai/DeepSeek-V3.2-Exp/inference/model.py class Indexer)
- _apply_non_interleaved_rope respects the V3.2 gotcha that indexer
RoPE is non-interleaved while MLA's is interleaved
- Top-k indexing via mx.argpartition; clipped to seq length
cppmega_v4/nn/sparse_attention_v4.py (ROI 8/9):
- NativeSparseAttention scaffold (ROI 8 — NSA, arxiv 2502.11089)
- CsaHcaHybridAttention scaffold (ROI 9 — V4 CSA+HCA hybrid)
- Both fall back to dense causal SDPA today; replace with three-branch
and compressed-sparse paths in research follow-up
44 new tests across 4 files:
- tests/v4/test_path_dispatch.py — 18 tests for GDN+KDA path scaffolding,
env override correctness, dispatch == Path A parity
- tests/v4/test_benchmark_receipt.py — 5 tests for receipt schema + JSON
- tests/v4/test_mla_absorb.py — 5 tests including numerical parity vs
standard_mla_decode (atol 1e-4)
- tests/v4/test_lightning_indexer.py — 7 tests including non-interleaved
RoPE math correctness
- tests/v4/test_sparse_attention_v4.py — 9 tests for NSA + CSA+HCA scaffolds
166/166 v4 + regression green.
Plugin invariant preserved: zero modifications under cppmega_mlx/.
All 11+ ROIs from INTEGRATION_PLAN_CPPMEGA_MLX.md now have committed code
and tests; deferred backends explicitly carry their pending reason in the
PathStatus and delegate to Path A so the v4 stack runs end-to-end today.1 parent 0addd18 commit c00c62b
13 files changed
Lines changed: 1523 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
0 commit comments