Blog

Introducing tritrun: a Ternary Bonsai engine, 1.34× faster than PrismML’s

tritrun runs PrismML’s Ternary-Bonsai-2.5-27B at 323.6 tokens per second on an RTX 5090 with 3 MTP drafts, 1.34× PrismML’s llama.cpp fork at its best settings, and decodes faster on every card we tested, from a T4 up, using 5 to 7% less memory.

Magni6 min read

Two days ago, PrismML released Ternary-Bonsai-2.5-27B, and it caught our eye. It stores every weight as -1, 0 or +1, which puts a 27-billion-parameter model in about 6 GB, small enough for a 16 GB T4. On cards like that, decode is a question of how fast the weights can be read, and ternary weights are a format no general engine was built around. PrismML ships its own llama.cpp fork to run the file on NVIDIA, and it is the only other engine that can. Since then we have written one from scratch in CUDA to see how much faster the format could go.

tritrun decodes 323.6 tokens per second on an RTX 5090 with 3 multi-token-prediction drafts, 1.34× the fork’s 241.4 at its best settings. It is faster on every card we tested, a T4, an L4, an A10 and an RTX 5090, with drafts and without, and it uses less memory doing it. Most of the gain comes from one idea: a block of ternary weights is decoded once and then used for every token in the step, so checking three drafts costs little more than generating one token.

Faster than PrismML’s llama.cpp fork on every card we tested. Ternary-Bonsai-2.5-27B, PTQ1_0 GGUF, both engines in the same container on the same GPU with the same prompt tokens, the fork at its best setting.

  • +28%decode with MTP on a T4, the smallest card, 60.1 tokens per second against 46.8
  • 5 to 7%less VRAM than the fork at its leanest setting, with MTP on
  • 778 / 1,000MMLU questions right, against the fork’s 777, with the same model file
Greedy decoding, 3 MTP drafts, current build. Quality figures on an A10 and an RTX 5090.

Decode with 3 MTP drafts

Tokens per second, higher is better

Bars are scaled within each group

  • tritrun
  • PrismML llama.cpp fork
  • T4
    • tritrun: 60.1 tok/s
    • PrismML llama.cpp fork: 46.8 tok/s
  • L4
    • tritrun: 73.7 tok/s
    • PrismML llama.cpp fork: 63.7 tok/s
  • A10
    • tritrun: 112.7 tok/s
    • PrismML llama.cpp fork: 99.5 tok/s
  • RTX 5090
    • tritrun: 323.6 tok/s
    • PrismML llama.cpp fork: 241.4 tok/s
4 short prompts, greedy, 200 new tokens, the better of 2 repetitions. The fork’s figure is its best of MTP at cut-off 0.1 and 0, at batch sizes 512 and 64.

Why does one read have to serve several tokens?

Each 128 weights of the model are packed as trits into a few bytes, and a decode step on a card this size spends most of its time fetching those bytes. Unpacking them is cheap next to the fetch, so tritrun unpacks each block once into registers and multiplies it, with the dp4a integer instruction, against the int8 activations of every token in the step. One read of the weights then serves all of them.

That is what makes multi-token prediction pay. The model’s MTP head drafts 3 tokens ahead, and the engine checks all of them with the real model in one step, keeping the prefix that agrees. A 4-token step costs 1.15× a 1-token step on an L4 and 1.4× on a T4, and about 2.8 tokens survive each step, so drafts gain us 13 to 34% over the fork’s own MTP, more than the 8 to 11% we gain without them.

One block of 128 ternary weights, +1 standing, 0 flat and -1 sunk, is read once by a sweep, and four tokens light together: one token and three drafts
One read of a 128-weight block serves every token in the step. The block size is real, the trit values are illustrative.

When a draft is wrong, its effects have to be undone, and that includes the model’s recurrent layers, whose state changes with every token. Instead of saving a copy of that state per token, tritrun keeps one checkpoint and replays the recorded layer inputs up to the last accepted token.

What else does a step spend its time on?

Launches. A 1-token step is about 640 kernels, so the engine folds as much as it can into each one. The RMS norm factor is a scalar, so it is applied to the output of the matmul, which lets a single kernel do the residual add, the sum of squares, the Hadamard transform and the quantization of the next input. The whole step is then replayed as one CUDA graph per step width, which reads the position from device memory so the same graph is reused for every token.

The RTX 5090 had a cost of its own. Matmuls there split their columns into 34 partitions so that all 170 SMs have work, and the kernel that adds the partial sums was waiting on one load at a time. Fetching 8 partitions of 4 elements per thread at once was worth 7% of plain decode on that card, the largest single gain there, where the CUDA graphs were worth about 2%.

And prefill?

Prompts are long enough to keep tensor cores busy, so steps of more than 8 tokens decode 128 rows of trits into shared memory and run them against up to 128 tokens with the INT8 mma.sync instruction. The limit we hit was not the tensor cores but shared memory, which delivers about 64 bytes per clock on each SM of these cards. We rebuilt the tile around that number, so each warp owns 64 rows by 32 tokens, every fragment arrives in one wide load, and the activations are written in the order the kernel reads them.

Prefill on real text, tokens per second, best of 3. Higher is better.
GPU512 tokens, fork512 tokens, tritrun2,048 tokens, fork2,048 tokens, tritrun
T4331412341403
L4741827788811
A10913994951966
RTX 50902,8994,0433,1743,531

Our figure is the wall time of the whole prefill plus the first token, and the fork’s is its own reported rate at its default batch size. The first generated token agreed every time. Short prompts gain the most, from 1.7× on a T4 to 6.3× on the 5090 at 64 tokens, and at 2,048 tokens on an A10 the two engines are level.1

How was it measured?

Both engines ran in the same container on the same GPU with the same prompt token ids. The fork is PrismML’s prism-b12178-03ec600 with flash attention, an FP16 KV cache, a 4,096-token context and one slot. We ran it at batch sizes 512 and 64 and, for MTP, at draft cut-offs of 0.1 and 0, and each of its figures here is the best of those. Memory is the peak nvidia-smi reading against the fork at batch size 64, its leanest setting.

Two bonsai on one RTX 5090 open a blossom per token, the fork at 241.4 tokens per second and tritrun at 323.6, reaching 1,207 and 1,618 tokens after 5 seconds
Decode with 3 MTP drafts on an RTX 5090, in real time at each engine’s measured average rate.

Each card’s final numbers come from one machine, and machines of the same type differ by several percent. On an earlier A10, before the last two decode changes, our margin was 1 to 2% plain and 10 to 12% with drafts.

Does it give the same answers?

It does, within the fork’s own spread. We ran the same model file through both engines with the fork’s chat template and tokenizer, and added a control: the fork against itself at another batch size, which shows how far its own rounding moves the results.

Quality on the current build. Perplexity is lower-is-better, MMLU and GSM8K count correct answers.
TestGPUForkFork, controltritrun
WikiText-2 perplexity, 10,200 tokensT49.71549.71459.7150
L49.71479.71679.7195
A109.71619.71709.7146
RTX 50909.71079.71679.7173
MMLU, 1,000 questionsA10777778 / 776778
RTX 5090777776 / 779778
GSM8K, 300 questionsA10282283280
RTX 5090282282284

The median KL divergence from the fork is 9e-5 for us and for the control, and our top token matches the fork’s 99.3 to 99.4% of the time, against 99.3 to 99.5% for the control. On the 1,000 MMLU questions we pick the fork’s answer on 998 and 996.

Inside the engine the checks are exact. Steps of 1, 2, 4 and 8 tokens give bit-identical logits, repeated runs are bit-identical, and speculative output is identical to plain greedy output, on all four cards.

What went wrong on the way?

The RTX 5090 failed the bit-identity check the first time it ran. Under --use_fast_math the 1/sqrtf in the RMS scale compiled to different instruction sequences in two kernels, so steps of different widths rounded the same value differently. It now uses the correctly rounded __frsqrt_rn, and the checks pass on every card.

The first version decoded trits through a lookup table, and the shared dp4a decode that replaced it is what lets one read serve several tokens. We also looked for a way to read fewer bytes, but the trits are spread evenly over -1, 0 and +1, at 1.585 bits of entropy each, so they do not compress further.

Where it stands

A 27-billion-parameter model now decodes at 60 tokens per second on a T4 and at 324 on an RTX 5090, faster than the engine its own makers ship, with the same answers and less memory. It decodes greedily, one sequence at a time, on Linux and NVIDIA, and we have not yet run it on an H100, a B200 or consumer RTX 30 and 40 series cards.

The engine, the benchmarks and every raw log are at https://github.com/amw720386/tritrun.

Notes

  1. At 2,048 tokens on an A10 tritrun is 2% ahead in this container and 6% behind in another, 1,060 against 1,127, which is within the spread between machines. ↑

We push AI inference closer to the physical limit of GPUs, within days, on any model and any hardware.

Post on XShare on LinkedIn

Read next

  1. 8 min read

    We built the fastest Qwen3-TTS engine for a GB10

    Streaming Qwen3-TTS 1.7B on one NVIDIA GB10, our engine generates 3.1× the audio of vLLM-Omni, the vLLM project’s engine for speech models, and 2.1× that of sglang-omni, as geometric means over 1 to 256 clients.

All posts