Skip to content

ggml: honor requested F32 flash attention value accumulation - #439

Open
JohnUzoka wants to merge 1 commit into
PrismML-Eng:prismfrom
JohnUzoka:fix/flash-attn-f32-accumulation
Open

JohnUzoka wants to merge 1 commit into
PrismML-Eng:prismfrom
JohnUzoka:fix/flash-attn-f32-accumulation

Conversation

@JohnUzoka

Copy link
Copy Markdown

Overview

Honor the existing GGML_PREC_F32 accumulation request in the CPU F16-KV fallback and the generic CUDA/HIP flash-attention tile and vector paths. These paths can currently retain the running value numerator in F16 despite that request, losing small contributions during cancellation.

  • Keep requested-F32 value accumulators and cross-warp partials in F32.
  • Preserve the default F16 accumulator path; do not change Q/K or softmax storage precision.
  • Reuse shared KV scratch for the wider reduction partials.
  • Add the existing public-API 15-shape cancellation regression and document backend/thread selection.

CPU, tile and vector changes stay together because they enforce one existing operator contract and the same public regression. The first historical tile-only correction still failed vector cases. This branch is independent of model/tokenizer changes and starts at prism@6447906; implementations and regression are extracted from JohnUzoka/llama.cpp@3d1930a (original base d7b2896, an ancestor of prism).

Additional information

Recorded validation, not a new test run

The 2026-11-11 canonical correctness record records the same public probe against before/after shared libraries:

Backend Before After
CPU, 1 thread 2/15 passed 15/15 passed
CPU, 3 threads 2/15 passed 15/15 passed
RX6600 HIP (ROCm0) 0/15 passed 15/15 passed

Toolchain and runtime identity and the source-patch application record retain provenance.

No build, tests, linters or formatters were run during this extraction; this separated branch has not been independently built. Historical hardware coverage is Ryzen 3700X CPU and Windows HIP RX6600, F16 KV. NVIDIA CUDA and MUSA have not been validated. Dispatch coverage comments describe source expectations, not a kernel trace. No speed, perplexity or model-quality improvement is claimed; full CI, test-backend-ops, and other hardware remain unrun here. The focused public-API regression is used because a differently rounded backend reference can conceal this accumulator-contract failure.

Requirements

  • Contributing guidelines: inspected while preparing this submission. The contributor remains responsible for review and maintenance; no human-review attestation or agreement is made on their behalf.
  • AI usage disclosure: YES. AI-assisted research produced the published source changes. An AI agent reviewed the diff and recorded evidence, mechanically separated the existing precision fix and regression, added documentation, and prepared this PR. No new runtime validation is claimed.

@github-actions github-actions Bot added documentation Improvements or additions to documentation ggml testing CUDA labels Nov 15, 2026

@bri-prism bri-prism left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the careful write-up. One problem with the premise: llama.cpp's attention builder sets
GGML_PREC_F32 on every flash attention node (build_attn_mha in llama-graph.cpp), so with this PR the
CPU path with an F16 KV cache and the CUDA/HIP vec and tile kernels switch to F32 accumulation for every
model, not only for graphs that opt in. That is a default precision and performance change, and there
are no speed numbers yet.

It also instantiates both accumulator variants for every tile and vec kernel, which roughly doubles those
template instances and adds a lot of CUDA/HIP build time.

To move forward I would need:

  1. llama-bench before/after on CPU, an NVIDIA GPU (vec path) and an AMD GPU (tile path), at least pp512
    and tg128 with the default F16 cache.
  2. Evidence that F16 accumulation hurts a real model (KLD or greedy divergence against an F32 reference),
    not only the synthetic cancellation inputs.
  3. A FLASH_ATTN_EXT case in test-backend-ops instead of a standalone test, so every backend is checked.
  4. A build and test run on this branch, including a GPU without fast FP16, since the float tile path was
    restructured too.

Since this is upstream ggml code, I would also suggest raising it with ggml-org first. If only one model
needs it, an opt-in that leaves the default dispatch unchanged would be much easier to take here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA documentation Improvements or additions to documentation ggml testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants