r/LocalLLM • • 2d ago

Question Built a ternary (BitNet-style) inference engine in Rust/CUDA: 8x faster than dense f32 on one CPU core. Looking for GPU testers

I've been working on ternary-gemm, an engine for models with weights in {-1, 0, +1}. With ternary weights, matmuls become adds and subtracts, so there are no multipliers in the inner loop.

CPU numbers so far (p50, one core, AVX-512 Xeon VM):

Tiny: 2.28µs vs 4.79µs for dense f32

small: 18.3µs vs 147.8µs (8.1x)

medium: 80.6µs vs 471.5µs (5.8x)

Also in the repo:

a looped transformer (one shared ternary block run N times, so the weights fit in cache)

a BitNet/safetensors converter, PyTorch bindings, and an RTX 5090 autotuner

an FPGA reference unit in Verilog

What's missing is real GPU numbers. If you have a 5090, 4090 or H100 and can run `bench.sh`, I'd really appreciate the results, and I'll credit you in the README. Criticism of the methodology is welcome too.

Repo: https://github.com/shubhxho/ternary-gemm

https://x.com/shubhgupta/status/2124468535128739866?a=x5oeEI5ZBvfTuFjiI5k&s=19

0 Upvotes

1 comment sorted by

1

u/silenceimpaired 2d ago

People are suspicious creatures. If you don’t get engagement consider renting the hardware. I’m guessing it will be under $10 maybe $100 depending on what you’re doing.