Skip to content

perf(attn): GQA-4 shared-KV tile for Qwythos hd256 full-attn decode (+2.4% @4k)#326

Closed
inference2026 wants to merge 1 commit into
gittensor-ai-lab:mainfrom
inference2026:feat/qwythos-gqa4-hd256
Closed

perf(attn): GQA-4 shared-KV tile for Qwythos hd256 full-attn decode (+2.4% @4k)#326
inference2026 wants to merge 1 commit into
gittensor-ai-lab:mainfrom
inference2026:feat/qwythos-gqa4-hd256

Conversation

@inference2026

@inference2026 inference2026 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Route Qwythos-9B full attention (16Q / 4KV = GQA-4, head_dim=256) to the existing shared-KV tile kernel fa_split_gqa_kernel<256, 4, …> instead of the scalar fa_split_kernel<256> fallback it was hitting. The scalar path runs one warp per q-head with no KV-tile sharing, so the 4 q-heads in a group each re-read the same KV head; the tile kernel stages KV once and shares it, cutting full-attn KV global reads ~4×. One file, +31 lines. Byte-identical output; SPARKINFER_FAGQA4=0 restores the scalar path. (Rebased onto main @ #324.)

Proof of speedup

  • Tested on RTX 5090 (sm_120)

Decode tok/s (end-to-end, bench/scripts/bench.sh, Qwythos-9B Q4_K_M, --ctx 4096 --tokens 64, interleaved A/B median of 5 rounds, vs same-box main @ #324):

decode tok/s
before (main) 245.14
after (this PR) 250.12

(+2.03% @4k — the strongest scored context. 128/512 are neutral-to-positive; the KV-read sharing grows with context, so 4k benefits most.)

=== interleaved A/B @4k, Qwythos-9B Q4_K_M, n=64 (before = main / SPARKINFER_FAGQA4=0, after = this PR) ===
round1 before=247.62 after=251.82
round2 before=245.79 after=250.12
round3 before=244.68 after=249.96
round4 before=245.14 after=250.19
round5 before=244.92 after=249.79
median before=245.14 after=250.12  ->  +2.03%

Correctness — byte-identical to main: qwen3_gguf_score, greedy, tokens 100..4300 (covers the 4k scored context) → 4203 / 4203 lines identical. The GQA-4 tile does the same online-softmax over the same tokens in the same order; only the KV global-read pattern changes. So top-1 / KL vs llama.cpp equals main exactly.

Qwen3.6 guard — unaffected: Qwen3.6 full attention is GQA-8 and never enters the new GQA-4 branch (byte-unaffected). 16k decode 381 tok/s == baseline.

Qwythos-9B full attention is 16Q/4KV (GQA-4, head_dim=256). The hd256
flash-decode dispatch only handled GQA-8, so Qwythos fell through to the
scalar fa_split_kernel<256> (one warp per q-head, no KV-tile sharing —
each of the 4 q-heads in a group re-reads the same KV head).

Route GQA-4 to fa_split_gqa_kernel<256,4,TILE> (shared-KV tile, one block
per (kv_head,split), 4 warps sharing one smem KV tile), cutting the
full-attn KV global reads ~4x. TILE=8 (smaller smem than the GQA-8 TILE=14
-> higher occupancy for the 4-warp block). Byte-identical to the scalar
path (same online-softmax order). SPARKINFER_FAGQA4=0 restores scalar.

Qwythos decode (RTX 5090, n=64, vs same-box main):
  128:  250.5 vs 249.0  (+0.6%)
  512:  248.1 vs 247.0  (+0.4%)
  4k:   241.5 vs 235.8  (+2.4%)
Byte-identical (score cmp 2003/2003 lines). Qwen3.6 guard (GQA-8) byte-
unaffected: 16k 381.3 == baseline (never enters the GQA-4 branch).
@github-actions github-actions Bot added the copycat Re-submits an earlier PR's diff — not evaluated; 2 strikes = block label Jul 10, 2026
@github-actions

Copy link
Copy Markdown

🐈 Flagged: copycat (real-time guard)

This PR re-submits substantially the same diff (≥85% line overlap) as the earlier #195 by a different author. Duplicating another contributor's work is treated as gaming the SN74 emission mechanism. The account has been blocked and this PR closed.

See .github/COPYCATS.md.

@github-actions github-actions Bot added the flagged:gaming Eval-gaming / sybil — blocked, not evaluated or merged label Jul 10, 2026
@github-actions

Copy link
Copy Markdown

🚩 Flagged: eval-gaming

Blocked account(s) for gaming the SN74 emission mechanism (sybil / coordinated duplicate farming): inference2026. The PR is not evaluated, scored, or merged.

See .github/FLAGGED.md.

@github-actions github-actions Bot closed this Jul 10, 2026
@inference2026

Copy link
Copy Markdown
Contributor Author

Maintainer review requested — I believe this is a false positive of the line-overlap copycat guard, and I want to be transparent about exactly why the overlap exists.

What this PR actually changes (31 lines, one file): it adds a single dispatch branch so Qwythos-9B's full-attention (16Q / 4KV = GQA-4, head_dim=256) is routed to the existing bf16 shared-KV tile kernel fa_split_gqa_kernel<256, 4, …>. Today that GQA-4 shape falls through to the scalar fa_split_kernel<256> (one warp per q-head, no KV-tile sharing), so the 4 q-heads in a group each re-read the same KV head. The fix cuts full-attn KV reads ~4× (+2.4% @4k, byte-identical output).

Why it overlaps #195: #195 (fansilas, merged) introduced the hd256 GQA-8 tile dispatch and the fa_split_gqa_kernel<256, 8, …> instantiations. The only way to add a parallel GQA-4 branch is to mirror that adjacent GQA-8 branch's launch boilerplate (fa_split_gqa_kernel<256, GQA, TILE, …><<<…>>> + the fa_combine_kernel call + the two template instantiations) with GQA=8 → GQA=4. So my added lines do closely resemble lines #195 added — that shared kernel-launch boilerplate is what trips the ≥85% threshold.

Why it is not a re-submission of #195's work: #195's actual contribution is the int8 tensor-core kernel fa_split_gqa_mma_i8_kernel + the int8 KV cache (+267/9 files). This PR does not touch that kernel or the KV cache at all — it only adds a num_kv_heads * 4 routing branch and two <256, 4, …> instantiations of the pre-existing bf16 tile kernel. Different kernel, different mechanism (routing gap vs. a new algorithm), 31 lines vs. ~400.

I fully understand the anti-gaming stance and I'm not trying to farm anyone's work — the diff is small precisely because it reuses the correct existing kernel rather than duplicating logic. If the maintainers judge a 31-line parallel-dispatch branch too derivative to score, I completely accept closing it on those grounds. My one real request is to lift the account block on inference2026, since this was a good-faith extension, not sybil/duplicate farming. Happy to provide the byte-identity score comparison, benchmarks, or rework the change however you prefer. Thank you for taking a look.

@skyrocket2026

Copy link
Copy Markdown
Member

🐈 Flagged: copycat (real-time guard)

This PR re-submits substantially the same diff (≥85% line overlap) as the earlier #195 by a different author. Duplicating another contributor's work is treated as gaming the SN74 emission mechanism. The account has been blocked and this PR closed.

See .github/COPYCATS.md.

@skyrocket2026

Copy link
Copy Markdown
Member

🚩 Flagged: eval-gaming

Blocked account(s) for gaming the SN74 emission mechanism (sybil / coordinated duplicate farming): inference2026. The PR is not evaluated, scored, or merged.

See .github/FLAGGED.md.

@skyrocket2026

Copy link
Copy Markdown
Member

Copycat false positive cleared (maintainer). Branch restored; continued as #327 — GitHub would not reopen this PR after the head branch was recreated.

skyrocket2026 added a commit that referenced this pull request Jul 10, 2026
fansilas pushed a commit to fansilas/f_sparkinfer that referenced this pull request Jul 10, 2026
…function block escalation.

Unblock inference2026, mark gittensor-ai-lab#326 cleared in copycats.json, and cap
per-function containment at WARN — template boilerplate must not trigger ≥85% block.

Co-authored-by: Cursor <cursoragent@cursor.com>
@skyrocket2026 skyrocket2026 added test-on-5090 Maintainer-approved to evaluate on RTX 5090 (greenlight) copycat-cleared and removed copycat Re-submits an earlier PR's diff — not evaluated; 2 strikes = block flagged:gaming Eval-gaming / sybil — blocked, not evaluated or merged labels Jul 10, 2026
@skyrocket2026

Copy link
Copy Markdown
Member

Copycat clearance applied: removed copycat + flagged:gaming, added copycat-cleared + test-on-5090.

GitHub will not reopen this PR — branch feat/qwythos-gqa4-hd256 was already merged via #327 (same commit 833fda1). Formal Polaris eval for that change is on #327 (eval:XS, receipt in eval comment).

This PR stays closed as superseded; labels updated so it no longer shows as a gaming/copycat strike.

@skyrocket2026

Copy link
Copy Markdown
Member

Maintainer tracking: #334 — void #327 emission, credit #326, merge feat/qwythos-gqa4-hd256 (rebased on current main, cf9d521). GitHub still won't reopen this PR.

skyrocket2026 added a commit that referenced this pull request Jul 10, 2026
maintainer: land GQA-4 via #326 + void #327 emission (#334)
@skyrocket2026

Copy link
Copy Markdown
Member

Landed via maintainer #335 — GQA-4 on main; emission credited to #326 (eval:XS, inference2026). #327 voided in dashboard.

reyanthony062001-ops pushed a commit to reyanthony062001-ops/sparkinfer that referenced this pull request Jul 10, 2026
…fix (gittensor-ai-lab#334)

- Credit PR gittensor-ai-lab#326 (inference2026) with gittensor-ai-lab#327 Polaris eval; void gittensor-ai-lab#327 emission in dashboard
- GQA-4 Qwythos dispatch (rebased on main, cf9d521)
- Copycat guard: per-function warn-only, boilerplate filter, copycat-cleared skip

Closes gittensor-ai-lab#334. Refs gittensor-ai-lab#326 gittensor-ai-lab#327 gittensor-ai-lab#332.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copycat-cleared test-on-5090 Maintainer-approved to evaluate on RTX 5090 (greenlight)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants