Skip to content

perf(models): remove the fixed per-step cost of absorbed MLA decode #3121

Closed

Description

@inureyes

Problem

#3102 (PR #3118) kept DeepSeek V2's decompressed MLA cache as the default because absorbed decode was 9.9% slower at pp512/tg128 (180.7 against 200.6 tok/s on an M5 Max, deepseek-v2-lite-chat-4bit-mlx), although it is 57% faster behind a 16K prompt (111.2 against 70.9 tok/s) and peaks 6.7 GB lower at 28K with 2048-token chunks. The crossover is near 3K tokens of context. The measurement suggests a fixed per-step cost of about 0.55 ms in the absorbed path at short context.

Candidates named in #3118:

  • the dense f16 folded W_UK / W_UV contractions;
  • the composed (unfused) absorbed attention.

DeepSeek V3, V3.2, Kimi-VL and Kimi-K2 always take the absorbed path, so any fixed decode cost there applies to every decode step of those models too.

Acceptance Criteria

  • Profile one absorbed decode step at 512 tokens of context against the decompressed step (per-op GPU time, e.g. with the mlxcel-gpu-profiling approach), and post where the extra ~0.55 ms goes.
  • Remove or shrink the dominant fixed cost (for example quantized or fused folded projections, or a fused absorbed attention), with output unchanged or the teacher-forced trace reported if arithmetic changes.
  • Re-measure pp512/tg128 and the 2048- and 16K-context decode for deepseek-v2-lite in both layouts, plus one always-absorbed model if a checkpoint fits (kimi-vl-a3b-thinking-4bit). If absorbed decode now holds within a few percent at short context, revisit the V2 default per docs/mla-absorbed-decode.md.

Refs #3102, #3118.

Activity

  1. added
    status:ready
    type:performance
    priority:medium
    area:models
    area:inference
    status:in-progress
    and removed
    status:ready
    on Nov 16, 2026
  2. inureyes commented on Nov 16, 2026

    @inureyes
    MemberAuthor

    Profile of one decode step at 512 tokens of context, DeepSeek-V2-Lite geometry (16 heads, rank 512, rope 64, nope/v 128), 27 chained layers, M5 Max. Method: an in-context ablation in MLX (each layer's output feeds the next layer's projections so the graph is serial like a real step; graph built first, only eval timed; median of 150 evals, best of three interleaved rounds; GPU lock held). Each row removes one component, so the delta is that component's marginal cost per token. Per-shader GPU time from a .gputrace was not used: the capture replay is impractical at this size, and the ablation answers the same question.

    step variant (S=512) ms/token marginal cost
    absorbed, as on main (dense f16 folds, rope mask + SDPA) 2.006
    without absorb_queries 1.865 0.14 ms
    without unabsorb_output 1.771 0.24 ms
    without either fold 1.646 0.36 ms
    without the rope-score mask 1.840 0.17 ms
    without attention at all 1.080 attention block 0.93 ms
    decompressed (4-bit kv_b_proj + fused vector SDPA) 1.73
    decompressed without attention 0.761

    Where the extra time goes:

    • The folds: 0.36 ms. Two batched f16 GEMVs over 113 MB of dequantized W_UK/W_UV per token; unabsorb_output (N=128 per head) runs at about 230 GB/s, absorb_queries at about 385 GB/s. Against the decompressed step's single 4-bit kv_b_proj GEMV, that is the ~0.3 ms difference between the two no-attention rows.
    • The attention block: the 512-wide head with an array mask is not fused by MLX, so the step runs the rope-score matmul, the scale, the score matmul, the mask add, the softmax and the value matmul as separate small kernels (about 34 us per layer at 512 keys, latency rather than bytes: it reads 0.6 MB per layer). Two other compositions (GQA-row score matmul, addmm) and forcing MLX's head-dim-512 vector kernel with the mask (MLX_SDPA_D512_MIN_KL=0) did not help.

    Fixes, in order of the measured cost:

    1. Fold the quantized kv_b_proj without dequantizing. Its packed rows are grouped along the rank axis, which is the output axis of the query contraction and the input axis of the output one, so both run as batched quantized_matmul (transpose false and true) on the checkpoint's own planes: 30 MiB instead of 113 MiB, same quantized weights as the decompressed path. Ablation: 2.06 to 1.83 ms.
    2. A fused Metal kernel for unmasked single-query absorbed attention: both score halves, an online softmax and the latent-value sum, split over two key halves plus a merge. Prototype against the composed block alone (27 layers): 1.12 to 0.66 ms at 512 keys, 1.49 to 1.12 at 2048, 3.88 to 3.26 at 8192, slower from 16384 (each head re-reads the window), so the composed path keeps windows above 8192.

    End-to-end numbers on the real checkpoint follow in the PR.

  3. added
    status:done
    and removed
    status:in-progress
    on Nov 16, 2026
  4. added a commit that references this issue on Nov 16, 2026
    abbbe36
  5. added this to the 0.9 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:inferencearea:modelspriority:mediumstatus:donetype:performance

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions