Skip to content

vulkan: add dedicated PQ2_0 mat-vec and BC-250 batch tuning - #281

Open
renovys wants to merge 1 commit into
PrismML-Eng:prismfrom
renovys:bc250-pq2-matvec
Open

renovys wants to merge 1 commit into
PrismML-Eng:prismfrom
renovys:bc250-pq2-matvec

Conversation

@renovys

@renovys renovys commented Sep 26, 2026

Copy link
Copy Markdown

Overview

PQ2_0 still uses the generic float mat-vec shader. On an AMD BC-250 (gfx1013/RDNA1, RADV, no cooperative matrices or accelerated integer dot), this dominates decode time. This adds a dedicated PQ2_0 shader and tunes the BC-250 path. It complements the PTQ1_0 work in #252 and extends the BC-250 tuning discussed in #229.

The shader reads each 34-byte PQ2_0 block through aligned 16-bit words, decodes each row once before looping over columns, and computes d * (sum(q*y) - sum(y)). This algebraic reassociation changes floating-point rounding relative to the generic shader; tolerance-based operator tests pass on BC-250. The shader arithmetic matches the earlier deployed implementation used in our reference-comparison tests.

BC-250 uses a 32-thread workgroup/subgroup and eight rows per workgroup (16 for five columns). For PCI 1002:13FE / RDNA1 / no coopmat only, PQ2_0, BF16 and Q8_0 can use mat-vec through 16 columns. BF16/Q8_0 cover the supporting MTP operations; their existing shaders are reused. Other devices keep the existing launch geometry and eight-column limit, but PQ2_0's float mat-vec shader itself changes on them too.

The PR excludes our packed FP16 prefill path, GDN/state-copy fusion, runtime tuning knobs, and measurement scripts.

Additional information

Based on prism at adfffbe41; patch commit 031212ec9. Both were built directly on BC-250 with GCC 16 and Vulkan enabled, Release, identical flags.

llama-bench (mean of 3) upstream this PR
tg128, tokens/s 22.638 +/- 0.042 28.324 +/- 0.022 (+25.1%)
pp512, tokens/s 141.714 +/- 0.029 141.695 +/- 0.016

Model: Ternary-Bonsai-2-27B-PQ2_0-MTP-Q8_0; MTP is not used by this llama-bench run. -ngl 99 -fa 1 -ctk q8_0 -ctv q4_1 -b 2048 -ub 512 -t 6 -p 512 -n 128 -r 3.

test-backend-ops test -b Vulkan0 -o MUL_MAT,MUL_MAT_ID -p 'type_a=(pq2_0|bf16|q8_0)' passed on both builds. Upstream: 476/476 tests passed; this PR: 514/514 tests passed. The new coverage includes columns 9 through 16, row tails, batch shapes and the 17408x5120 model shape. These are targeted operator tests. Full CI and an independent model-quality evaluation were not run on this extracted PR.

Only BC-250 hardware is available for testing. The new shader also serves PQ2_0 float mat-vec on other GPUs, including the generated MUL_MAT_ID variants, so independent testing is welcome. No claim of cross-device performance parity is made.

Our earlier deployment tests compared against the previous deployed build: Korean and English/code KL top-1 agreement was 100%, with small perplexity differences. This demonstrates agreement with that reference, not an independent assessment of model quality. English long-context quality and semantic correctness of the real-request sample were not evaluated.

Requirements

  • I have read the contributing guidelines.
  • AI usage disclosure: YES. Devin SWE-2 max and Codex assisted with implementation, porting, review, benchmarking and this description; Muse max and GLM-5.3 max provided independent review. An earlier operational version also received GLM Flash assistance. The submitted patch and BC-250 test results are recorded separately from the broader deployed optimization stack.

Assisted-by: Devin SWE-2 max and Codex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant