Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .agents/evidence/vt-flash-order-20261130/PROCESS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# vt-flash-order — the ggml-flash-order arm of vt::PagedAttention (KERNEL-ATTN-PAGED)

Shared-seam unit for the kolibri11-u3 attention-core fp order (issue
ISSUE-LOCAL-01M8MYQZRAX0KV2SV497RT2MRR, row KERNEL-ATTN-PAGED; worktree
row/KERNEL-ATTN-PAGED-ggml-flash-order off main ee9c3de77).

- DEFECT (from /tmp/kolibri11-u3 sparse-layer-set-20261129.txt): 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 — fp-noise-scale divergence
(rel 2.1e-5 at (L13,pos1) with bitwise-exact inputs) that flips greedy
tokens at depth.
- CHANGE: ADDITIVE `PagedAttentionArgs::ggml_flash_order` (default false =
byte-identical two-pass body, untouched) + the arm branch in
cpu_paged_attn.cpp mirroring ggml's accumulation order: Q rounded to the
F16 vec-dot grid BEFORE the dot (:8933-8934,8972), ggml's softcap fold
(scale/=cap, cap*tanhf, :8915-8925,8998-9000), per-key ONLINE softmax
M/S/VKQ with ms/vs (:9004-9034), typed widen V mad (:9024-9032), ggml sink
block AFTER the key loop (:9038-9053), final 1/S (:9064-9065). Same paged
jmin..jmax walk; page-major pages slice reused. CPU-only; no provider
refusal extended (uniform_spec_query_len routing pattern).
- RED-FIRST: tests/vt/test_ops_paged_attn_ggml_flash_order.cpp failed to
COMPILE pre-arm ("no member named ggml_flash_order") — red-compile.log.
- GREEN: 4 cases / 16 assertions (red-compile.log, arm-green.log):
(1) INERTNESS default == the transcribed two-pass body byte-for-byte;
(2) ARM == GgmlFlashOrderRef (the scalar transcription of ggml's order)
byte-for-byte, over F16 KV, F32 KV, intersecting sliding window, and
the ggml softcap fold (a different fold than the default body's —
pinned separately); (3) DISCRIMINATOR arm != default on the same
fixture (the F16 query rounding plus the online rescale sequence).
- SIBLING INERTNESS: test_ops_paged_attn, _dtype, _neon,
test_ops_dflash_paged_block_attn, test_paged_attn_route all RC=0
unchanged.
- MUTATION: `S = S*ms + vs` -> `S = S + vs` in the arm => arm test REDS
4/4 cases, 4 assertions (mutation-red.log); restored BYTE-FOR-BYTE (cmp
clean) => 16/16 green again.
- HONEST SCOPE: the reference is the scalar f32 sequential transcription of
ggml's order (the NEON widened-lane scalar order). A live-oracle bit-proof
of ggml's SIMD lane grouping (vec.cpp ggml_vec_dot_f16) and the consumer
rewiring (kolibri1 setting the field per model) are the follow-up wave,
like the quant seam. The W1 flash harness named by the dispatch does not
exist on this host (/tmp worktrees searched); the transcription IS the
reference per the dispatch's METHOD clause.
- PREFLIGHT: agent-preflight.sh --staged RC=0 (preflight-staged.log; first
run failed role-undeclared — helper claimed under KERNEL-ATTN-PAGED, not a
checker change). No push.
- 2026-11-30 — F1 REPAIR (4a9383062). Review finding: the inertness guarantee
was only detected inside the arm suite; the sibling test_ops_paged_attn.cpp
compares at epsilon 1e-4..1e-5, an order above the ~2e-5 default-flip
divergence. Reproduced RED-first: flipping the field default
(include/vt/ops.h:2101) to true left the sibling GREEN (15/15 cases, 1838
assertions, rc=0 — /tmp/vtfo-mut1-sib.log) while the arm suite redded 4/4
(/tmp/vtfo-mut1-arm.log). Repair is additive: one focused pin in the
sibling suite, "paged_attention default body is byte-identical to the
two-pass transcription" (tests/vt/test_ops_paged_attn.cpp, TwoPassDefault-
BytesRef transcription of the default body, memcmp equality, multi-block
varlen GQA fixture, no epsilon touched). Under the flip the pin REDS
(memcmp -1, rc=1, 1839/1840) — /tmp/vtfo-mut1-sib2.log. Restore:
ops.h byte-clean (git diff empty), all six focused suites GREEN —
new arm suite, test_ops_paged_attn (16/16, 1840), _dtype, _neon,
test_ops_dflash_paged_block_attn, test_paged_attn_route
(/tmp/vtfo-green-*.log). Mutation 2 (neuter dispatch, `if (false && ...)`):
arm suite REDS 4/4 cases / 12 assertions as before
(/tmp/vtfo-mut2-arm.log); sibling green as expected (pin covers the
default path, not the dispatch); restored byte-clean. PREFLIGHT:
agent-preflight.sh --staged RC=0 (/tmp/vtfo-preflight-f1.log). Committed
4a938306271f20c7390003765426e94de6a993fe on row/KERNEL-ATTN-PAGED-ggml-
flash-order; no push.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ID: ISSUE-LOCAL-01M8MYQZRAX0KV2SV497RT2MRR
Title: vt::PagedAttention ggml-flash-order arm (shared seam, kolibri11-u3 core fp order)
Row: KERNEL-ATTN-PAGED
State: OPEN
Kind: bug
GitHub: -
Mirror: PENDING
Availability: FULL
Created: 2026-11-30
Updated: 2026-11-30
Closed: -

## Problem

The kolibri11-u3 lane localized the remaining token divergence INSIDE the attention core arithmetic: with bitwise-exact inputs at (L13,pos1) the kqv core differs at rel 2.1e-5 (max abs 7.7e-6) because the oracle computes attention through ggml CPU flash_attn_ext (GGML_PREC_F32, F16 K/V, llama-graph.cpp:3173-3340 @ PR 5f4d22289) while ours runs the vt::PagedAttention two-pass softmax order (cpu_paged_attn.cpp). The fp-noise-scale difference accumulates through layers and flips greedy tokens at depth (24-golden gate stuck 6/24; raw probe holds 9224,46,14147). This unit adds an ADDITIVE opt-in ggml-flash-order arm in/behind vt::PagedAttention (per-call field, default false = byte-identical), mirroring ggml_compute_forward_flash_attn_ext_f16_one_chunk's accumulation order (Q to vec-dot F16, scale-after-dot, per-key online-softmax M/S/VKQ rescale, F16 V mad, final 1/S scale, ops.cpp:8858-9076). Consumer rewiring (kolibri1) is the follow-up wave, like the quant seam. Evidence: /tmp/kolibri11-u3/docs/bench-evidence/kolibri11-u3-oracle-20261125/sparse-layer-set-20261129.txt; precedent rows QUANT-GGUF-CIQ-GEMM-gemm-q80-fma and QUANT-GGUF-CIQ-GEMM-q4k-q6k-repack (6c510a9eb).

## Resolution

