Downloads · 30 days
0
UlukaDev/ternary-qat-jax-tpu-demo
ternary-qat-jax-tpu-demo is a machine learning model from UlukaDev. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
This is a public experiment and infrastructure test, not a usable model. It exists to demonstrate one specific thing: BitNet b1.58-style ternary quantization-aware training (QAT) with a straight-through estimator conv…
Downloads · 30 days
0
Access
Public
Updated Jul 18, 2026
Repo size
59.5 MB
Likes
2
Public
Click a slice to open those files.
Other59.6 MB · 100%
From the Hugging Face model README
This is a public experiment and infrastructure test, not a usable model. It exists to demonstrate one specific thing: BitNet b1.58-style ternary quantization-aware training (QAT) with a straight-through estimator converges if and only if master weights are kept in fp32 — and to show that working end-to-end in JAX/Flax on TPU.
In a prior PyTorch run of the same QAT scheme with bf16 master weights, training silently no-opped: Adam updates (~5e-5) fall below the bf16 ULP at typical weight magnitudes (8 mantissa bits -> spacing ~1e-4 near |w| ~ 0.03), so every update rounds away. Across 936 steps, 0 of 318M sampled weights changed ternary value.
loss_curve.png~16M-param decoder-only transformer (4 layers, d_model 256,
8 heads, seq len 256); all attention and FFN projections are
BitLinear (weights ternarized to {-1, 0, +1} x mean(|W|) per-tensor scale on every
forward pass, STE backward: w + stop_gradient(quantize(w) - w)); embeddings, norms
and the tied output head are ordinary fp32. ~3.15M of 16.08M params are ternary.
Trained on streamed TinyStories with Adam (peak lr 0.0003, 50 warmup steps,
cosine decay), data-parallel via jax.jit + NamedSharding — runs unmodified on 1
(Colab v6e-1) or 8 (Kaggle v5e-8) TPU devices.
After 800 steps this produces TinyStories-flavored babble, exactly as expected at this scale and budget:
Once upon a time, there lived a small measure the little boy named white car. We "Wow, always took it was a toy.
The man began to only a big owl and used that she saw a ribbon. Tom. The man.
Lily and arrived, Lily and worked it back to play off it in the lovely everywhere on, Lily and said, the sleepy.
Run ternary_qat_jax_tpu.ipynb (in this repo) top-to-bottom on any Colab or Kaggle
TPU runtime. Restore the checkpoint:
import orbax.checkpoint as ocp
with ocp.StandardCheckpointer() as ckptr:
params = ckptr.restore("checkpoint/params", nnx.state(model, nnx.Param))
nnx.update(model, params)