Repository navigation
fix(models): keep Inkling 2 verify blocks exact on M1-class GPUs - #3475
Conversation
Both block-vs-chain tests failed on M1 Ultra because of the matmul overlay's few-row GEMV route (#2587): on GPU generations 13 and 14 a dense product of at most `MLXCEL_DENSE_GEMV_ROWS` (default 6) rows in one batch runs each row through the one-row GEMV, and anything larger takes the steel GEMM tile. Setting the variable to 0 makes both tests pass on M1; setting it to 16 moves the Inkling failure to width 8. Inkling 2: the attention-residual mix (`AttentionResidual::forward`) multiplies `[B, L, S, H]` by a shared `[H, Q]` query, which MLX folds into M = L * S, and then mixes over L batches. A decode step and a verify block therefore took different kernels on M1. Inside a verify block the mix now runs per position through `row_invariant::per_position`, at the decode step's shapes; decode steps and prefill are unchanged. On a real Inkling 2 Mini 4-bit checkpoint on M1 Ultra the probe goes from Diverges to Equal at widths 2, 4 and 8. DeepSeek V2: the negative control's widths 2 and 4 fall inside the GEMV route, so the decompressed layout already matched the chain on M1. The control now also runs widths 8 and 12, where the decompressed layout differs at every row, and it still fails with the row-invariant scope forced on. The ignored real-checkpoint diagnostic also prints the probe verdict the DSpark gate reads. Refs #3468
Implementation Review SummaryIntent
Findings AddressedNone needed: no CRITICAL or HIGH findings. Remaining Items
Checked
Verification
|
The per-position attention-residual mix that keeps an Inkling 2 verify block exact is needed only where the matmul overlay's few-row GEMV route runs (GPU generations 13 and 14). On M3 and later the block already matched the chain with a single mix, so the split only added cost there. `AppleSiliconGen::few_row_dense_gemv` names the generation half of the overlay predicate (true for M1, M2 and `Unknown`), and `AttentionResidual::forward` splits only where it holds. `MLXCEL_DENSE_GEMV_ROWS` is not read: with the route disabled the split is still exact, just slower. A misread generation can only switch the drafter off through the exactness probe, never change output. Measured on M1 Ultra, Inkling 2 Mini 4-bit, `verify_round_timing`, three interleaved runs per arm: verify width 4 median 75.1 to 75.4 ms with the split against 69.5 to 69.9 ms without (+7.7%), width 8 111.5 to 112.1 ms against 101.7 to 101.8 ms (+9.8%), argmax digests identical. That is the cost M3 and later no longer pay. On M1 Ultra the split stays on and `probe_block_chain_exactness` on the real checkpoint is Equal at widths 2, 4 and 8. The M3-class run of the no-split branch is still pending. Refs #3468
Security and performance reviewAddressed
Measured on M1 Ultra, Inkling 2 Mini 4-bit,
Spread within an arm is under 1 ms, and argmax digests match between arms. This is the cost M3 and later no longer pay. Exactness on M1 Ultra with the gate:
Remaining
No security findings: the change adds no input parsing and no new panic paths. |
The Inkling 2 DSpark row listed the verify-block exactness mechanisms but not the per-position attention residual mix that runs on Apple GPU generations 13 and 14 (M1, M2), and it stated the block-versus-chain probe result on an M3 Ultra only. Add the mechanism and the measured M1 Ultra result, scoped to Mini 4-bit at widths 2, 4 and 8. Refs #3468
The generation predicate reads `AppleSiliconGen::Unknown` as true so an unidentified Apple chip keeps the exact split, but CUDA and ROCm also report `Unknown`, so every Inkling 2 verify block there paid the per-position residual mix for a few-row GEMV route that exists only in the Metal matmul overlay. `HardwareCapabilities::few_row_dense_gemv` now also requires the Apple vendor tag, and the residual mix asks it instead of the bare generation. Non-Apple backends keep the single mix they ran before #3475. Validated on M1 Ultra: the new vendor test, `deepseek_v2::`, `inkling2` and `dense_verify_block` filters (97 passed), and the real-checkpoint probe on `Inkling-2-Mini-4bit` at width 8 (Equal). The CUDA arm is covered by the unit test only; no CUDA host was used. Refs #3468
#3462 added `unix_micros`, `rfc3339`, `unix_micros_now` and `rfc3339_now` to `src/server/clock.rs`, but every caller outside the clock tests sits behind the `webui` feature. Builds without it, such as the OpenXLA feature compile job under `RUSTFLAGS=-D warnings`, failed on dead code, and that job has been red on main since #3462. The two `_now` wrappers now compile with `webui` only and the two formatters with `webui` or tests. Validated with `cargo clippy --no-default-features --features metal,accelerate --lib --tests -- -D warnings`, the workspace clippy at default features, and the `server::clock` tests.
Implementation hardeningReviewed this PR against #3468 on the branch merged with current Findings and fixes
Security: no new input parsing or panic paths. Performance: the fix removes the verify-round cost off Apple; Apple behavior is unchanged. Validation (M1 Ultra)
Remaining
|
Cause
Both tests fail on M1 Ultra because of the matmul overlay's few-row GEMV route (#2587,
src/lib/mlxcelverse/overlays/metal/mlx/backend/metal/matmul.cpp). On GPU generations 13 and 14 (M1, M2), a dense product with at mostMLXCEL_DENSE_GEMV_ROWSrows (default 6) in a single batch runs each row through the one-row GEMV. Larger products take the steel GEMM tile, which sums in a different order. Generation 15 and later never take that route, which is why the M3 measurements behind #3405 and #3424 missed it. On M1, with the unchanged tests onmain:MLXCEL_DENSE_GEMV_ROWSTurning off
MLXCEL_INKLING2_KERNELSdoes not help (it still diverges at width 2), so the Inkling 2 Metal kernels are not the cause.Changes
Inkling 2 (runtime). The op is
AttentionResidual::forward(src/models/inkling2/residual.rs).[B, L, S, H] @ [H, Q]shares its right operand, so MLX folds it into M = L * S, and the value mix runs L batches where a decode step runs one, so a decode step and a verify block dispatch different kernels on M1. The mix moves intomix(), and inside a verify block on generations where the few-row route exists, each position runs alone throughrow_invariant::per_positionat the decode step's own shapes. On the tiny model the per-visit trace showed the first divergence at the final visit input, after the last layer's residual mix; with the change every visit and the logits are byte-identical.Generation gate.
AppleSiliconGen::few_row_dense_gemv()(src/lib/mlxcel-core/src/hardware.rs) is true for M1, M2 and unidentified chips, mirroring the overlay'sget_architecture_gen() < 15, with a unit test. M3 and later keep the single mix, which already matched the chain there. It reads the brand-string generation rather than MLX's architecture generation; if the two ever disagree, the block-versus-chain probe declines the drafter, so output never changes. It does not readMLXCEL_DENSE_GEMV_ROWS: with the route disabled the split is still exact, only slower.row_invariant::per_positionitself is unchanged.Why gate it: the split costs every verify round. M1 Ultra,
Inkling-2-Mini-4bit,verify_round_timing, three interleaved runs per arm, argmax digests equal:On M1 and M2 that cost is the price of exactness (without it the drafter is declined); M3 and later no longer pay it.
DeepSeek V2 (test only). Widths 2 and 4 fall inside the GEMV route, so on M1 the decompressed layout's projections already match the chain without the row-invariant scope. The control in
src/models/deepseek_v2_verify_tests.rsnow also runs widths 8 and 12. Differing rows on M1, scope off:With the scope forced on (
Some(false)andSome(true)in place ofNone), both layouts differ in 0 rows at every width and the control panics withthe block already equals the chain without the scope, so it still discriminates. UnderMLXCEL_DENSE_GEMV_ROWS=16width 12 still differs in all 12 rows. On other generations the width set contains the old[2, 4], so the control cannot weaken where it passed before.Diagnostics and docs. The ignored
verify_block_vs_chain_per_visitdiagnostic now prints the probe verdict the DSpark gate reads. The DSpark row indocs/supported-models.mdnotes the per-position residual mix on M1 and M2 and the M1 Ultra result below.Real checkpoint (M1 Ultra,
mlx-community/Inkling-2-Mini-4bit)probe_block_chain_exactness:mainmtp_config.block_size)On
mainthe DSpark gate therefore declined on M1 withoutMLXCEL_MTP_ALLOW_INEXACT=1. The mlx-community conversion does not bundlemtp.safetensors, so the drafter check used the upstream sidecar (thinkingmachines/Inkling-2-Minimtp.safetensorsandconfig.json, in a separate directory passed as--draft-model). With this PR, without the override,mlxcel generate --temp 0 -n 96logsMTP exactness probe passed ... block_size=8and the drafter engages (50 rounds, 13 of 39 proposals accepted; the drafter was trained against the BF16 target, not this 4-bit conversion). The 96 tokens are byte-identical to the same run without--draft-model.Test plan
make verify-teston M1 Ultra: 17201 passed, 2 failed. Both failures aremlxcel-xlaplamo2 prefill goldens (emit_all_reproduces_registered_goldens,registered_fixtures_are_byte_exact) that fail onmainat the merge base and are fixed onmainby fix(xla): refresh the plamo2 prefill goldens for the shifted-add scan #3471; the two tests of test(models): two Metal block-vs-chain byte-identity tests fail on M1 Ultra #3468 pass.deepseek_v2::,inkling2,dense_verify_blockfilters on M1 Ultra, all six (passes, width) combinations; both tests also pass underMLXCEL_INKLING2_KERNELS=0,MLXCEL_DENSE_GEMV_ROWS=0andMLXCEL_DENSE_GEMV_ROWS=16cargo clippy --features metal,accelerate --lib --tests -- -D warnings(root andmlxcel-core),cargo fmt --checkCloses #3468