Skip to content

cuda: extract Q2_0 elements via __byte_perm - #25603

Merged
ggerganov merged 1 commit into
ggml-org:masterfrom
dfriehs:q2_0-cuda
Jul 31, 2026
Merged

cuda: extract Q2_0 elements via __byte_perm#25603
ggerganov merged 1 commit into
ggml-org:masterfrom
dfriehs:q2_0-cuda

Conversation

@dfriehs

@dfriehs dfriehs commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Overview

Unpack Q2_0 elements via __byte_perm, leading to quite a substantial boost in t/s especially for single decode (+15-40% tg, +8% pp).

Additional information

test-backend-ops test passes before and with d19075f, and KL divergence is 0 between the two. I have not tested KL divergence against CPU as the CPU pass would take 6+ hours on my machine.

I'm not able to test HIP/ROCm or MUSA. If either don't support __byte_perm, I will add a fallback path.

test-backend-ops perf

before d19075f:

Backend 1/2: CUDA0
  Device description: NVIDIA GeForce RTX 3090
  Device memory: 24120 MB (23468 MB free)

  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=1,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   873300 runs -  34.38 us/run - 117.44 MFLOP/run -  3.42 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=2,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   825588 runs -  36.35 us/run - 234.88 MFLOP/run -  6.46 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=3,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   707160 runs -  42.43 us/run - 352.32 MFLOP/run -  8.30 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=4,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   576591 runs -  52.04 us/run - 469.76 MFLOP/run -  9.03 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=5,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   562248 runs -  53.37 us/run - 587.20 MFLOP/run - 11.00 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=8,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   384237 runs -  78.08 us/run - 939.52 MFLOP/run - 12.03 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=512,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):  43456 runs - 690.37 us/run -  60.13 GFLOP/run - 87.10 TFLOPS
  Backend CUDA0: OK

with d19075f:

Backend 1/2: CUDA0
  Device description: NVIDIA GeForce RTX 3090
  Device memory: 24120 MB (23469 MB free)

  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=1,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):  1303560 runs -  23.02 us/run - 117.44 MFLOP/run -  5.10 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=2,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):  1238382 runs -  24.23 us/run - 234.88 MFLOP/run -  9.70 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=3,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   873016 runs -  34.37 us/run - 352.32 MFLOP/run - 10.25 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=4,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   644538 runs -  46.55 us/run - 469.76 MFLOP/run - 10.09 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=5,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   647577 runs -  46.33 us/run - 587.20 MFLOP/run - 12.68 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=8,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   418584 runs -  71.68 us/run - 939.52 MFLOP/run - 13.11 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=512,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):  47994 runs - 625.08 us/run -  60.13 GFLOP/run - 96.19 TFLOPS
  Backend CUDA0: OK
llama-batched-bench

merged output of
llama-batched-bench -no-kvu -ngl all -fit off -ub 1024 -npp 0,256,4096 -ntg 256 -npl 1,2,4,8 -m Ternary-Bonsai-8B-Q2_0_g64.gguf
and
llama-batched-bench -no-kvu -ngl all -fit off -ub 1024 -npp 16384,32768 -ntg 256 -npl 1 -m Ternary-Bonsai-8B-Q2_0_g64.gguf

before d19075f:

PP TG B N_KV T_PP s S_PP t/s T_TG s S_TG t/s T s S t/s
0 256 1 256 0.000 0.00 1.533 166.97 1.533 166.97
0 256 2 512 0.000 0.00 1.677 305.34 1.677 305.34
0 256 4 1024 0.000 0.00 2.233 458.48 2.233 458.48
0 256 8 2048 0.000 0.00 2.941 696.34 2.941 696.34
256 256 1 512 0.054 4782.72 1.540 166.21 1.594 321.26
256 256 2 1024 0.097 5263.64 1.713 298.88 1.810 565.65
256 256 4 2048 0.187 5470.00 2.311 443.06 2.498 819.73
256 256 8 4096 0.370 5535.55 3.036 674.51 3.406 1202.50
4096 256 1 4352 0.799 5127.60 1.716 149.19 2.515 1730.60
4096 256 2 8704 1.595 5135.29 2.047 250.13 3.642 2389.76
4096 256 4 17408 3.185 5143.32 2.984 343.14 6.170 2821.52
4096 256 8 34816 6.388 5129.79 4.347 471.14 10.735 3243.31
16384 256 1 16640 3.975 4121.32 2.225 115.05 6.200 2683.67
32768 256 1 33024 10.173 3220.92 2.933 87.29 13.106 2519.72

with d19075f:

PP TG B N_KV T_PP s S_PP t/s T_TG s S_TG t/s T s S t/s
0 256 1 256 0.000 0.00 1.110 230.54 1.110 230.54
0 256 2 512 0.000 0.00 1.216 421.16 1.216 421.16
0 256 4 1024 0.000 0.00 1.901 538.56 1.901 538.56
0 256 8 2048 0.000 0.00 2.710 755.80 2.710 755.80
256 256 1 512 0.048 5332.56 1.106 231.37 1.154 443.49
256 256 2 1024 0.089 5780.93 1.244 411.48 1.333 768.27
256 256 4 2048 0.169 6049.65 1.974 518.68 2.144 955.44
256 256 8 4096 0.336 6086.85 2.804 730.44 3.140 1304.36
4096 256 1 4352 0.730 5611.29 1.285 199.27 2.015 2160.16
4096 256 2 8704 1.454 5635.80 1.581 323.81 3.035 2868.14
4096 256 4 17408 2.912 5625.56 2.653 385.92 5.566 3127.66
4096 256 8 34816 5.827 5623.57 4.123 496.68 9.950 3498.99
16384 256 1 16640 3.700 4427.73 1.802 142.07 5.502 3024.25
32768 256 1 33024 9.622 3405.36 2.502 102.33 12.124 2723.82

Requirements

@dfriehs
dfriehs requested review from a team and ggerganov as code owners July 12, 2026 23:51
@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Jul 12, 2026
@Green-Sky

Copy link
Copy Markdown
Collaborator

@khosravipasha how is the cuda pr coming along?

@khosravipasha

khosravipasha commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Mostly ready. Waiting for metal to merge as policy is to have one PR open at a time. Can send ours as draft PR here instead of waiting. This is the bracnh planning to submit https://github.com/PrismML-Eng/llama.cpp/tree/pr/q2_0-cuda

Interesting speed up, need to take a closer look tomorrow.

@JohannesGaessler

Copy link
Copy Markdown
Contributor

The CUDA changes should be scheduled after #24127 .

@dfriehs
dfriehs marked this pull request as draft July 13, 2026 16:42
@dfriehs

dfriehs commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

I've been interested in running the Q2_0 version of Bonsai-27b, so I rebased onto current master.

I'm planning to have this PR wait for @khosravipasha's PR as well as #25628.

test-backend-ops perf

reference unpacking (c3a6223):

Backend 1/2: CUDA0
  Device description: NVIDIA GeForce RTX 3090
  Device memory: 24120 MB (23032 MB free)

  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=1,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   29820 runs -  34.34 us/run - 117.44 MFLOP/run -   3.42 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=2,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   28116 runs -  35.87 us/run - 234.88 MFLOP/run -   6.55 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=3,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   24140 runs -  41.47 us/run - 352.32 MFLOP/run -   8.50 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=4,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   20022 runs -  50.25 us/run - 469.76 MFLOP/run -   9.35 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=5,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   19494 runs -  51.57 us/run - 587.20 MFLOP/run -  11.39 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=8,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   13268 runs -  75.44 us/run - 939.52 MFLOP/run -  12.45 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=512,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):  1496 runs - 668.51 us/run -  60.13 GFLOP/run -  89.95 TFLOPS
  Backend CUDA0: OK

this PR (16a019d):

