Repository navigation
tests: the attention accumulator must stay bounded by max|V|, not by the context length (Refs engine#1536) - #323
Conversation
…the context length Two arms that pin the property the f16 P*V accumulator lives on, and that no existing `flash_attention.*` row can see: they all fill Q and V with small magnitudes and compare against a CPU reference that narrows identically, so a range limit in the accumulator is invisible to them. The construction is model-free and deterministic: Q = 0 and K = 0 make every score identical, so after the running-max subtraction every softmax weight is exactly 1, and the correct output is the constant V whatever the context length. An UNNORMALISED accumulator would hold kv * V: flash_attention.accumulator_range.128.1024.v100 kv*V = 1.0e5 -> overflows f16 flash_attention.accumulator_range.128.1024.v60000 kv*V = 6.1e7 -> overflows f16 by 10^3 Both pass on 1bit/hrx-vulkan-patched (88 ms and 95 ms, 2 passed / 0 failed), which is the useful result: the accumulator IS normalised per block, so its bound is max|V| rather than n_ctx * max|V|. That refutes a mechanism that had been asserted twice on engine#1536 and once on engine#1346 -- with numbers instead of another reading -- and leaves these rows as the regression test for the normalisation: if the per-block scaling is ever "optimised" away, they go red for the right reason. Worth recording why the refutation was needed: the loop's initial value is named `scaled_current_output0`, which reads as an unnormalised carry if you stop there. It is the running result divided by the running sum. A test cost one ticket; the two comments it retracts cost more. Refs ggml-org#1536, ggml-org#1346
|
VERDICT: READY at The hand-derivable oracleQ = 0 and K = 0 → every score identical → after the running-max subtraction every softmax weight is exactly 1 → the output is the mean of the V rows, which with V = 100 is exactly 100. Nothing about the model matters, so the expected value is arithmetic rather than a reference implementation — the strongest oracle available, and the same shape as the hand-computed conv rows in ggml-org#2237 and the Against it: The observation about the existing rows is the PR's real argument
Two independent reasons for blindness, and both are the class this fleet keeps finding: the inputs are too small to reach the ceiling, and the reference narrows the same way, so the reference inherits the defect. A test whose oracle commits the same narrowing can only ever confirm agreement, which is why this one had to be constructed instead of compared.
Two asks
|
Refs engine#1536 and engine#1346. Two rows that pin the property the f16 P·V accumulator lives on — and that no existing
flash_attention.*row can see, because they all fill Q and V with small magnitudes and compare against a CPU reference that narrows identically. A range limit inside the accumulator is invisible to both sides of such a comparison.The construction is model-free and deterministic
Q = 0, K = 0 ⇒ every score is identical, so after the running-max subtraction every softmax weight is exactly 1; V = constant ⇒ the correct output is that constant at any context length. An unnormalized accumulator would instead hold
kv · V:The oracle is an analytic constant, not a second implementation — which is the only kind of oracle that cannot share the defect under test.
Both pass, and that is the point
So the accumulator is normalized per block: its bound is
max|V|, notn_ctx · max|V|. That refutes a mechanism I had asserted twice on#1536and once on#1346, and the refutation is now in the tree rather than only in a comment — both issues have the retraction with these numbers.Why the arms are worth keeping after the refutation
They are the regression test for the normalization. If the per-block scaling is ever "optimized" away — it is a multiply per block that a future reader may see as redundant, since the sum is tracked separately — these two rows go red for exactly the right reason, at a context length and a magnitude that make the failure unambiguous.
And the reason the mistake happened
The loop's initial value is named
scaled_current_output0, which reads as an unnormalized carry if you stop there; it is the running result divided by the running sum. One test on one ticket settled what two careful readings had gotten wrong, which is the argument for writing the test before the second comment rather than after it.