2026-11-30: SEAM ARM LANDED (shared-seam unit, row KERNEL-ATTN-PAGED): the additive PagedAttentionArgs::ggml_flash_order arm is in the CPU kernel (commit a6a533881, branch row/KERNEL-ATTN-PAGED-ggml-flash-order off main ee9c3de77), default-off byte-identical, bit-exact vs the scalar transcription of ggml flash_attn_ext_f16_one_chunk (ops.cpp:8858-9076 @ 5f4d22289) on F16 KV, F32 KV, intersecting window, and the ggml softcap fold; mutation-verified (S-bend reds 4/4, restore byte-identical green). OWED / issue stays OPEN: no model sets the field yet — the kolibri1 consumer rewiring and a live-oracle bit-proof of ggml's SIMD lane grouping (vec.cpp ggml_vec_dot_f16) are the follow-up wave, like the quant seam. Evidence: .agents/evidence/vt-flash-order-20261130/ on that branch.
17 changes: 17 additions & 0 deletions include/vt/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,23 @@ struct PagedAttentionArgs {
// softmax (the output is renormalised over the real keys only). This mirrors
// the gpt-oss sink mechanism. nullptr => no sink (every model before MiMoV2).
const Tensor* attn_sink = nullptr;
// ADDITIVE ggml-flash-order arm (KERNEL-ATTN-PAGED shared-seam unit, issue
// ISSUE-LOCAL-01M8MYQZRAX0KV2SV497RT2MRR): when true the CPU kernel computes
// attention in ggml CPU flash_attn_ext's accumulation order
// (GGML_PREC_F32 semantics: the query row rounded to the K vec-dot type's
// F16 grid BEFORE the dot, scale-after-dot folded per ggml's scale/=softcap
// setup, per-key ONLINE softmax with the M/S/VKQ rescale, F16 V widened mad,
// final 1/S scale — ggml-cpu/ops.cpp:8858-9076 @ 5f4d22289) instead of the
// two-pass softmax body. Same math, different fp accumulation order: the arm
// exists so a consumer can mirror an oracle whose attention runs through
// ggml's flash_attn_ext bit-for-bit (fp-noise-scale divergence flips greedy
// tokens at depth). FALSE (default) leaves the two-pass body byte-identical
// — every existing caller gets exactly the pre-arm order. CPU-only: the
// field extends no provider refusal (the uniform_spec_query_len routing
// pattern); non-CPU providers ignore it. The ggml sink block runs AFTER the
// key loop (ops.cpp:9038-9053), which is a different order from the seeded
// two-pass sink handling — the arm reorders it faithfully.
bool ggml_flash_order = false;
};

// Arguments for vt::MlaDecodeAttention (MLA campaign W4). Mirrors the scalar
Expand Down
102 changes: 102 additions & 0 deletions src/vt/cpu/cpu_paged_attn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,108 @@ using vt::cpu::PagedAttnKDotBfDot;
q_bytes + static_cast<size_t>((t * hq + h) * d) * q_esize, d,
qrow.data());
q = qrow.data();
}
if (args.ggml_flash_order) {
// ADDITIVE ggml-flash-order arm (KERNEL-ATTN-PAGED, issue
// ISSUE-LOCAL-01M8MYQZRAX0KV2SV497RT2MRR): the accumulation order of
// ggml CPU flash_attn_ext (GGML_PREC_F32), transcribed from
// ggml_compute_forward_flash_attn_ext_f16_one_chunk
// (ggml-cpu/ops.cpp:8858-9076 @ 5f4d22289). The walk stays the same
// ascending paged jmin..jmax (ggml's F16 mask row is exactly the
// window the walk visits; a masked cell is one it never reads, the
// `mv == -INFINITY` skip at :8981-8984). Per ggml:
// - Q is converted to the K vec-dot type BEFORE the dot
// (:8933-8934,8972) — for F16 K the query rounds onto the F16
// grid, a rounding the two-pass body never applies;
// - the scale folds per ggml's setup (:8915-8925): sc = scale,
// scale/cap when a softcap is set, then cap*tanhf(s) (:8998-9000)
// — NOT the two-pass body's cap*tanh(s/cap) after scaling;
// - the softmax is ONLINE per key (:9004-9034): M/S running state,
// ms = expf(Mold-M) rescales VKQ on a new maximum, vs =
// expf(s-M) widens the V term, S = S*ms + vs — no two-pass
// max pass, no normalized probabilities;
// - V is widened to f32 and mad-ed into the f32 VKQ accumulator
// (:9024-9032) — via the typed KvElem read, so every cache
// dtype the kernel serves keeps its read semantics;
// - the per-head sink joins AFTER the key loop (:9038-9053);
// - the final scale is 1/S (:9064-9065).
// The scalar f32 sequential accumulation is the NEON widened-lane
// order (each product in f32, summed in sequence); the arm is
// opt-in, default-off, and the two-pass body below is untouched.
std::vector<uint16_t> q16;
const bool k_is_f16 = kv_kind == KvKind::kF16;
if (k_is_f16) {
q16.resize(static_cast<size_t>(d));
for (int64_t e = 0; e < d; ++e)
q16[static_cast<size_t>(e)] =
vt::F32ToF16(q[static_cast<size_t>(e)]);
}
float M = -std::numeric_limits<float>::infinity();
float S = 0.0f;
for (int64_t e = 0; e < d_v; ++e) acc[static_cast<size_t>(e)] = 0.0f;
const float sc = softcap != 0.0f ? scale / softcap : scale;
for (int64_t j = jmin; j <= jmax;) {
// Page-major walk, the same ascending key order the scalar body
// uses (the pages slice was resolved above).
const int64_t pb = j / block_size;
const int64_t blk = pages[static_cast<size_t>(pb - page0)];
const int64_t kpage = blk * kc_blk + g * kc_hd;
const int64_t vpage = blk * vc_blk + g * vc_hd;
const int64_t page_end = std::min(jmax, (pb + 1) * block_size - 1);
for (; j <= page_end; ++j) {
const int64_t off = j - pb * block_size;
const int64_t kbase = kpage + off * kc_pg;
float dot = 0.0f;
for (int64_t e = 0; e < d; ++e) {
const float kv =
KvElem<decltype(kv_tag)::value>(k_base, kbase + e, k_scale);
const float qv = k_is_f16
? vt::F16ToF32(q16[static_cast<size_t>(e)])
: q[static_cast<size_t>(e)];
dot += kv * qv;
}
float s = dot * sc;
if (softcap != 0.0f) s = softcap * std::tanh(s);
const float Mold = M;
float ms = 1.0f, vs = 1.0f;
const int64_t vbase = vpage + off * vc_pg;
if (s > M) {
M = s;
ms = std::exp(Mold - M);
for (int64_t e = 0; e < d_v; ++e)
acc[static_cast<size_t>(e)] *= ms;
} else {
vs = std::exp(s - M);
}
for (int64_t e = 0; e < d_v; ++e)
acc[static_cast<size_t>(e)] +=
KvElem<decltype(kv_tag)::value>(v_base, vbase + e,
v_scale) *
vs;
S = S * ms + vs;
}
}
// The ggml sink block, AFTER the key loop (:9038-9053): a new sink
// maximum rescales VKQ by expf(M-s), otherwise the sink joins at
// expf(s-M). The two-pass body seeds the max AT the sink instead —
// the arm keeps ggml's order faithfully.
if (sink_p != nullptr) {
const float s = sink_p[static_cast<size_t>(h)];
float ms = 1.0f, vs = 1.0f;
if (s > M) {
ms = std::exp(M - s);
M = s;
for (int64_t e = 0; e < d_v; ++e)
acc[static_cast<size_t>(e)] *= ms;
} else {
vs = std::exp(s - M);
}
S = S * ms + vs;
}
const float S_inv = S == 0.0f ? 0.0f : 1.0f / S;
for (int64_t e = 0; e < d_v; ++e) acc[static_cast<size_t>(e)] *= S_inv;
StoreRowF32(out, qoff, d_v, acc.data());
continue;
}
// Pass 1: scores + running max.
// SEEDED BY THE PER-Q-HEAD ATTENTION SINK when one is present.
Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4068,6 +4068,11 @@ vllm_cpp_add_test(test_paged_attn_route vt/test_paged_attn_route.cpp)
# PERF-CPU-ATTN-DTYPE: the hoisted dtype dispatch vs the pre-change per-element
# switch, memcmp over every dtype the switch handled (spec §3, issue #391).
vllm_cpp_add_test(test_ops_paged_attn_dtype vt/test_ops_paged_attn_dtype.cpp)
# KERNEL-ATTN-PAGED shared-seam unit: the additive ggml-flash-order arm of the
# CPU paged-attention kernel (ggml flash_attn_ext accumulation order,
# ops.cpp:8858-9076 @ 5f4d22289), inert-by-default, bit-exact vs the
# transcription reference.
vllm_cpp_add_test(test_ops_paged_attn_ggml_flash_order vt/test_ops_paged_attn_ggml_flash_order.cpp)
vllm_cpp_add_test(test_ops_sample vt/test_ops_sample.cpp)
if(UNIX)
add_test(NAME test_rocm_sample_scratch
Expand Down
Loading
Loading