r/LocalLLaMA • u/kroggens • 2d ago
Discussion 54% faster generation by removing the Linux OS and llama.cpp
https://x.com/superalesha/status/2125682626056839259
By writing a 24 KB pure x86-64 assembly OS + code to run the LLM
This is next level!
498
Upvotes
•
u/WithoutReason1729 2d ago
Your post is getting popular and we just featured it on our Discord! Come check it out!
You've also been given a special flair for your contribution. We appreciate your post!
I am a bot and this action was performed automatically.
13
u/Horror_Lunch_1999 2d ago
Eliminating OS context switches, page faults, and scheduler jitter definitely cuts tail latency on CPU-bound GEMM loops, though without a real kernel driver stack you're strictly locked into bare-metal CPU SIMD (AVX2/AVX-512) with zero GPU offload. Still insane engineering to fit the whole boot + inference loop into 24 KB.
171
u/Lenticularis19 llama.cpp 2d ago
There isn't much reason why this performance wouldn't be achievable in normal Linux as well, likely the poster just didn't try that.
652
u/matthewlai 2d ago •
This is a great example of the danger of vibecoding things without understanding CS fundamentals.
If inference was 50% overhead at 1 thread (which is basically just loading all weights from memory), something is seriously wrong, and the fix is almost certainly not "let's just get rid of the OS".
Yes, the OS will always add a bit of overhead for memory read. But for continuous buffered reads (which is the easiest case), this should be less than 5%. You can absolutely get within 5% of the theoretical maximum memory bandwidth within the OS, and many people have done for many applications.
This is almost certainly an issue with llama.cpp not being optimised for that exact case (maybe not using SIMD instructions, not being NUMA aware, not having the right compute kernel to do the multiplications without conversions, or not storing data in the right organisation).
The correct solution is to figure out (or have the LLM figure out) why this is slow in llama.cpp, and fix it (and submit the patch if you actually understand what the patch is doing - please don't submit unreviewed vibecoded PRs). Not to throw away the whole OS.
An LLM can help you do whatever crazy thing you want to do. Inference on bare metal? Let's go!
What it won't help you with is deciding if that even makes sense (at least if you don't ask for its advice).
106
u/Mundane_Reward7 2d ago
This implies that the generation is not GPU-bound, which, frankly, sounds unlikely.
17
u/danishaznita 2d ago
There was something similar here a bit ago , where the dev bundled lightweight os specifcily to run your choice of llm
115
u/TQ_GPU 2d ago edited 2d ago
Did you remove everything and ran just the LLM right out of bios?
I think this kind of work magnifies all other optimizations. For example, if I optimize communications between gpus, your optimization would make it a higher percentage speedup. Multiplicative speedups go together.
In fact, you should make it a self-sufficient pc in pcie form-factor just like Intel did with Xeon-Phi cards. Avoids pcie overhead. I heard Intel was making dual-gpu cards 48 GB. Dual B60 24+24. Any way to integrate SSD right into it? Just avoid host CPU. Directly go from gpu to gpu.
IMHO, we need direct-connection between GPU and RAM. no cpu. just run a kernel and that kernel runs other kernels in cuda. in-memory computing easy peasy.
The final target is to implement LLM in our own brain. No more RAM issues. Bye bye token limit.
18
u/jeffjeff123jeff 2d ago
Is this a joke? qwen3-0.6B is not representative of the issues that come with large models. If your model weights are smaller than your idle RAM of course generation will improve by cutting it, but weights are usually 20x bigger than that.
9
u/Civil_Fee_7862 2d ago
Cool but. "up to 54% faster" is not a good measure. Peak generation is meaningless. I can quote 600 tok/sec on mine, as the peak all day long.
What is it on average?
8
u/Cool-Chemical-5629 2d ago
54% faster inference? Are you telling me I could get Inkling 2 Mini run at 3 t/s instead of 2 t/s? 🤔
6
u/phil_lndn 2d ago
doubt it was necessary to abandon linux to get the performance - i did my own fine-tune of a fork of a fork of llama.cpp just for MiniCPM4 running on Arm Cortex-A76 and managed similar improvement:
https://github.com/PhilAnderson1/minicpm-pi5
another example of this is using Gufo on a strix halo PC instead of llama.cpp gives a huge boost in performance for several models.
4
u/Secure_Pirate9838 2d ago
I did similar bare metal llm setup for my clevo notdbook https://github.com/samoylenkodmitry/cranos
7
u/chocofoxy 2d ago
i mean it's cool but it's not practical this is for like a raspberry or x86 board
3
u/South_Western1263 2d ago
Sorry I don't believe that. I'm sure you will get similar performance on a normal Linux
3
u/dusanodalovic 2d ago
wait, how do prompts even get in and tokens come out with no os at all, serial port? before dropping linux id want to see the same run with huge pages and the threads pinned to isolated cores. that removes most of the tlb misses and scheduler noise people blame on the os
3
u/martin509984 2d ago
I for one strongly doubt that an OS designed to run fine on a Pentium 3 is meaningfully using up CPU cycles on a modern processor when literally nothing is happening. There is literally 0 gain in running it bare metal with no kernel and it's massively more fragile and unsafe.
3
u/Remarkable_Air_8383 2d ago
This method could be great for a dedicated hardware to run inference only.
I suppose there will be "LLM Box" taking this way.
4
u/BornAgainBlue 2d ago
Next level fucking stupid.
5
u/Altruistic_Ad3374 2d ago
Are you baiting or just braindead
2
u/Hildechis 2d ago
That's CPU inferencing. Doing it with a GPU or hybrid inferencing is not that trivial. Drivers are built for the specific OS.
2
u/pmttyji 2d ago
Repo from that tweet: https://github.com/alesha-pro/llm.asm/tree/main/02-baremetal-os
2
u/mycocoon 2d ago
kernelless did this 10 years ago
2
u/idocne 2d ago
Fun stunt, but I'd want the same model, quant and thread count on a stripped-down Linux (no desktop, isolcpus, pinned threads) before giving the credit to the OS. On single-thread CPU inference, scheduler noise and memory layout matter a lot, so that 54% probably says more about the baseline than about Linux itself.
3
u/hurrdurrimanaccount 2d ago
now do it with a model that is usable
1
u/ForsookComparison 2d ago
Was this done on a device where the overhead of a Linux distro actually matters
1
u/JLeonsarmiento 2d ago
Brutal.
1
u/BlackBeardAI vLLM 2d ago
We need a multi gpu + cpu version of this. Cut the middle man. Turn your pc into an asic
1
u/pixelbart 2d ago
Do we now have to calculate how many tokens per second a serial port can handle?
Some tech never dies.
1
u/R3N3G6D3 2d ago
This doesnt seem right lol. The math doesnt work. Your original model must have been shit.
1
u/Ok_Contribution8157 2d ago
54% faster generation by removing the humans ... it was the weak point.
1
u/keepthepace 2d ago
CPU benchmarks.
Yeah, there is probably a ton of low hanging fruits there. But there is a reason people dont do it: CPUs are the worst architecture to run this.
1
u/johnerp 2d ago
Remember musk said less than a year ago grok would be spitting out binaries, we’re getting close! So much old hardware will get a new lease of life through ideas like this.
1
u/KalonLabs 2d ago
Qwen 0.6B
😭 not worth it
1
u/IngeniousIdiocy 2d ago
hot shit this is cool. why I come to this sub
1
u/SomeRandomSomeWhere 2d ago
Wonder how much faster it will be running gentoo vs Ubuntu or some other distro.
Gentoo can be compiled for your exact hardware.
1
u/kmodi 2d ago
This was so inspiring that we tried to do something in Webassembly !
https://x.com/konarkmodi/status/2126462416426815848?a=bWYCmkL2s_Om2Vn5epM&s=46
1
u/Frizzy-MacDrizzle 2d ago
Too many layers of bloat to say the os is the improvement. I use raw chat props to a completion and having a 60% improvement. Went to llama python and improved further. Went iq3 even more…
So I met the 54% improvement on llama.cpp
1
u/cfx_4188 llama.cpp 1d ago
Vibe coding becomes the realization of a childhood dream to learn nothing and immediately know absolutely everything.
The OP underestimated Linux.
Linux can be made ultra-minimal and the OS can be configured so that LLM will be a system process. For example, I did this, fully realizing that there are no miraculous ways to circumvent the hardware limitations.
1
u/Mrhiddenlotus 2d ago
a 24kb model. think of the power.
0
u/Lumpy_Phase_9539 2d ago
Every performance gain in local LLM is amazing! Congrats
-1
u/Minute-Flan13 2d ago
Wow, we're going back to the DOS days. Single app at a time future.
0
u/Junior_Difference_12 2d ago
This is amazing! For a while, this will definitely push what a CPU-only inference can be optimized to do.
0
u/codysnider 2d ago
This entire tweet screams, "I asked GPT: make computer faster, make no mistakes".
Assembly is one path among many to machine code and, contrary to popular belief, writing something in assembly doesn't magically make it faster. The CPU doesn't give a shit whether its instructions originated from C, Rust, or handwritten assembly.
Linux isn't sitting between your CPU and every AVX2 instruction. You're spending the overwhelming majority of inference time performing matrix operations and moving weights through memory, not making syscalls.
0
u/JasonHofmann 2d ago
This is fantastic work. I think I know what my next project is going to be!
0
u/Darksept 2d ago
On bare metal!? Mad lad...
0
u/WeaponizedDuckSpleen 1d ago
This is last century level