r/LocalLLaMA • • 4d ago

Resources UPDATE: Qwen 3.8 27B 140 tok/s on single RTX 3090 Megakernel: KL divergence 0.0009 vs llama.cpp

This is a follow-up to my post from yesterday (https://www.reddit.com/r/LocalLLaMA/comments/1x2erdj/qwen3827b_on_a_single_3090_140_toks_on_code_with/) detailing the CUDA megakernel. Thank you all for the positive feedback and PRs!

RECAP: The megakernel is a CUDA engine for Qwen3.8-27B that runs 1.4-1.9x faster than llama.cpp on a single 3090. The most common questions were about accuracy, the baseline and context size, so here are the numbers.

Code and benchmarks: https://github.com/L-Forster/open-jet/tree/master/megakernel

Firstly, I benchmarked the engine accuracy against llama.cpp. No measurable loss in quality:

Decode accuracy vs llama.cpp

Context Positions MK top token MK KL LC top token LC KL
1K 13,299 99.08% 0.0009 98.68% 0.0019
30K 1,999 99.65% 0.0007 99.35% 0.0009
96K 1,999 99.60% 0.0008 99.45% 0.0014

MK = megakernel, LC = llama.cpp batched. Top token = how often the top token matches the reference. KL = mean KL divergence in nats.

  • Perplexity (1K run only): megakernel 2.4274, llama.cpp batched 2.4283, reference 2.4263.
  • Log-loss vs the reference: +0.0005 +/- 0.0004 at 1K, +0.0018 +/- 0.001 at 30K, +0.0012 +/- 0.001 at 96K. Not significant.
  • The 30K and 96K rows are one sequence of code each & the 1K row is code and prose.
  • Speculative decoding is exact: greedy output is the main model's greedy choice, and sampling keeps the same distribution as without drafts.

Speed (same 3090, megakernel vs llama.cpp with MTP)

  • Writing code: 140 vs 73 tok/s
  • Reasoning mode: 78 vs 51 tok/s
  • With 30K tokens of code in context: 73 vs 52 tok/s
  • Prompt processing (prefill): ~1,600 vs ~1,100 tok/s
  • With speculative decoding off they are about equal (42.9 vs 40.4). The gain comes from checking 4-5 drafted tokens per pass for about the cost of one. llama.cpp ran at 2 drafts, the megakernel at 4.

Since the first post

  • Two PRs have been merged: the loader now checks every tensor's type, and the server warms up before accepting requests.
  • Model download fixed after unsloth removed the Q4_K_M from their repo.
  • It also loads the Q4_K_M from lmstudio-community and mradermacher.
  • openjet setup shows which engine each model will use.

Quantisation support

This table details the quantisation support, with unsloth Q4_K_M being the native model and what I benchmarked, lmstudio and mradermacher being semi-compatible, not fully benchmarked, tentative results show similar speed to native after type conversions. Other quants fall back to llama.cpp

Qwen3.8-27B file Runs on
unsloth's original Q4_K_M (what openjet setup downloads) megakernel
Q4_K_M from lmstudio-community, mradermacher megakernel, semi-compatible
Other quants (unsloth UD-*, bartowski, GSQ-RCO and others) llama.cpp

Limits

  • Single GPU. RTX 30/40/50 series with 24 GB or more. MK is tuned on a 3090 only.
  • 147K context runs on a 3090 (fp16 KV cache to ~80K, using q8 above).
  • No task-level pass-rate benchmark yet.

Contributions that would help

  • Tunes for specific hardware: RTX 4090, 5090 and other 24 GB+ cards. It has only been tuned on a 3090.
  • Support for other quantisations of Qwen3.8-27B.
  • Please include benchmarks with the PR: your GPU, and bench/bench.py or bench/code_bench.py numbers before and after.

How to contribute: see CONTRIBUTING.md in the repo.

Comment the quant you use for Qwen3.8-27B so I know what to add support for next! (also planning for Qwen 4 when that drops).

72 Upvotes

33 comments sorted by

13

u/Barni275 4d ago

Numbers are very nice, cheers! One of my GPU id 3090, but, unfortunately, for context, I use two GPUs , and all these custom speedy forks pass by my, only llamacpp is flexible enough to utilize it. :(

3

u/OhGeeLIVE 3d ago

Same boat, so I made a two-GPU fork of this one. On 2x 3090 it does 164 tok/s average vs 100 for llama.cpp with tensor split, and it holds up at long context (105 vs 67 tok/s with 56K tokens of code in the prompt). Catch: both cards need PCIe P2P, which on GeForce means the patched open driver.

https://github.com/ohgeebtw/dual-gpu-megakernel

-4

u/voogamer 4d ago

Yeah everyone making custom engines for the GPU poor. Start making engines for the 4+ GPU gang please

4

u/DataGOGO 4d ago

sectilelabs.ai/gbench

Supports 1/2/4 GPU's, all 30, 40, 50 series + A100/CMP 170HX.

Even runs Qwen3.8 27B on 6 year old 16GB vram 3080ti laptop with 162k context length at:

3080 Ti Laptop - GInfer v1.0.0.3 standard benchmark (2048 in / 500 out, INT8 KV, 256 MiB reserve)

Model       C    TG (t/s)   Cold PP (t/s)   Warm PP (t/s)
Qwen smol   1       269.0           630.4         390,885
Qwen smol   4       352.9               -         733,569
Qwen smol   8       412.9               -         788,199
Muse smol   1       136.6           628.6         458,028
Muse smol   4       239.7               -         610,384
Muse smol   8       314.3               -         650,122

  • = not measured (prompt was already cached from the C1 run)
3080 Ti Laptop - GInfer v1.0.0.3, KV reserve 256 MiB - full pass (tok/s) Cell TG Cold PP Cold TTFT Warm PP Qwen smol C8, 2048 in/4000 out 378.2 618.7 3.3 s 776,000 Muse smol C8, 2048 in/4000 out 289.8 623.3 3.3 s 758,000 Qwen smol C1, 162,240 in/512 out 52.7 324.9 499.5 s 9,770,000 Muse smol C1, 129,984 in/512 out 58.4 432.0 301.0 s 17,600,000

Faster than any other inference engine by a lot. Support Qwen 27B / Muse 30B, Qwen flash next + GLM 5.3 Flash, tiered offloads, sliding attention, state of the art K/V system, adaptive draft lengths on Dflash2, adaptive prefix caching. It is slick. Can't wait for them to release it (should be in a week or 2).

1

u/Edenar 4d ago

what is qwen smol ? I'm sorry but 27b @ 269 tok/s tg on a single stream with a 512gb/s card is either very low quant and dflash 100% acceptable (not realistic) or i can't believe it. But maybe i'm wrong and it's insane ? Can you run some real output like try to output 20k token on a real prompt and mesure speeds ? I'm curious.

1

u/DataGOGO 4d ago edited 4d ago

Smol is made for 16GB cards (like the laptop), it is a mixed precision 2/4/8 bit quant, with some left in BF16/FP32. The test above is a kernel tester, it is a 2k repeated prompt pattern designed to test the kernels during tuning, PP, and the prefix cache.

Not sure if you noticed, but the very bottom block has 2k in, 4k out, and 162k in, 512 out.

3080 Ti Laptop - GInfer v1.0.0.3, KV reserve 256 MiB - full pass (tok/s)

Cell                              TG      Cold PP   Cold TTFT    Warm PP
Qwen smol C8, 2048 in/4000 out   378.2     618.7      3.3 s       776,000
Muse smol C8, 2048 in/4000 out   289.8     623.3      3.3 s       758,000
Qwen smol C1, 162,240 in/512 out  52.7     324.9    499.5 s     9,770,000
Muse smol C1, 129,984 in/512 out  58.4     432.0    301.0 s    17,600,000

Sure, give me a few and I will run it and post it here.

Model: Qwen3.8 27B smol. 3080ti laptop, 16GB vram, Reasoning: high, Dflash2: Dynamic draft length, K/V Int 8.

1K prompt, 20k output (asked it for a history of AI basically) via api:

3080 Ti Laptop - GInfer v1.0.0.6, KV reserve 256 MiB 

                                    Total Context   t/ps
PP   1,020 prompt (cold)            1k              1,269
TG   19.7k                          22.2k           112

Here is what the benchmark interface looks like in the client:

1

u/ThePixelHunter 3d ago

Your GitHub repo 404's

1

u/DataGOGO 3d ago

It is not mine, it is there, just empty and set to private.

11

u/DelicateTicker 4d ago

that KL divergence is basically zero, wild to see it holding up at 96k context too

been running the unsloth Q4_K_M and the speed difference is noticeable even without measuring, my fans aren't screaming anymore

4

u/StupidScaredSquirrel 4d ago

You should also try undervolting your card. Look up for more ressources but you can basically reduce power need by 30% with no impact on speed

2

u/me0here 4d ago

There's a speed impact, but closer to -5%, more if you undervolt drastically.

Possible to increase speed by a -20 Watt undervolt when card throttling.

I keep mine at 310W for bursty AI image work, 290W for longer term workloads.  Most do 275-250W, but I have extra fans on my card.

4

u/DefNattyBoii 4d ago

how about parallel requests, cont. batching etc?

2

u/DataGOGO 4d ago edited 4d ago

You still have a ton of headroom there on the 3090. Here is my latest result on the tuned 3090 kernels for ginfer.

3090, standard clocks/power limits, Qwen 27B mixed precision Q4, dflash2, 2k/500 prompt, generation, 162k MAX context length:

RTX 3090, Qwen 27B INT                C1       C4       C8   (tok/s)
                                      503.5    860.1   1095

1

u/Vektast 4d ago

500+ tok/s c1 decode on qwen 3.8 27b with a single 3090? no way bro

1

u/DataGOGO 4d ago edited 4d ago

ran again just to be sure, Qwen 3.8 27B, mixed precision quant, mainly 4 bit, 2k prompt / 500 generation + Dflash2 K15.

T/G

GPU            steps/s   tokens/step   TG (C1)
RTX 3090          33         15.1         499
RTX 4090          43         15.1         650
RTX 5090          64         15.1         965
RTX PRO 6000      65         15.1         981

T/G:

GPU            C1 TG     C4 TG     C8 TG
RTX 3090         499       849     1,088
RTX 4090         650     1,682     2,429
RTX 5090         965     2,396     3,127
RTX PRO 6000     981     2,291     3,119

PP:

GPU            C1 cold   C4 cold   C8 cold    C1 warm     C4 warm     C8 warm
RTX 3090         1,960     1,957     1,953    561,238   1,051,482   1,349,566
RTX 4090         4,634     4,624     4,629    520,079   1,022,519   1,230,588
RTX 5090         6,411     6,767     6,719    575,441     748,382     944,503
RTX PRO 6000     6,321     6,027     5,947    798,892   1,403,774   1,851,361

1

u/Vektast 4d ago

Okay.. it's too good to be true, but where to download? Github link is give 404 error
500tg with tiny context or just prompt repeat?

1

u/DataGOGO 4d ago edited 4d ago

It is a kernel test, it is repeating prompt pattern that hits all the different kernels. Tests the inference kernels on each layer, and the cold > warm PP test the prefix cache and K/V system. It is designed to test inference against the full hardware capability to look for areas that can be improved. each model / GPU combo has it's own hot path and kernels.

The benchmark site is https://sectilelabs.ai/gbench

Supports 4 models right now, Qwen 27b, Muse 30B, Qwen next flash, and GLM 5.3 Flash. Each with 1/2/4 GPU's, C1-C8.

Supports hybrid inference, multi-stage vram > memory > disk without skipping experts like Strata / infernix, has CPU kernels for AVX, AVX2, AVX 512, AMX, VINNI, etc. will do CPU only inference as well. Windows, WSL, and Linux.

Supports all A100/CMP 170HX (sm_80), 30xx, 40xx, 50xx, and all RTX pro Blackwell.

Not sure when they are going to release it, Not my project, I just know them and I am just testing. Told a week or two, working on the kernels for Qwen flash next right now.

Also has a pretty slick little server manager in it, all the hosts on your LAN, register and pair, you can define work pools. Single chat client and interface can and control all hosts, and distribute swarms across the work pools, or you can use the dedicated server manager.

really neat, and very quick,

repos are up, but empty until release.

SectileLabs/ginfer

SectileLabs/gchat

1

u/Simple_Library_2700 4d ago

Before anyone confuses this being able to accept every one of your drafter tokens means the workload here is not representative of real-world decode.

(Especially 15 tokens deep)

1

u/DataGOGO 4d ago

no, it is engine / kernel benchmark

1

u/Taenk 4d ago

You need to document where that inference speed could possibly come from and what interventions had which impact. Because this is well beyond what that card could possibly give with that model.

1

u/DataGOGO 4d ago edited 4d ago

Not my project, I am just helping test.

Case study: building GInfer with Quaestor — Sectile Research Laboratories

talks about how they made it.

That is what it is running, test is a 2k repeating prompt pattern used to test the different kernels, (which is why the warm PP is so high, it is 100% cached after first read) + dflash2.

1

u/winky9827 4d ago

where can I find more on this ginfer?

1

u/DataGOGO 4d ago

Sectile Research Laboratories

Click opensource, the case study is how they made it.

Case study: building GInfer with Quaestor — Sectile Research Laboratories

it isn't released yet, told another week or two, It isn't my project, I am just helping test.

2

u/Taenk 4d ago

Awesome work. I had Claude and ChatGPT have a go at similar optimisations the other week but yours blew mine out of the water. The things I tried was n-gram reuse, tuning DFlash, some kernel tuning and what I called "card shaped quant", that is quantising such that the weights fit the card's quirks. I ran a head-to-head test of your version against mine (on the exact same weights, yours) and your megakernel approach is slightly better.

So I think for now one approach to improve your engine is to fiddle with the weights themselves a little bit -- that gave me about 15% boost using stock kernels. I tried bringing my n-gram reuse approach to your engine and while it massively increased code edit tasks (decode boost well over 100%) it hit prose, coding and thinking.

Besides fiddling with the quants, I found that you can offload the mmproj weights to regular RAM and pull them JIT for image encode. For single images it's barely a hit on processing time.

Comparing to what the 3090 could theoretically achieve there is still some room to grow:

Path Current, RTX 3090 Ideal hardware ceiling, RTX 3090 Realised efficiency
Prompt processing, short context 1,595 tok/s ~2,915 tok/s ~55%
Decode, no drafting 42.9 tok/s ~58 tok/s ~74%

Have you considered the same megakernel approach with other models like Qwen 3.6 35B-A3B or Nemotron Lightning 30B-A3B?

1

u/dsanft 4d ago

What is the mtp acceptance rate on your benchmarks, for lcpp and your own? This is going to be the biggest factor in decode speed.

1

u/bitzap_sr 4d ago

What happened to that unsloth quant?

1

u/chimpera 4d ago

So the quant the repo uses was removed from hugging face by unsloth.

1

u/caetydid llama.cpp 4d ago

Thanks for the follow up, this looks promising! I'd be really interested in vision support, especially in an implementation likewise https://github.com/Anbeeld/beellama.cpp/issues/179

1

u/Liberaces_Isopod 4d ago

What case is that? I see CPE PCCooler, but looking at their site i dont see that particular one.

Cool setup BTW. Youre doing better numbers than I am on 3x3090's.

1

u/Glittering-Call8746 4d ago

Anything at this point is faster than llama.cpp , what's the comparison with other single gpu focus inference engine ?

1

u/AdventurousFly4909 4d ago

I tried it out and got 100tok/s, that's ~40 tok faster than llama.cpp. Impressive.

1

u/OhGeeLIVE 3d ago

I made a tensor-parallel fork of this. On 2x 3090 it does 214 tok/s on code and 164 on average, vs 128 / 100 for llama.cpp tensor split on the same cards, and 105 vs 67 tok/s with 56K tokens of code in context.

Ran your KL test on it: the original, the fork on one card and the fork on two cards all score the same (96.75% top-token agreement, KL 0.004), so splitting costs no quality.

On more quants: the fork loads any per-tensor mix of Q4_K, Q5_K, Q6_K and Q8_0. Only Q4_K_M is benchmarked so far, but happy to validate the others and send it upstream as a PR if you want it.

https://github.com/ohgeebtw/dual-gpu-megakernel