Qwen causal GQA rounds scaled queries to BF16 before the QK contraction
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- c
- Ambito
- machine-learning
Direzione di ricerca
Inizia dal punto di ingresso h3_gqa_causal_bf16 del kernel GQA causale del prompt encoder di Qwen3-VL e ispeziona l’assegnazione di shared_query. Confronta il suo output con il riferimento esplicito di attenzione F32 per sequence 32, 8 teste di query, 2 teste KV e dimensione della testa 128. Il lavoro è completato quando le query scalate rimangono in F32 durante la contrazione QK e supera un test di regressione numerica a larghezza di produzione senza fixture, senza coprire il percorso DiT non correlato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
h3_gqa_causal_bf16 scales each BF16 query value in F32, but then rounds the product back to BF16 before the F32 QK contraction:
shared_query[d] = h3_bf16_to_f32(h3_f32_to_bf16(
h3_bf16_to_f32(query[q_base + d]) * args.scale));
shared_query is a threadgroup float array and the dot product uses F32 fma, so this intermediate BF16 round loses precision without reducing storage or bandwidth.
Current: BF16 Q -> F32 scale -> BF16 round -> F32 QK contraction
Expected: BF16 Q -> F32 scale --------------> F32 QK contraction
The lost bits perturb the attention scores before softmax. This path is used by the Qwen3-VL prompt encoder's causal GQA kernel; the DiT attention path uses MPSGraph SDPA and is not affected by this specific expression.
Reproduction and evidence
I exercised the real Metal kernel on an Apple M5 with deterministic synthetic BF16 inputs at the production head width:
- sequence: 32
- query heads: 8
- KV heads: 2
- head dimension: 128
- scale:
1 / sqrt(128) - 64 trials, 2,097,152 output elements
Each GPU result was compared at the kernel's BF16 output boundary with an explicit CPU attention reference that keeps the scaled query in F32.
| Metric versus F32 reference | Current BF16-rounded Q | F32-scaled Q | Change |
|---|---|---|---|
| Maximum absolute error | 0.0924071 | 0.00390625 | 95.77% lower |
| RMSE | 0.00194536 | 0.000868307 | 55.37% lower |
| BF16 output mismatch rate | 21.6468% | 0.007486% | 99.97% lower |
The two variants differed in 453,957 of 2,097,152 outputs (21.65%). Both were bit-for-bit deterministic across repeated runs.
A smaller eight-trial regression configuration also distinguishes the behavior reliably:
- F32-scaled implementation: max error 0.00390613, RMSE 0.000864323, mismatch rate 0.00839% — passes
- Current BF16 re-rounding: max error 0.0924071, RMSE 0.00197766, mismatch rate 21.5992% — fails
Repeated GPU timestamp measurements found no performance regression: median dispatch time was 21.274 us with the BF16 re-round and 20.491 us while retaining F32. The distributions overlap, so this should be read as precision improvement at neutral measured cost rather than a speedup claim.
Expected behavior
Keep bf16_to_f32(query) * scale in F32 through the QK contraction, and cover the production-width kernel with a fixture-free numerical regression test.
Scope
This confirms a material kernel-level numerical divergence from explicit F32 attention mathematics. Downstream prompt-encoder effects are outside the scope of this report.
- Lingua principale
- C
- Stelle
- 3.1k
- Fork
- 268
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di antirez/h3.c
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Bug: Interactive session doesn't emit 'Done ->' line when stdout is a pipe (non-TTY)Forse già presa @quantz8a l’ha presa 66 giorni fa. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
Deadlock (not corruption) at 243 frames: `_MTLCommandBuffer waitUntilCompleted` never returnsAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
Thank you: H3.c + StoryboardAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
Tutte le issue di antirez/h3.c
Issue simili
-
on_ctrl_redirect(): iterator never advances — infinite loop stalls the event loop at 100% CPUAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
openziti/ziti-sdk-c#1254 ·
I maintainer di solito rispondono entro 1 giorno
-
http_fetch tests: the two no-child rows fail, not skip, where a task's children file does not existForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaarea:http kind:gate-defect
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
InauguralSystems/EigenScript#2397 ·
I maintainer di solito rispondono entro 1 giorno
-
Add SECURITY.mdApertaenhancement
Difficoltà 1/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
modem: ppp: CMUX DLCI receive buffer overruns on large downlink packetsForse già presa @pedrohqr l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
zephyrproject-rtos/zephyr#126195 ·
I maintainer di solito rispondono entro 3 giorni