Backend 1/2: CUDA0
  Device description: NVIDIA GeForce RTX 3090
  Device memory: 24120 MB (23016 MB free)

  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=1,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   43452 runs -  23.23 us/run - 117.44 MFLOP/run -   5.06 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=2,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   41748 runs -  24.03 us/run - 234.88 MFLOP/run -   9.78 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=3,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   30104 runs -  33.34 us/run - 352.32 MFLOP/run -  10.57 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=4,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   22152 runs -  45.32 us/run - 469.76 MFLOP/run -  10.36 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=5,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   22572 runs -  44.64 us/run - 587.20 MFLOP/run -  13.16 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=8,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):   14659 runs -  68.64 us/run - 939.52 MFLOP/run -  13.69 TFLOPS
  MUL_MAT(type_a=q2_0,type_b=f32,m=4096,n=512,k=14336,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1):  1666 runs - 600.72 us/run -  60.13 GFLOP/run - 100.10 TFLOPS
  Backend CUDA0: OK
llama-batched-bench

merged output of
llama-batched-bench -no-kvu -ngl all -fit off -ub 1024 -c 65536 -npp 0,256,4096 -ntg 256 -npl 1,2,4,8 -m Ternary-Bonsai-27B-Q2_g64.gguf
and
llama-batched-bench -no-kvu -ngl all -fit off -ub 1024 -c 65536 -npp 16384,32768 -ntg 256 -npl 1 -m Ternary-Bonsai-27B-Q2_g64.gguf

reference unpacking (c3a6223):

PP TG B N_KV T_PP s S_PP t/s T_TG s S_TG t/s T s S t/s
0 256 1 256 0.000 0.00 4.703 54.43 4.703 54.43
0 256 2 512 0.000 0.00 5.507 92.98 5.507 92.98
0 256 4 1024 0.000 0.00 8.210 124.72 8.210 124.72
0 256 8 2048 0.000 0.00 12.331 166.09 12.331 166.09
256 256 1 512 0.189 1357.08 4.728 54.14 4.917 104.13
256 256 2 1024 0.363 1409.47 5.560 92.09 5.923 172.89
256 256 4 2048 0.711 1440.69 8.279 123.69 8.990 227.81
256 256 8 4096 1.423 1438.73 12.440 164.63 13.863 295.45
4096 256 1 4352 2.902 1411.39 4.828 53.02 7.730 562.99
4096 256 2 8704 5.815 1408.88 5.745 89.12 11.559 752.98
4096 256 4 17408 11.636 1408.07 8.628 118.68 20.264 859.07
4096 256 8 34816 23.314 1405.53 13.121 156.09 36.434 955.58
16384 256 1 16640 12.214 1341.46 5.053 50.67 17.266 963.73
32768 256 1 33024 26.485 1237.22 5.374 47.64 31.859 1036.56

this PR (16a019d):

PP TG B N_KV T_PP s S_PP t/s T_TG s S_TG t/s T s S t/s
0 256 1 256 0.000 0.00 3.448 74.24 3.448 74.24
0 256 2 512 0.000 0.00 3.959 129.34 3.959 129.34
0 256 4 1024 0.000 0.00 6.914 148.10 6.914 148.10
0 256 8 2048 0.000 0.00 10.753 190.45 10.753 190.45
256 256 1 512 0.174 1473.61 3.435 74.53 3.609 141.88
256 256 2 1024 0.333 1537.13 3.986 128.45 4.319 237.10
256 256 4 2048 0.654 1566.40 6.983 146.64 7.637 268.18
256 256 8 4096 1.306 1568.10 10.841 188.92 12.147 337.21
4096 256 1 4352 2.672 1533.15 3.522 72.70 6.193 702.71
4096 256 2 8704 5.338 1534.61 4.143 123.58 9.481 918.01
4096 256 4 17408 10.678 1534.31 7.298 140.31 17.976 968.38
4096 256 8 34816 21.391 1531.88 11.498 178.12 32.888 1058.61
16384 256 1 16640 11.308 1448.93 3.752 68.23 15.060 1104.92
32768 256 1 33024 24.687 1327.32 4.064 63.00 28.751 1148.62

@khosravipasha

Copy link
Copy Markdown
Contributor

@dfriehs Was this rebased after our latest branch? If yes let me do some testing on my side today, I am probably okay with just merging this one too, was there any big change when doing the rebase?
Or do you want this PR to just be the __byte_perm changes after I send a PR for Q2_0 cuda?

@dfriehs

dfriehs commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@khosravipasha

Was this rebased after our latest branch?

No, it's still the commit from the prism branch as before. As far as I could tell, there was no difference between that commit and the PR branch except for fixing VDR_Q2_0_Q8_1_MMQ (which I did too), so I just rebased that one.

was there any big change when doing the rebase?

All the changes in mmq.cuh needed to get moved around basically, and you need some mmq configs. I just copied the ones available for Q1_0 per architecture.

I am probably okay with just merging this one too, or do you want this PR to just be the __byte_perm changes after I send a PR for Q2_0 cuda?

I don't mind either way, it's your call. One PR might be less work for reviewers, so if you don't mind I'd err on that side. Can't have two PRs out of draft, however, so it might need to wait.

@dfriehs

dfriehs commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@khosravipasha

Sorry, if you meant this as in

Was this rebased after [we rebased] our latest [PR] branch?

then yes, this is post mmq refactor (rebased on b10011).

MarkShark2 added a commit to MarkShark2/llama.cpp that referenced this pull request Jul 15, 2026
Q2_0 (ternary) GPU kernels for CUDA and Vulkan, cherry-picked from the
upstream-targeted PrismML PR branches (ggml-org#25603 cuda, ggml-org#25430 vulkan). Upstream
already carries the Q2_0 type + CPU backend (ggml-org#24448) and the qwen35 arch, so
these kernels are the only gap for running Ternary-Bonsai-27B (Q2_g64).
@khosravipasha

khosravipasha commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

I see thanks, I meant both, I did the rebasing and did a bit more test.
If thats ok then rebuild on top of this PR after its merged, your changes with __byte_perm look great too but did not want to mix them. Will test those myself as well.

Wanted to add some speed numbers, and also pointin people to the the right gguf models.
#25707

@dfriehs dfriehs changed the title cuda: Support Q2_0 cuda: extract Q2_0 elements via __byte_perm Jul 30, 2026
@dfriehs

dfriehs commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@khosravipasha, if you don't mind I'd appreciate some tests on your side again. The changes should have only touched the integer unpacking so I expect the logits to match exactly, and KLD between 9b2a088 and a487841 is pretty much just noise for me:

====== Perplexity statistics ======
Mean PPL(Q)                   :  11.454627 ±   0.086796
Mean PPL(base)                :  11.448741 ±   0.086674
Cor(ln(PPL(Q)), ln(PPL(base))):  99.99%
Mean ln(PPL(Q)/PPL(base))     :   0.000514 ±   0.000085
Mean PPL(Q)/PPL(base)         :   1.000514 ±   0.000085
Mean PPL(Q)-PPL(base)         :   0.005885 ±   0.000980

====== KL divergence statistics ======
Mean    KLD:  -0.000000 ±   0.000000
Maximum KLD:   0.000067
99.9%   KLD:   0.000049
99.0%   KLD:   0.000036
95.0%   KLD:   0.000022
90.0%   KLD:   0.000016
Median  KLD:  -0.000000
10.0%   KLD:  -0.000016
 5.0%   KLD:  -0.000023
 1.0%   KLD:  -0.000036
 0.1%   KLD:  -0.000049
Minimum KLD:  -0.000066

====== Token probability statistics ======
Mean    Δp:  0.000 ± 0.000 %
Maximum Δp:  0.006%
99.9%   Δp:  0.004%
99.0%   Δp:  0.002%
95.0%   Δp:  0.001%
90.0%   Δp:  0.000%
75.0%   Δp:  0.000%
Median  Δp:  0.000%
25.0%   Δp: -0.000%
10.0%   Δp: -0.000%
 5.0%   Δp: -0.001%
 1.0%   Δp: -0.002%
 0.1%   Δp: -0.004%
Minimum Δp: -0.005%
RMS Δp    :  0.001 ± 0.000 %
Same top p: 99.997 ± 0.001 %

For the benchmarks I still see the same improvements as above, around +15-40% tg, +8% pp on a RTX 3090. I'm planning to have the PR leave draft once #26264 is closed.

@khosravipasha

Copy link
Copy Markdown
Contributor

@dfriehs Thanks for adding this and rebeasing, got some solid speed ups on L40S, should be similar on other GPUs and accurary is good, more details below

========

  • GPU: NVIDIA L40S (sm_89), CUDA 12.8
  • before: 9b2a08881 (CUDA: add Q2_0 support (#25707))
  • after: a4878413e (cuda: extract Q2_0 elements via __byte_perm)
  • models: Ternary-Bonsai-{1.7B,4B,8B,27B}-Q2_0_g64.gguf

Commands

# build before/after
git worktree add --detach bp-before 9b2a08881
git worktree add --detach bp-after  a4878413e
for d in bp-before bp-after; do
  cmake -S $d -B $d/build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89 -DCMAKE_BUILD_TYPE=Release -G Ninja
  cmake --build $d/build -j --target llama-bench llama-perplexity
done

# speed
./bp-before/build/bin/llama-bench -m <model>.gguf -ngl 99 -fa 1 -p 512 -n 128 -r 3
./bp-after/build/bin/llama-bench  -m <model>.gguf -ngl 99 -fa 1 -p 512 -n 128 -r 3

# KL (before vs after)
./bp-before/build/bin/llama-perplexity -m <model>.gguf -f wiki.test.raw -c 512 --chunks 20 -ngl 99 \
  --save-all-logits before.bin
./bp-after/build/bin/llama-perplexity  -m <model>.gguf -f wiki.test.raw -c 512 --chunks 20 -ngl 99 \
  --kl-divergence --kl-divergence-base before.bin

Speed (t/s)

model tg128 before tg128 after tg Δ pp512 before pp512 after pp Δ
1.7B 532.05 585.24 +10.0% 30114.97 32365.29 +7.5%
4B 322.65 343.91 +6.6% 16418.66 17225.02 +4.9%
8B 239.06 245.97 +2.9% 10561.75 11782.98 +11.6%
27B 71.95 74.16 +3.1% 2811.83 2998.27 +6.6%

KL divergence (before vs after)

model Mean KLD Maximum KLD Same top-1
1.7B 0.000000 0.000059 100.000%
8B -0.000000 0.000066 100.000%

@dfriehs
dfriehs marked this pull request as ready for review July 31, 2026 04:02
@Green-Sky

Copy link
Copy Markdown
Collaborator

Should be a simple merge now. 🚀


$ llama-bench -m models/Ternary-Bonsai-8B-Q2_0_g64.gguf -ngl 99 -fa 1 -p 512 -n 128 -ctk q8_0 -ctv q8_0
$ llama-bench -m models/Ternary-Bonsai-8B-Q2_0_g64.gguf -ngl 99 -fa 1 -p 512 -n 128 -ctk f16 -ctv f16

before

model size params backend ngl type_k type_v fa test t/s
qwen3 8B Q2_0 2.15 GiB 8.19 B CUDA 99 q8_0 q8_0 1 pp512 1290.16 ± 17.38
qwen3 8B Q2_0 2.15 GiB 8.19 B CUDA 99 q8_0 q8_0 1 tg128 58.24 ± 0.08
qwen3 8B Q2_0 2.15 GiB 8.19 B CUDA 99 f16 f16 1 pp512 1317.81 ± 16.00
qwen3 8B Q2_0 2.15 GiB 8.19 B CUDA 99 f16 f16 1 tg128 59.74 ± 0.11

after

model size params backend ngl type_k type_v fa test t/s
qwen3 8B Q2_0 2.15 GiB 8.19 B CUDA 99 q8_0 q8_0 1 pp512 1423.95 ± 21.26
qwen3 8B Q2_0 2.15 GiB 8.19 B CUDA 99 q8_0 q8_0 1 tg128 72.30 ± 0.18
qwen3 8B Q2_0 2.15 GiB 8.19 B CUDA 99 f16 f16 1 pp512 1461.13 ± 21.23
qwen3 8B Q2_0 2.15 GiB 8.19 B CUDA 99 f16 f16 1 tg128 74.57 ± 0.11

Device 0: NVIDIA GeForce RTX 2070, compute capability 7.5, VMM: yes, VRAM: 7777 MiB

@am17an am17an added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Jul 31, 2026
@ggerganov
ggerganov merged commit 15e755f into ggml-org:master Jul 31, 2026
1 check passed
khosravipasha pushed a commit to PrismML-Eng/llama.cpp that referenced this pull request Jul 31, 2026
Port of ggml-org#25603 (upstream commit 15e755f) adapted to
this fork's group-size-128 Q2_0. Upstream's tile-load lives in
mmq-load-tiles.cuh after their MMQ refactor; ours is still in mmq.cuh, so
this is a manual port rather than a cherry-pick.

The technique is group-size agnostic: it consumes 4 int16 (32 codes) per
Q8_1 chunk, and that chunk size comes from Q8_1's 32-element block rather
than from QK2_0, so the iqs*4 indexing is unchanged for g128.

The decode path previously summed unsigned codes and applied a deferred
-sum(act) correction; __byte_perm yields signed symbols directly, so the
tail becomes d2*d8*sumi. Both reduce to d2*d8*sum((c-1)*q8).
@dfriehs
dfriehs deleted the q2_0-cuda branch July 31, 2026 22:52
kashif pushed a commit to kashif/llama.cpp that referenced this pull request Aug 2, 2026
huaxel pushed a commit to huaxel/CachyLLama that referenced this pull request Aug 2, 2026
smalinin pushed a commit to smalinin/llama.cpp that referenced this pull request Aug 4, 2026
satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 11, 2026
satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 12, 2026
Pipyakas added a commit to Pipyakas/llama.cpp that referenced this pull request Aug 15, 2026
Squashed overlay of the custom-hardware fork (45 files, +3255/-11) on top of
upstream master:

- MoE expert cache: GPU-accelerated LRU cache for CPU-resident MoE experts
  (ggml-cuda/moe-cache.cu, backend hooks, fit placement, --moe-cache flag),
  toggleable via -DGGML_MOE_CACHE
- maple arch + TQ ternary quants + Q2_0_128 type (ggml + CUDA kernels, GGUF
  type-42 remap), toggleable via -DGGML_MAPLE
- q2_0/q4_0 vecdot byte_perm port (upstream ggml-org#25603)
- server reasoning_effort -> thinking_budget mapping
- ROCm bring-up fixes: HIP stream-priority/popcnt portability, clang prefetch
  casts, loader mmap-bypass reverted (caused GPU load hang)
Pipyakas added a commit to Pipyakas/llama.cpp that referenced this pull request Aug 15, 2026
Squashed overlay of the custom-hardware fork (45 files, +3255/-11) on top of
upstream master:

- MoE expert cache: GPU-accelerated LRU cache for CPU-resident MoE experts
  (ggml-cuda/moe-cache.cu, backend hooks, fit placement, --moe-cache flag),
  toggleable via -DGGML_MOE_CACHE
- maple arch + TQ ternary quants + Q2_0_128 type (ggml + CUDA kernels, GGUF
  type-42 remap), toggleable via -DGGML_MAPLE
- q2_0/q4_0 vecdot byte_perm port (upstream ggml-org#25603)
- server reasoning_effort -> thinking_budget mapping
- ROCm bring-up fixes: HIP stream-priority/popcnt portability, clang prefetch
  casts, loader mmap-bypass reverted (caused GPU load hang)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants