A Chinese / English input-method model of Zhiyi IME for phones, in about 12 MB, with the compute of the 4M-parameter models of other input methods: 4 ModernBERT layers of width 256 reading 32 tokens of context, a 32,000-token vocabulary, weights in 4 bits, and one shared hashed n-gram memory table (250,007 rows x 64, stored as product quantization, 4 MB). It does two things:
你的作业|了吗, "your homework | yet?").It replaces zhen-mini-next-1123 in this repository: the same structure, size and speed, trained one pass further on long-span word choice with short context (6-20 characters typed, at most 30 characters of context before them, candidates from seven input-method engines, Qwen3.5-9B LoRA as the only teacher on these rows). On the hard neutral set v5 it scores 71.4% instead of 69.3% (4-bit ONNX; on v5's rows with 1-16 characters of context 72.5% instead of 70.8%, PyTorch), on v2 / v3 / v4 within 0.1 point of 1123, next words unchanged within noise. A preview: Zhiyi IME does not use it yet.
Against zhen-mini-next-preview-1116 (8 layers, 128 tokens of context, no table) the 4-layer Mini needs about 204 million multiply-adds a word-choice row instead of 739 million (3.6 times less) in the same size class. What makes up for most of the cut is the table: the encoder adds each token's bigram / trigram rows to its input, and the next-word decoder reads four rows around the cursor as extra memory, from the same table. zhen-mini-next-1123 and zhen-mini-next-preview-1116 stay in this repository's history; 1116 also in its GitHub release. All Zhiyi models: https://github.com/dd1000001000/zhiyi_models
| File | |
|---|---|
model.safetensors |
all weights (12.3 MB): 40 matrices already 4-bit as ggml Q4_0 blocks, the n-gram table as PQ16 codes + codebooks, the rest F32 |
config.json |
the structure (with encoder.layer_types), prefix_mask, shared_head, compact, choice_only, next_word_decoder, special tokens, sequence settings (choice_context_tokens 32), ml, next_word (the decoder, rows_are_tokens, context_tokens 32), ngram (the table: its keys and hash), vocab_size and q4_0: each 4-bit tensor's [rows, columns] |
next_rows.json |
per token: its piece and text, the mode masks (zh, en_start, en_cont), the end token, characters per token |
tokenizer.json |
the 32k Unigram tokenizer: context, tags, typed text |
tokenizer.candidates.json |
the same with Metaspace prepend_scheme never: candidates, Chinese and English (no leading ▁) |
unified_vocab.json |
the units and letters of the typed slots (its character tables are not used) |
test_vectors.safetensors |
13 word-choice and 12 next-word inputs (4 of them mid-text) with the fp32 PyTorch model's outputs, to check an implementation |
candle_ref/ |
a reference forward pass in Rust (candle 0.11), version 0.8.0: reads the 4-bit file and the table |
onnx/w4/ |
laya.mini.w4.onnx (14.9 MB, word choice and next words in one file, the table included: opset 21 + com.microsoft MatMulNBits / GatherBlockQuantized), with both tokenizers and the JSON files |
onnx/slim/ |
the same file in 13.3 MB (laya.mini.w4.onnx: the head's in-projection 4-bit too, scales float16); same inputs and outputs |
example.py |
the quick start below |
LICENSE |
Apache License 2.0 |
Word choice, next words and mid-text with onnx/w4/laya.mini.w4.onnx (the code is in example.py):
pip install onnxruntime tokenizers numpy huggingface_hub
python example.py
D = os.path.join(snapshot_download("zhiyi-ime/zhiyi-zhen-mini-12M", allow_patterns=["onnx/w4/*"]), "onnx", "w4")
tok = Tokenizer.from_file(os.path.join(D, "tokenizer.json")) # context, tags, typed text
ctok = Tokenizer.from_file(os.path.join(D, "tokenizer.candidates.json")) # candidates (no leading ▁)
BOS, EOS, MASK = 2, 1, 4
CTX = 32 # context tokens
# 1. Word choice: <bos> context <eos> <mask> x syllables <eos> cand1 cand2 ... <eos>; one score per candidate
# (context mode on the leading block, then key mode on the rest with that cache; ctx_tail = the context's last
# two tokens, for the table's candidate keys)
print(choose("今天天气很好,我们去公园", ["san", "bu"], ["散步", "散布", "三部"]))
# 2. Next words: context mode once (cross_k_out / cross_v_out / cross_mask_out: the context and the table's four
# positions), then is_step in a beam search over the 32k tokens
print(next_words("今天天气很好,我们一起去"))
print(next_words("Thank you very much for your", lang="en"))
print(next_words("我们明天去公", min_chars=1)) # completion: the typed start of the word ends the context
print(next_words("你的作业", right="了吗")) # mid-text: <bos> left <mask> right <eos>
Output (ONNX Runtime 1.30.0, CPU):
[('散步', 2.34...), ('散布', -5.90...), ('三部', -6.32...)]
[('看看', -1.99...), ('旅游', -2.60...), ('旅行', -3.19...), ('吃火锅', -3.19...), ('游泳', -3.24...)]
[('support', -1.75...), ('advice', -3.22...), ('feedback', -3.43...), ('comments', -3.76...), ('email', -3.79...)]
[('司', -0.55...), ('园', -2.05...), ('交', -2.94...), ('开', -3.77...), ('营', -4.02...)]
[('怎么', -2.14...), ('已经', -3.16...), ('开始', -3.21...), ('没有', -3.74...), ('工作', -4.02...)]
The calls build the inputs of test_vectors.safetensors cases 0, next0, next5, next7 and next8 (token for
token); the 4-bit file's words differ a little from the vectors' fp32 ones (next0: the same five words, in a
slightly different order). Traditional rows add the tag <zh-Hant> after <bos> and the typed text instead of
<mask> units (see "Inputs"). For the slim file, change onnx/w4 to onnx/slim in example.py (the file names are
the same). Set MINI_DIR to a local onnx/w4 folder to skip the download.
The bool input is_step picks the branch (an If node runs only that one). Every input has a small default, so ONNX
Runtime lists them as overridable initializers, not as graph inputs (get_overridable_initializers()); feed them by
name and leave out what the branch does not use.
is_step false (the default), word choice: input_ids, unit_ids, past_enc_k / past_enc_v
(4 × 1 × 4 × P × 64), past_choice_k / past_choice_v (1 × 1 × 4 × P × 64) with past_mask, marker_pos,
ctx_tail (1 × 2: the context block's tokens at positions n−3 and n−2, before its <eos>; −1 when the block has
under 3 tokens, i.e. an empty context) → logits, present_0 … present_3 (the encoder's and the head's keys and values), cross_k_out /
cross_v_out, cross_mask_out. Context mode (the leading block <bos> … <eos>, no past) gives the cache; key mode
(the rest, the cache as the past) gives the scores, with marker_pos counted from the start of the rest. Pass the
same ctx_tail in both modes (context mode does not read it): a candidate's first tokens are keyed on the context's
last tokens in the n-gram table.<bos> context[last 32 tokens] <eos> (mid-text:
<bos> left <mask> right <eos>, below) with unit ids 0 → cross_k_out, cross_v_out (2 × 1 × 4 × (T + 4) × 64),
the decoder's cross-attention keys and values of the T context positions and the table's four positions, and
cross_mask_out (1 × (T + 4), all true for one context). In an input method this is the context pass word choice
already runs, when the contexts are the same.is_step true, one next-word step for N hypotheses: prev (N, the previous token; any value at position 0),
pos (N), dec_past_k / dec_past_v (2 × N × 4 × P × 64) with dec_past_mask (N × P; at position 0 a placeholder
of length 1, false), cross_k / cross_v (2 × N × 4 × (T + 4) × 64, one copy per hypothesis) with cross_mask
(N × (T + 4), from cross_mask_out) → logits (N × 32,000, one per token), present_0 / present_1 = the
decoder's keys and values with this step appended.Speed (ONNX Runtime 1.30.0, CPU, AMD Ryzen 5 9600X; the search loop around the graph not counted; both files measured in the same run on 300 pages of neutral v2 and 300 + 300 next-word test contexts, medians):
| zhen-mini-next-1126 | zhen-mini-next-1123 | |
|---|---|---|
| Word choice, context mode (once per context), 4 threads / 1 | 1.81 / 2.35 ms | 1.68 / 2.34 ms |
| Word choice, a key, 4 threads / 1 | 1.78 / 2.32 ms | 1.64 / 2.33 ms |
| A whole next-word prediction (slim file, beam 8, 5 words), 4 threads / 1 | 3.60 / 5.08 ms | 3.62 / 5.14 ms |
The same graph as 1123, so the same speed within the noise of one run; memory as measured for 1123 (onnx/w4, loaded
/ running): 42 / 44 MB. For comparison, zhen-mini-next-preview-1116 as measured for the 1123 release: word choice 5.03 /
10.24 ms (context mode) and 2.67 / 4.63 ms (a key), a whole next-word prediction 7.5 / 14.1 ms.
One RTX 5070 Ti.
A tensor listed in config.json q4_0 is stored as ggml's Q4_0 blocks: dtype U8, shape rows × (columns / 32 × 18).
Each block of 32 values along a row is 18 bytes: an f16 scale d (little-endian), then 16 bytes q; value j
(0…15) is ((q[j] & 15) − 8) · d, value j + 16 is ((q[j] >> 4) − 8) · d. This is the layout candle's
qtensor_from_ggml(GgmlDType::Q4_0, …) (and llama.cpp) read, so a linear layer runs as a 4-bit matrix product:
use candle_core::quantized::{ggml_file::qtensor_from_ggml, GgmlDType, QMatMul};
let raw = safetensors.load(name, &device)?.flatten_all()?.to_vec1::<u8>()?;
let w = QMatMul::from_qtensor(qtensor_from_ggml(GgmlDType::Q4_0, &raw, vec![rows, cols], &device)?)?;
// w.forward(&x) = x · wᵀ, then add the bias if the layer has one
The 4-bit tensors: every linear weight of the encoder, the head and the decoder, scorer.1, ng_proj,
next.mem_proj, and the two embedding tables encoder.embeddings.tok_embeddings.weight (32000 × 256) and
unit_emb.weight (3833 × 256), whose rows are unpacked when read. The token table is also the read-out: keep it as a
Q4_0 matrix for x · tableᵀ and unpack only the rows a lookup needs (one copy in memory). Everything else (norms,
biases, type_emb, tone_emb, cand_emb, next.start, next.pos.weight, next.bias, next.mem_type,
scorer.3) is F32.
The table (ngram.codes U8 250007 × 16, ngram.codebooks F32 16 × 256 × 4): row r is the 16 codebook vectors
codebooks[p, codes[r, p]] (p = 0…15) one after another, 64 values.
The hash (config.json ngram.hash): for a salt and key tokens t₁ … tₖ, in int64 with a wrapping multiply,
x = salt * 0x9E3779B1 + 12345
for t in t1 ... tk: x = (x XOR (t + 1)) * 0x100000001B3; x = x XOR (x >> 29) (arithmetic shift)
row = x mod 250007 (non-negative)
An absent key token is −7.
Names are the PyTorch ones.
| Tensor | Shape | |
|---|---|---|
encoder.embeddings.tok_embeddings.weight |
32000 × 256 | Q4_0; token id = row |
encoder.embeddings.norm.weight |
256 | LayerNorm, no bias |
encoder.layers.N.attn_norm.weight (N ≥ 1; layer 0 has none) |
256 | |
encoder.layers.N.attn.Wqkv.weight |
768 × 256 | N = 0…3, Q4_0 |
encoder.layers.N.attn.Wo.weight |
256 × 256 | Q4_0 |
encoder.layers.N.mlp_norm.weight |
256 | |
encoder.layers.N.mlp.Wi.weight |
1024 × 256 | Q4_0 |
encoder.layers.N.mlp.Wo.weight |
256 × 512 | Q4_0 |
encoder.final_norm.weight |
256 | |
unit_emb.weight |
3833 × 256 | Q4_0; row 0 = none, 1-3804 the units of unified_vocab.json, 3805-3832 letters |
tone_emb.weight |
6 × 256 | Zhuyin tones: row 0 = none, 1-5 (5 = neutral) |
type_emb.weight |
3 × 256 | row 0 is the one used (word choice and the decoder's memory) |
cand_emb |
256 | added at each candidate's first token |
ngram.codes, ngram.codebooks |
250007 × 16, 16 × 256 × 4 | the n-gram table (PQ16) |
ngram.idmap |
32000 (I32) | token id → the id the encoder's keys are hashed on (the 256k vocabulary's) |
ng_proj.weight, ng_proj.bias |
256 × 128, 256 | the encoder's table rows (2 × 64) → its input |
head.layers.0.* |
one nn.TransformerEncoderLayer (matrices Q4_0) |
|
scorer.0 (LayerNorm), scorer.1 (256 → 256), scorer.3 (256 → 1) |
word choice | |
next.mem_in.0 (256 → 256), next.mem_in.1 (LayerNorm) |
the decoder's memory | |
next.mem_proj (64 → 256), next.mem_norm (LayerNorm), next.mem_type (4 × 256) |
the decoder's four table positions | |
next.tok_in (256 → 256) |
a token's embedding → the decoder's input | |
next.start |
256 | the input at position 0 |
next.pos.weight |
22 × 256 | learned positions |
next.layers.N.* (N = 0, 1) |
nn.TransformerDecoderLayer: self_attn, multihead_attn (in_proj_weight = q, k, v stacked, 768 × 256), linear1 (256 → 1024), linear2, norm1-norm3 |
|
next.out.0 (LayerNorm), next.out.1 (256 → 256) |
the decoder's output | |
next.bias |
32000 | the read-out's bias, per token |
One sequence at a time (batch 1, no padding; with padding, mask padded keys in every attention).
The prefix mask. Let n be the position of the first <eos> (1) plus one: positions 0 … n−1 are the
leading block. A query inside the block may attend only to keys inside it; a query after it attends to every key
(within the sliding window where the layer has one). This holds in every encoder layer and in the head layer.
x = tok_emb[input_ids] + unit_emb[unit_ids % 3833] + tone_emb[unit_ids / 3833], plus cand_emb at every
position in marker_pos (each candidate's first token).o = ngram.idmap[input_ids]: for every context position p (1 ≤ p < n − 1,
between <bos> and the first <eos>) and every candidate token (from the first marker up to, not including, the
final <eos>):prev1 = o[p − 1], prev2 = o[p − 2] (−7 at p < 2); for a candidate token at offset off from its candidate's
first token: off = 0 → prev1 = o[n − 2], prev2 = o[n − 3] (the context's last two tokens; −7 when n < 3: an empty context),
off = 1 → prev2 = o[n − 2];k2 = hash(1; prev1, o[p]), k3 = hash(2; prev2, prev1, o[p]);x[p] += ng_proj(concat(row(k2), row(k3))).
Other positions (<bos>, the <eos>s, the typed units) get nothing. Then LayerNorm (encoder.embeddings.norm).h = attn_norm(x) (layer 0: h = x); q, k, v = split(Wqkv h), laid out as (3, heads, 64).x·cos + rotate_half(x)·sin, frequencies
1 / 160000^(2i/64), positions 0, 1, 2, ….config.json encoder.layer_types gives each layer's kind:
layers 0, 1 and 3 attend globally (full_attention), layer 2 only where |i − j| ≤ 64 (sliding_attention).x += Wo(attention); then a, g = split(Wi mlp_norm(x)) (512 each), x += mlp.Wo(gelu(a) · g), with the
exact (erf) GELU.final_norm. No biases anywhere in the encoder.h0 = encoder output + type_emb[0], then head.layers.0 (PyTorch nn.TransformerEncoderLayer,
norm_first=True, 4 heads, feed-forward 1024 with ReLU, LayerNorm eps 1e-5, in_proj_weight = q, k, v stacked;
no final norm), with the prefix mask.p, score = scorer.3(gelu(scorer.1(scorer.0(h0[p])))).
Higher is better.Caching the context. Run the block alone once per context and keep each layer's keys and values (after RoPE)
for its n positions; on each key run only the positions after it (the ONNX file's context and key modes). The key
part needs the context's last two tokens for the candidates' table keys (ctx_tail).
<bos> encode(context)[last 32 tokens] <eos> (English: the context's trailing spaces cut
first) with the encoder above (unit ids 0, no candidates; one prefix block, so the plain mask with the sliding
window). m = LayerNorm(next.mem_in.0(encoder output + type_emb[0])), (T, 256).
Mid-text: <bos> L <mask> R <eos> with R = encode(right)[first 32 tokens] and
L = encode(left)[−(31 − len(R)):] (as trained: the left side gives way to the right side), the gap marked by
<mask> (a context never holds one: replace <mask> in the text by a space first). Encode the right side on its
own; English: cut the left side's trailing spaces as before.c (the 32k ids, not mapped), with g the <mask>
position (else the final <eos>): l1, l2, l3 = c[g−1], c[g−2], c[g−3], r1, r2 = c[g+1], c[g+2] (−7 without a
gap; indices clamped to the block); keys hash(11; l2, l1), hash(12; l3, l2, l1), hash(13; r1, r2),
hash(14; l1, r1) (salts 1-4 + ngram.decoder.salt_offset 10); position j = `next.mem_norm(next.mem_proj(row(key_j)). Append the four after m`: the memory is (T + 4, 256).multihead_attn.in_proj_weight (and bias): compute them once per context.next.start; position j ≥ 1 is next.tok_in(tok_emb[t_j]), t_j the token written
at step j; plus next.pos.weight[j].nn.TransformerDecoderLayer, norm_first=True, 4 heads of 64, LayerNorm eps 1e-5, no
dropout): x += self_attn(norm1(x)) with a causal mask; x += multihead_attn(norm2(x), memory) (all T + 4
positions); x += linear2(relu(linear1(norm3(x)))). Attention scale 1/8.logits = next.out.1(next.out.0(x)) · tok_embᵀ + next.bias over the 32,000 tokens. A cache of each
layer's self-attention keys and values makes a step cost one position.Search (as example.py and candle_ref): beam 8, k = 5 words, at most 6 tokens a word.
zh tokens (Simplified Han) and the end (<eos>, next_rows.json end);
English mode en_start at the first token, then en_cont or the end. The others get −10⁹ before the log-softmax.next_rows.json text_zh / text_en;
English stripped), kept if it has at least 2 characters (completion: 1); hypotheses writing the same text are summed
(log-sum-exp).Token ids are tokenizer.json's, with <bos> (2) as [CLS], <eos> (1) as [SEP], <mask> (4). The context, a tag
and the typed text are encoded with tokenizer.json; candidates with tokenizer.candidates.json (no ▁, English
ones too), each cut to 16 tokens. Encode without special tokens. A Traditional row starts with the tag <zh-Hant> as
plain text; Simplified Chinese and English have no tag. Characters outside the 32k tokens fall back to UTF-8 bytes
(<0x..> tokens).
word choice, Simplified (pinyin) <bos> encode(context)[last 32] <eos> <mask> × typed units <eos> cand(候选1)[:16] cand(候选2)[:16] … <eos>
word choice, Traditional <bos> encode("<zh-Hant>") encode(context)[last 32] <eos> encode(typed text)[:24] <eos> cand(候選1)[:16] … <eos>
word choice, English as Simplified, one <mask> a typed letter (its letter unit)
next word <bos> encode(context)[last 32] <eos>
next word, mid-text <bos> encode(left)[−(31 − len(R)):] <mask> R = encode(right)[:32] <eos>
marker_pos lists the position of each candidate's first token. Each <mask> of the typed units carries its unit in
unit_ids (unified_vocab.json units: f:san = the full syllable san, p:s = typed only partly); the other
positions have unit 0.
test_vectors.safetensors holds, for word-choice case i = 0…12, i.input_ids, i.unit_ids, i.marker_pos
(int64) and the fp32 PyTorch model's i.logits (cases 0-4 Simplified Chinese, 5-12 the first row of each Traditional
test file); for next-word case nextN, N = 0…11, nextN.input_ids (<bos> context <eos>; cases 8-11 mid-text,
<bos> left <mask> right <eos>), nextN.mode (0 Chinese, 1 English), nextN.min_chars and the fp32 model's 5 words
nextN.text (UTF-8, one word a line) with nextN.logp. The fp32 model is the one with the PQ16 table (the table as
stored), the other weights before 4 bits.
The model alone, not the IME end to end. fp32 = the PyTorch model before rounding to 4 bits (with its table as stored,
PQ16); 4-bit ONNX = the slim onnx/slim/laya.mini.w4.onnx (ONNX Runtime 1.30.0); Q4_0 = this file with candle_ref.
Word choice, first candidate right: every third row of the Simplified Chinese sets and the first 200 rows of each Traditional test file.
| Word choice | fp32 | 4-bit ONNX | Q4_0 (candle_ref) |
Q4_0's best = fp32's |
|---|---|---|---|---|
| Simplified Chinese, words and word pairs (2175) | 86.3% | 86.5% | 86.5% | 98.3% |
| Simplified Chinese, long input (749) | 80.2% | 79.3% | 79.2% | 95.1% |
| Simplified Chinese, IME's real candidates (right word among them) (545) | 90.1% | 90.5% | 90.3% | 98.9% |
| Simplified Chinese homophones with the previous sentence (267) | 93.3% | 91.8% | 91.8% | 97.4% |
| Traditional, pinyin (luna_pinyin) (200) | 83.0% | 80.0% | 80.0% | 95.5% |
| Traditional, Zhuyin (bopomofo_tw) (200) | 85.0% | 84.5% | 85.0% | 98.5% |
| Traditional, Zhuyin (libchewing) (200) | 95.0% | 95.0% | 95.0% | 100.0% |
| Traditional, Jyutping (jyut6ping3) (200) | 86.0% | 84.5% | 84.0% | 96.0% |
| Traditional, Cangjie 5 (200) | 95.0% | 96.5% | 96.5% | 98.5% |
| Traditional, Quick 5 (200) | 95.5% | 96.0% | 96.0% | 99.5% |
| Traditional, Cangjie 3 (200) | 81.0% | 80.0% | 80.5% | 97.0% |
| Traditional, Quick 3 (200) | 75.5% | 74.0% | 74.0% | 96.5% |
Next word: the text's next word first (@1) / among the 5 words (@5), the model alone (no n-gram), beam 8; the first 200 rows of the Chinese and English next-word test sets, the first 100 mid-text rows of each (the rows whose text goes on after the word, that text as the right side) and 100 Chinese words cut after their first characters (completion). Small sets: a row is half a point or a whole one.
| Next word | fp32 | 4-bit ONNX | Q4_0 (candle_ref) |
Q4_0's first word = fp32's |
|---|---|---|---|---|
| Simplified Chinese (200) | 12.0 / 18.0% | 12.0 / 20.0% | 12.0 / 20.0% | 79.0% |
| English (200) | 20.5 / 37.5% | 19.5 / 37.5% | 19.5 / 37.5% | 82.5% |
| Chinese mid-text (100) | 15.0 / 23.0% | 16.0 / 23.0% | 15.0 / 23.0% | 77.0% |
| English mid-text (100) | 21.0 / 39.0% | 24.0 / 39.0% | 23.0 / 40.0% | 80.0% |
| Chinese completion (100) | 47.0 / 65.0% | 47.0 / 65.0% | 47.0 / 65.0% | 86.0% |
The 4-bit file and the 4-bit ONNX graph agree with each other almost row for row; against fp32 they move a few scores (word choice: the same best candidate in 95-100% of rows; on the 13 vectors the same best in 13/13, logits within 1.694; next word: the same first word in 12 of the 12 vectors, 4.2 of the 5 words shared on average).
On the full next-word test sets (PyTorch fp32 before 4 bits; mid-text = the test rows whose text goes on after the word; both with their tables as PQ16), against zhen-mini-next-1123:
| @1 / @5 | zhen-mini-next-1123 | zhen-mini-next-1126 |
|---|---|---|
| Chinese mid-text | 13.6 / 26.7% | 13.4 / 26.5% |
| English mid-text | 27.8 / 46.2% | 27.9 / 46.6% |
| Chinese next word | 10.9 / 21.4% | 10.9 / 21.4% |
| ... with ng1017 | 11.8 / 23.1% | 11.9 / 23.1% |
| English next word | 20.2 / 37.4% | 20.0 / 37.5% |
| ... with a trigram of the training text | 20.7 / 38.2% | 20.6 / 38.4% |
| Chinese completion | 49.3 / 71.5% | 49.3 / 71.8% |
On the public neutral word-choice test sets (v2, v3 web, v4 chat, v5 hard; whole page, first candidate right):
| v2 | v3 | v4 | v5 | |
|---|---|---|---|---|
| zhen-mini-next-preview-1116, PyTorch fp32 | 93.63% | 93.37% | 91.31% | 70.65% |
| zhen-mini-next-1123, PyTorch fp32 | 92.86% | 93.11% | 92.31% | 69.58% |
| zhen-mini-next-1126, PyTorch fp32 | 93.01% | 93.18% | 92.29% | 71.55% |
zhen-mini-next-preview-1116, 4-bit ONNX (onnx/w4) |
93.2% | 93.2% | 91.1% | 70.4% |
zhen-mini-next-1123, 4-bit ONNX (onnx/w4) |
92.7% | 92.8% | 92.2% | 69.3% |
zhen-mini-next-1126, 4-bit ONNX (onnx/w4) |
92.8% | 92.9% | 92.2% | 71.4% |
v5 by the context before the typed text (PyTorch fp32; none / 1-16 characters / more):
| none | 1-16 characters | more | |
|---|---|---|---|
| zhen-mini-next-preview-1116 | 61.33% | 69.43% | 82.91% |
| zhen-mini-next-1123 | 58.63% | 70.79% | 80.86% |
| zhen-mini-next-1126 | 62.05% | 72.52% | 81.43% |
The ONNX rows are the comparison scorer's (the charts below), the fp32 rows the training code's; the two count the same rows slightly differently.
candle_ref (loads the file in about 0.1 s):
cd candle_ref
RUSTFLAGS="-C target-cpu=native" cargo build --release
target/release/zhiyi-ref ../model.safetensors ../test_vectors.safetensors out.safetensors
candle's quantized kernels choose their SIMD code at compile time: build with RUSTFLAGS="-C target-cpu=native" (or
at least x86-64-v3). candle_ref is a reference, not a fast runtime: it runs the whole sequence with the mask (no
cache) and reruns the decoder over each hypothesis' prefix at every step; the outputs are those of the cached runs.
Word choice on the public neutral test sets, each model alone (no engine, no n-gram), against the theoretical compute
to score a row: of the Zhiyi models only the four maintained ones are shown, pumpkin
(zhiyi-ml-pumpkin), Flash
(zhiyi-ml-flash), Mini (this model) and Feather
(zhiyi-zhen-feather), each scored with its released ONNX file
(this model: onnx/w4/laya.mini.w4.onnx), so the points can differ a little from the numbers above. The other models
(the file of each, its license and how it is run) and the scoring code: https://github.com/dd1000001000/zhiyi_models/tree/main/comparisons/models
These weights are Zhiyi IME's own work and are licensed under the Apache License 2.0 (LICENSE). The reference
code in candle_ref/ is GPL-3.0-only, like Zhiyi IME (https://github.com/dd1000001000/zhiyi_ime/blob/main/LICENSE).
The upstream parts keep their licenses: the Laya architecture (https://huggingface.co/convaiinnovations/laya)
Apache-2.0, the mmBERT-small encoder and tokenizer (Marone et al., 2025; https://huggingface.co/jhu-clsp/mmBERT-small)
MIT (the 32k tokenizer is a subset of its vocabulary). The n-gram table follows the idea of hashed n-gram embeddings
read beside a transformer (Engram-style conditional memory); the design and the code here are Zhiyi's own.
Teachers (only their scores and words were used; none of their weights are in these files): Zhiyi's own 8-layer model (zh-lite-next-preview's Lite x8) online for word choice; Qwen3.5-9B (https://huggingface.co/Qwen/Qwen3.5-9B) fine-tuned with LoRA for word choice (stored scores) and Qwen3-1.7B-Base (https://huggingface.co/Qwen/Qwen3-1.7B-Base) for next words, both by the Qwen team (Alibaba Cloud), Apache-2.0. Next-word text: Chinese text of C4 (Raffel et al.) and LCCC, English text of FineWeb (CC-MAIN-2025-26) and C4. 1126's short-context word-choice rows: Chinese text of FineWeb-2 (cmn_Hani), LCCC and C4, their candidates from seven input-method engines run on the typed letters (Zhiyi, Rime with rime-ice and with luna_pinyin, libpinyin, libime, Qingjian and Microsoft Pinyin; only their candidate lists were used). These programs and data only produced training rows; none of them is in these files.
onnx/w4/laya.mini.w4.onnx 15 MBonnx/slim/laya.mini.w4.onnx 13 MBmodel.safetensors 13 MBtest_vectors.safetensors 21.9 kBjhu-clsp/mmBERT-small