Skip to content

vt(kernel): ggml flash-order arm for CPU PagedAttention - #3605

Open
lu-zero wants to merge 4 commits into
localai-org:mainfrom
lu-zero:row/KERNEL-ATTN-PAGED-ggml-flash-order
Open

lu-zero wants to merge 4 commits into
localai-org:mainfrom
lu-zero:row/KERNEL-ATTN-PAGED-ggml-flash-order

Conversation

@lu-zero

@lu-zero lu-zero commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

vt(kernel): ggml flash-order arm for CPU PagedAttention

Adds an additive ggml_flash_order selection to vt::PagedAttention that
mirrors ggml's CPU flash_attn_ext_f16_one_chunk accumulation exactly
(ops.cpp:8858-9076 @ llama.cpp 5f4d22289): F16 K/V read, Q->F16 vec-dot
rounding, the softcap fold (scale/=cap, cap*tanhf), online M/S/VKQ
update, the widened-V mad, sinks applied after the key loop, final 1/S.
Default selection is byte-identical to today and asserted against a
transcribed two-pass reference; the arm is asserted bit-for-bit against
an independent scalar transcription of the pinned source over F16 KV,
F32 KV, intersecting sliding window, and the softcap fold, with a
discriminator proving the orders differ. Mutation-verified (online-S
bend reds 4/4; dispatch-neuter reds the arm cases), and a byte-exact
memcmp pin guards the default body in the sibling suite so a default
flip is detected outside the arm's own tests (review finding F1).

Motivation: the kolibri1 lane proved the serving oracle computes
attention via this flash order (GGML_PREC_F32, F16 K/V) and our order
differs at fp-noise scale (rel 2.1e-5 at bitwise-exact inputs) - enough
to flip greedy tokens at depth. No model sets the field yet; the
kolibri1 consumer rewiring is in flight and the default flip is gated
on the consumer re-proof wave. One owed item is recorded in the issue:
a live-oracle bit-proof of ggml's SIMD lane grouping for the vec-dot
(the transcription is scalar and was empirically validated; the SIMD
grouping claim is not yet byte-proven against the live oracle).

Refs ISSUE-LOCAL-01M8MYQZRAX0KV2SV497RT2MRR (stays open for the
consumer wave and the owed SIMD proof)

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [maki]

… paged-attention kernel

The kolibri11-u3 lane localized the last token divergence INSIDE the
attention core arithmetic: the oracle computes attention through ggml CPU
flash_attn_ext (GGML_PREC_F32, F16 K/V, ggml-cpu/ops.cpp:8858-9076
f16_one_chunk @ 5f4d22289) while the default vt::PagedAttention body is a
two-pass softmax — same math, different fp accumulation order, fp-noise-scale
divergence (rel 2.1e-5 at (L13,pos1) with bitwise-exact inputs) that flips
greedy tokens at depth.

This adds an ADDITIVE per-call arm, PagedAttentionArgs::ggml_flash_order
(default false = the two-pass body byte-identical and untouched), implemented
in the CPU kernel: Q rounds onto the K vec-dot type's F16 grid BEFORE the dot
(ops.cpp:8933-8934,8972), the softcap folds per ggml's scale/=cap setup and
cap*tanhf (:8915-8925,8998-9000) rather than the default cap*tanh(s/cap), the
softmax runs ONLINE per key with the M/S/VKQ ms/vs rescale (:9004-9034), V
widens into the f32 accumulator via the typed read (:9024-9032), the per-head
sink joins AFTER the key loop (:9038-9053), and the final scale is 1/S
(:9064-9065). The paged jmin..jmax walk is unchanged, so the causal/window
semantics stay the kernel's own.

RED-first: the gate test failed to compile pre-arm. GREEN 4 cases / 16
assertions: inertness (default == the transcribed two-pass body
byte-for-byte), arm == the GgmlFlashOrderRef transcription byte-for-byte
(F16 KV, F32 KV, intersecting sliding window, the ggml softcap fold), and
the discriminator (arm != default on the same fixture). Mutation
`S = S*ms + vs` -> `S = S + vs` reds 4/4 cases; restore byte-identical,
green again. Sibling paged gates unchanged (test_ops_paged_attn, _dtype,
_neon, test_ops_dflash_paged_block_attn, test_paged_attn_route all RC=0).

Unreached by design: NO model sets the field — this is the seam + tests
slice, and the kolibri1 consumer rewiring is the follow-up wave owned by
issue ISSUE-LOCAL-01M8MYQZRAX0KV2SV497RT2MRR. The reference is the scalar
f32 transcription of ggml's order; a live-oracle bit-proof of ggml's SIMD
lane grouping stays with the consumer wave. Evidence:
.agents/evidence/vt-flash-order-20261130/.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [task]
…der arm with its dated landing evidence

The issue owns the seam arm landed at a6a5338 and stays OPEN for the
consumer rewiring wave (kolibri1 sets the field; the live-oracle SIMD lane
bit-proof of ggml_vec_dot_f16 rides with it).

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [task]
… paged-attention suite

Review finding F1 on the ggml-flash-order arm: the inertness guarantee
(default selection byte-identical to the pre-arm two-pass body) was only
detected inside the new arm suite. The sibling suite
test_ops_paged_attn.cpp compares at epsilon 1e-4..1e-5, and the arm's
default-flip divergence sits at ~2e-5 fp-noise scale, so a flip of the
field default left the sibling green while only the new suite redded.

Repair is additive: one focused pin in the sibling suite,
"paged_attention default body is byte-identical to the two-pass
transcription", which computes the reference from a scalar transcription
of the default two-pass body (same technique as the arm suite's
inertness pin) and asserts memcmp-level equality of the default path's
output on a multi-block varlen GQA fixture. No existing epsilon
comparison is touched; all 1838 prior assertions still pass.

RED-first evidence: with `ggml_flash_order` default-flipped to true, the
new pin fails (memcmp -1, test_ops_paged_attn rc=1) while the other 1839
sibling assertions stay green; after restoring the default all six
focused suites pass. Regression mutation: neutering the arm dispatch
(`if (false && args.ggml_flash_order)`) reds the arm suite 4/4 cases as
before, and both mutations were restored byte-for-byte (git diff clean).

Evidence: /tmp/vtfo-mut1-arm.log, /tmp/vtfo-mut1-sib.log,
/tmp/vtfo-mut1-sib2.log, /tmp/vtfo-mut2-arm.log,
/tmp/vtfo-green-*.log, /tmp/vtfo-preflight-f1.log (preflight --staged
rc=0).

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [task]
Appends the dated F1 repair record to the lane log: the red-first
default-flip reproduction, the additive sibling pin, the mutation-2
regression check, the six-suite green run, and the staged preflight
result, alongside the commit SHA they belong to.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [task]

This branch has not been deployed

No deployments
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