#1703·colibri

Ternary weight formats (~1.75-2.13 bpw): in scope? and how to handle the GGUF/safetensors gap

Author: kiljoy001Created Sep 23, 2026Updated Sep 28, 2026

Question: are ternary (~1.6-2.1 bpw) weight formats in scope, and how would you want the container gap handled?

Asking before writing code, since the container question changes the design and I would rather not guess.

What I am proposing

Adding two ternary formats to quant.h: weights in {-1, 0, +1} with one fp16 scale per 128 weights. These are the formats behind PrismML's Ternary Bonsai models (a 27B lands at ~5.5 GB).

Two packings:

  • PQ2_0 — 2 bits/element, { fp16 d; uint8_t qs[32]; } per 128 weights, 34 B/block (2.13 bpw). Codes 0..3 map to value c - 1.
  • PTQ1_0 — base-3 trit packing, { uint8_t qs[24]; uint8_t qh[2]; fp16 d; } per 128 weights, 28 B/block (1.75 bpw). 5 trits per byte in the main plane, 4 in the high plane.

The split-plane layout of PTQ1_0 looks structurally close to your int3-g64 (16 B low + 8 B high per 64-element group), so that seems like the closest existing template.

Why it might interest you

Your int3-g64 note says 3.5 bpw beat per-row int4 on the #132 OLMoE ablation. Ternary is the next point down that curve at ~1.75-2.13 bpw. For a MoE engine that streams experts from disk, halving bytes/weight against int4 is a direct cut to the per-token I/O that bounds the disk-resident case — more experts resident per GB of VRAM and RAM, less streaming per token. That seems more relevant to Colibri's bottleneck than to a fully-resident engine.

The part I want your read on: containers

st.h is safetensors-only, and these formats ship as GGUF. I see three options and do not want to pick unilaterally:

  1. Offline conversion to safetensors with the packed bytes as U8 plus a sidecar for scales and metadata. Keeps st.h untouched, but adds a conversion step and duplicates files.
  2. New dtype codes in st.h following the pattern you used for F8 (codes 4/5/6), so packed blocks are first-class. Requires a converted container, but the engine reads them natively.
  3. A minimal GGUF reader alongside st.h. Biggest change and cuts against the dependency-free principle, so I would only do it if you actively wanted it.

My inclination is (1) or (2). Do you have a preference, or a reason none of these is right?

The other thing worth flagging: Hadamard

These models carry a Hadamard activation rotation in the file metadata (normalized-sylvester-walsh-hadamard, block_size = 1024, applied to a named subset of weights). Without it the weights load fine and produce garbage, so this is not optional.

I noticed e8_rot_rows() already does Walsh-Hadamard rotation for the E8/IQ3 lattice path. If that is reusable at width 1024 with per-tensor selection driven by a name list, that is most of the work already done. If it is specialised to E8 in ways that do not generalise, I would want to know before assuming.

What I would bring

I have implemented these kernels twice: a SYCL/oneAPI backend (MMVQ vector dot with DP4A) and an x86 SSE2/SSSE3 CPU path, both in the PrismML llama.cpp fork. The SSE work is the relevant one here since it targets your dependency-free CPU path — _mm_maddubs_epi16 plus _mm_madd_epi16 for the dot, shift/mask/compare for the trit unpack, no AVX required. It maps onto your dot_i4i8() shape fairly directly.

Measured on an i5-12600K with AVX disabled at compile time, isolated A/B (same binary, only the kernel library swapped, alternated across runs), Ternary Bonsai 1.7B PQ2_0:

build pp128 tg32
scalar 15.33 / 15.39 9.49 / 9.62
SSE2 42.91 / 43.23 25.20 / 25.35
SSSE3 59.49 / 58.98 32.07 / 31.42

3.3x on generation for SSSE3 over scalar. I have also verified the formats build and run correctly on a 2010 dual Xeon E5645 (SSE4.2 ceiling, no AVX at all), which is the hardware tier this mainly serves.

Correctness is gated by an exact test: 256 bit patterns per format against a scalar oracle, with power-of-two scales so the comparison is exact rather than tolerance-based. That should slot into your correctness-gate requirement, and I can produce the experiment manifest with at least three samples per configuration per docs/benchmarking.md.

Scope check

Happy to do this against dev as a focused PR, or to split it (formats first, Hadamard wiring second) if you would rather review it in pieces. If ternary is out of scope for the project, no problem — I would rather hear that now than after a PR.