Daily Tech Briefing
AI 科技速览
每天 5 分钟内学习 AI。获取最新的人工智能新闻,理解其重要性,并学习如何将其应用于您的工作。
Hacker News · 2026/7/31 16:17:04
Why we write our own C and C++ inference engines
AI 中文解读
这家公司没有选择“站在巨人肩膀上”,而是亲手用C和C++重写了AI推理引擎。最吸引人的是,他们把原本需要9.1GB安装包的AI服务,压缩成了一个66MB的小文件,运行速度还不输主流方案,甚至在某些场景下更快。
通俗点说,以前部署AI就像搬一整套家具,体积大、还挑剔地面平不平;现在他们换了个方式,只带一个工具箱,到了地方直接干活。他们重写的引擎支持常见的AI图像识别、语言处理等任务,输出的结果和原版一模一样,但内存占用更少,运行效率更高,尤其在CPU上表现优秀。
这项技术带来的直接好处是:普通人以后用AI应用可能更快、更便宜。开发者能以更低成本把AI嵌入到手机、电脑甚至小设备里,不用非得依赖昂贵的显卡和大容量存储。这意味着即使没有顶级硬件,也能流畅运行高级AI功能,未来各类AI小工具、本地化助手会更普及,隐私保护也更好,因为很多计算可以直接在设备上完成,不用上传到云端。
← All postsEngineeringWhy we write our own C and C++ enginesA 66 MiB binary instead of a 9.1 GiB virtualenv, depth estimation that beats PyTorch on CPU in half the memory, and biometrics that match insightface bit for bit. The method, the measurements, and what it costs us.Ettore Di Giacinto
24 July 2026
7 min readMost LocalAI backends wrap somebody else’s engine, and that is the right default. llama.cpp, vLLM, whisper.cpp, stable-diffusion, MLX and the rest are maintained by people who are better at those models than we are, and wrapping them costs a Dockerfile and a gRPC shim.Eighteen of our backends do not wrap anything. They are C or C++ ports we wrote from scratch, and each one exists because wrapping the upstream engine would have meant shipping something we could not ship: a multi-gigabyte Python install, a non-portable CUDA-only stack, or a model that had no C++ implementation at all. This post is about what those ports buy, measured, and what they cost.What you get: one file, and memory you can predictDeploying a Python inference stack means resolving a dependency tree at install time, on the target machine, against whatever CUDA and glibc it has. Deploying a ggml port means copying a shared library and a GGUF file.The clearest measurement of that difference is vllm.cpp, our C++20 port of vLLM’s V1 serving architecture. Installing vLLM produces a 9.1 GiB virtualenv. Installing vllm.cpp produces a 66 MiB binary. The engine implements the same things the Python original does, including paged KV cache, continuous batching, prefix caching, the scheduler and the sampler, with no Python, no PyTorch and no ggml at inference.The obvious question is what that costs in throughput. On an NVIDIA GB10 running Qwen3.6-27B in NVFP4, greedy, closed loop, against vLLM in its production graphed configuration rather than --enforce-eager:Concurrency12481632vllm.cpp tok/s86.05159.68292.34508.77801.761095.01vLLM tok/s82.32158.03290.31505.46789.161076.25Ratio1.045x1.011x1.007x1.007x1.016x1.017xWe are ahead at all six points, and five of those six are ties. Our run-to-run noise band is 0.5%, and concurrency 2 through 32 land between 0.7% and 1.7%, so the honest reading is that only the single-stream case (4.5%) is clearly outside noise. Output is token-for-token identical to vLLM at every point on that curve. Peak host memory is 24.88 GiB against 28.18 GiB.A tie against a mature CUDA stack is a good result for a 66 MiB binary, and it means the footprint saving is not paid for in throughput. Against llama.cpp on CPU from the same GGUF file, prefill runs 1.18x faster (223.8 against 177.3 tok/s), decode is a tie inside llama.cpp’s own spread, and the tokens are byte-identical to its greedy decode. Against MLX-LM on an Apple M4, prefill time to first token is 1.5% ahead and warm total throughput is 97.6% of MLX-LM, a real 2.4% gap that sits entirely in decode.Sometimes the port is simply fasterdepth-anything.cpp is a port of ByteDance’s Depth Anything 3, which gives you metric depth in metres from one ordinary photo, plus per-pixel confidence, camera intrinsics and extrinsics, and a back-projected point cloud. On CPU it is faster than PyTorch running the same model.EngineQuantModel MBLoad msInfer msPeak RAM MBvs PyTorchPyTorchf32516749416.913281.00xC++/ggmlq8_014240319.43631.31xSame model, 1.31x the speed, 27% of the memory, and a load that finishes in 40 ms instead of 749 ms, on a Ryzen 9 9950X3D at 504x336 with 16 threads. The quantized q4_k build is a 99 MB file and stays near-lossless. Output correlates 1.0 with the reference forward pass, component by component, across 37 parity tests.The reason it is faster has nothing to do with writing better matmul kernels than PyTorch. Two positional embeddings, the DPT head’s UV embedding and the backbone’s bicubic position embedding, were being recomputed on every forward pass with single-threaded scalar sin, cos and bicubic loops, even though they depend only on the input geometry and are identical
分享
阅读原文 ↗