Skip to content

hip : use native PQ2_0 unpacking in MMQ tile loader - #200

Merged
bri-prism merged 1 commit into
PrismML-Eng:prismfrom
markschatza:hip/pq2-mmq-native-unpack
Sep 21, 2026
Merged

bri-prism merged 1 commit into
PrismML-Eng:prismfrom
markschatza:hip/pq2-mmq-native-unpack

Conversation

@markschatza

@markschatza markschatza commented Sep 18, 2026 •

Copy link
Copy Markdown

Overview

Use the existing q2_0_symbols4_hip helper in the PQ2_0 MMQ tile loader. On RX 7900 GRE, the isolated change improves Bonsai 27B prompt processing by about 2x at 512 and 2048 tokens, and 3.09x at 32 tokens.

The loader currently unpacks each int16 with four __byte_perm calls. HIP implements these through a software path. Two calls to the existing native AMD helper produce the same low/high groups of four signed-byte symbols. This follows the existing PQ2_0 vec-dot path; tile layout, scales, and accumulation are unchanged. CUDA/MUSA and HIP host compilation keep the original branch.

Additional information

Tested on AMD Radeon RX 7900 GRE (gfx1100), Linux, AMD clang 22.0.0git. Control and candidate were built from 01041db99dae68529db58c6fc692a9ca623b30a2; the candidate adds only the five-line change in this diff. No decode tuning or activation-reuse patches are included. The branch is rebased onto 9a9394a; the intervening upstream commit changes release configuration and DSPARK option-storage portability, not these kernels. Measurements below remain from 01041db.

Model: Ternary-Bonsai-27B-PQ2_0.gguf (SHA-256 e4781999f1997ef97ce0c58d05750835acc999d18d83ee6489ba7ac7b14cb5f6).

Five paired llama-bench invocations per workload, alternating control/candidate order, with exclusive GPU access. Throughput is mean +/- sample SD in tokens/s; gain is the mean paired ratio.

Workload Upstream Patched Paired gain
pp32 89.31 +/- 0.16 275.97 +/- 1.17 +208.99%
pp512 390.55 +/- 0.88 786.54 +/- 1.20 +101.39%
pp2048 393.01 +/- 0.38 779.35 +/- 10.29 +98.30%
tg128 45.97 +/- 0.35 46.18 +/- 0.13 +0.45%

The tg128 confidence interval includes zero: this is a prefill improvement, not a demonstrated decode gain. The paired 95% lower confidence bounds for pp32/pp512/pp2048 are +207.05%, +100.58%, +95.01%, respectively.

Validation:

  • Exhaustive on-device comparison of all 65,536 signed int16 input patterns: zero unpacking mismatches, including both output words.
  • Existing test-backend-ops test -o MUL_MAT -p 'type_a=pq2_0': 45 supported cases pass against the CPU reference on both builds; 33 unsupported cases are skipped on both.
  • All 63 full-vocabulary logit vectors match bit-for-bit, covering natural-language prompts, 512/2048/8192-token inputs, and following decode steps.
  • WikiText-2, four 512-token chunks: identical per-chunk perplexity and final PPL 10.1473 +/- 0.94883 on both builds. This is a limited sample, not a full-corpus evaluation.
  • HIP release builds pass on gfx1100. The changed PQ2_0 MMQ translation unit also passes compiler checks for gfx908, gfx942, and gfx1201; those devices were not runtime-tested.
  • Full multi-backend CI and NVIDIA runtime tests have not been run locally.

Reproduce each build:

cmake -S . -B build -DGGML_HIP=ON -DGPU_TARGETS=gfx1100 -DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_TESTS=ON
cmake --build build --target llama-bench llama-perplexity test-backend-ops -j 3
build/bin/test-backend-ops test -o MUL_MAT -p 'type_a=pq2_0'
build/bin/llama-bench -m "$MODEL" -ngl 99 -fa on -t 8 -b 512 -ub 512 -ctk f16 -ctv f16 -p 512 -n 0 -r 1 -o json
build/bin/llama-perplexity -m "$MODEL" -f wikitext-2-raw/wiki.test.raw -ngl 99 -fa on -t 8 -c 512 -b 512 -ub 512 --chunks 4

