Kintu-2.0-30M-ONNX
ONNX exports of Kintu-2.0-30M, a 30M-parameter Luganda chat model built with MiniMind. Each export decodes incrementally with a KV cache and runs on-device with ONNX Runtime.
Variants
Every variant was checked against the PyTorch model after a prefill and one cached decoding step. Each one predicts the same next token.
| File | Weights / compute | Size | Max |Δlogit| |
|---|---|---|---|
onnx/model.onnx |
fp32 | 127.4 MB | 0.000 |
onnx/model_fp16.onnx |
fp16 | 63.9 MB | 0.004 |
onnx/model_uint8f16.onnx |
8-bit asymmetric / fp16 | 38.0 MB | 0.077 |
onnx/model_q8f16.onnx |
8-bit symmetric / fp16 | 37.1 MB | 0.114 |
onnx/model_int8.onnx |
int8 dynamic / fp32 | 32.1 MB | 1.436 |
onnx/model_q4.onnx |
4-bit / fp32 | 30.8 MB | 2.087 |
onnx/model_q4f16.onnx |
4-bit / fp16 | 22.8 MB | 2.087 |
q4 is the default for phones because its fp32 activations run fast on any CPU. q4f16 is the smallest. q8f16 is the closest to fp32 among the small variants. The 4- and 8-bit variants use the MatMulNBits contrib op.
Inputs and outputs
Every variant has float32 inputs and outputs, including the fp16 ones. The model has 8 layers, 4 KV heads and a head size of 64.
| Name | Type | Shape |
|---|---|---|
input_ids |
int64 | [batch, sequence] |
attention_mask |
int64 | [batch, past_sequence + sequence] |
position_ids |
int64 | [batch, sequence] |
past_key_{0..7}, past_value_{0..7} |
float32 | [batch, 4, past_sequence, 64] |
Output logits |
float32 | [batch, 6400], last token only |
Output present_key_{0..7}, present_value_{0..7} |
float32 | [batch, 4, past_sequence + sequence, 64] |
Starting the cache: begin with one position of zeros in every past_* tensor, and set attention_mask to 0 for it. No tensor is ever empty that way. position_ids count real tokens from 0. After each step, feed the present_* outputs back in as past_*.
The names follow the Kintu app, so these files don't load in Transformers.js or Optimum.
Usage
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
repo = "henryhale/Kintu-2.0-30M-ONNX"
tok = AutoTokenizer.from_pretrained(repo)
sess = ort.InferenceSession(hf_hub_download(repo, "onnx/model_q4.onnx"))
outputs = [o.name for o in sess.get_outputs()]
prompt = tok.apply_chat_template([{"role": "user", "content": "Oli otya?"}], tokenize=False, add_generation_prompt=True)
ids = tok(prompt).input_ids
past = {i.name: np.zeros((1, 4, 1, 64), np.float32) for i in sess.get_inputs() if i.name.startswith("past_")}
mask, pos, reply = [0], 0, []
while len(reply) < 100:
mask += [1] * len(ids)
out = dict(zip(outputs, sess.run(None, {
"input_ids": np.array([ids], np.int64),
"attention_mask": np.array([mask], np.int64),
"position_ids": np.arange(pos, pos + len(ids), dtype=np.int64)[None],
**past,
})))
past = {name: out[name.replace("past", "present")] for name in past}
pos += len(ids)
token = int(out["logits"][0].argmax()) # greedy; the model card samples used temperature 0.85, top-p 0.95
if token == tok.eos_token_id:
break
reply.append(token)
ids = [token]
print(tok.decode(reply))
Limitations
The limitations of Kintu-2.0-30M apply: at 30M parameters it writes fluent Luganda but is often off-topic and gets facts wrong. The context is 512 tokens, and positions beyond that fail.