For the benchmark table, repeat the bench command as five alternating control/candidate pairs for (p,n) = (32,0), (512,0), (2048,0), (0,128).

Related: #125 (existing native HIP unpack helpers), #116 (separate broader HIP optimizations).

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES. Devin CLI using SWE-2 Max proposed and implemented the original experiment. OpenAI Codex (Astra) helped isolate and review the change, perform the validation above, and prepare this description.

Assisted-by: SWE-2 Max (Devin)

Assisted-by: OpenAI Codex (Astra)

@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.

Agent review: posted by the maintainer's coding agent at their request.

No findings in this source pass. The HIP device-only substitution preserves the two four-symbol groups produced by the original byte-permute sequence, while leaving the other compilation paths unchanged.

HIP compilation and MMQ numerical tests were not executed here; those remain the platform gate for this narrow change.

Reviewed commit: 5476d46e95b5fb978f8f28f000298ac12cfe7403.

@bri-prism

Copy link
Copy Markdown
Collaborator

Agent benchmark follow-up, posted at the maintainer's request.

Tested this head (5476d46) against 9a9394a on MI300X, ROCm 7.1.1, gfx942. Both builds passed all 45 supported PQ2 MUL_MAT CPU-reference cases. Five alternating baseline/candidate pairs per workload:

Workload Before → after, tok/s Mean paired change
pp32 415.51 → 493.95 +18.89%
pp512 1484.61 → 2217.62 +49.37%
pp2048 1624.20 → 2589.01 +59.40%
tg128 74.99 → 74.42 −0.75% (inconclusive)

Important limitation: the allocated GPU had an unrelated host process holding substantial VRAM. It was idle at inspection, but exclusive access was not established, so these are exploratory measurements, not clean performance validation. We also used the newer public model generation in PQ2 format, rather than the model used in the original report. No end-to-end logit-parity claim is made.

The results support the prefill-only direction of the change; decode's paired 95% interval was −4.28% to +2.78%. Bench settings: full GPU offload, flash attention enabled, f16 K/V, 8 CPU threads, batch and microbatch 512, one repetition per invocation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chozzz

chozzz commented Sep 20, 2026

Copy link
Copy Markdown

From my side, gfx1201 (2× AMD Radeon AI PRO R9700, ROCm, R9700 = gfx1201) data points, since those devices were compile-checked but not runtime-tested here.

  • Control: prism-b10709-9a9394a prebuilt (the base of this branch)
  • Candidate: this branch (5476d46), built with cmake -DGGML_HIP=ON -DGPU_TARGETS=gfx1201
  • Model: Ternary-Bonsai-2-27B-PQ2_0.gguf, 5 paired alternating llama-bench rounds per workload, flags: -ngl 99 -fa on -t 8 -b 512 -ub 512 -ctk q4_0 -ctv q4_0
Workload Control (t/s) Candidate (t/s) Gain
pp32 312.8 ± 10.3 355.6 ± 16.4 +13.7%
pp512 898.8 ± 0.8 1087.6 ± 3.8 +21.0%
pp2048 924.8 ± 3.8 1125.4 ± 2.1 +21.7%
tg128 41.5 ± 0.8 43.0 ± 0.1 +3.5% (neutral)

I think prefill gain is consistent across all 5 rounds but much smaller on gfx1201 than the gfx1100 numbers (+20% vs ~2x) - decode unchanged as predicted.

Note: these runs shared the GPU with a live 4-slot llama-server, so treat as relative A/B only.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused change matches an established helper path and preserves existing fallback behavior.

Review effort: Balanced
Findings: None

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.

4 participants