The larger multilingual input-method model of Zhiyi IME: 12 ModernBERT layers of width 384 (the mmBERT-small tokenizer) that do two things:
char_logits), in Simplified
and Traditional Chinese (pinyin, Zhuyin with tones, Jyutping) and Japanese (kana).It is ML-pumpkin-1026 (Zhiyi IME's default model in 1.6.0–1.6.3) with a prefix mask, so the context's keys and values can be computed once per context and reused on every key, and one head for both tasks, trained two more epochs; it is much better when there is no context and as good or better with it. Of the four Zhiyi models maintained now it is the largest: pumpkin and Flash (8 layers) are the multilingual ones, Feather and Mini the Chinese (Simplified and Traditional) + English ones. pumpkin and Flash use the same tokenizer, vocabulary and inputs. ML-pumpkin-1103 is not in Zhiyi IME. The GitHub release model-ml-pumpkin-1103 has the same files, and its release notes have every test result. All Zhiyi models: https://github.com/dd1000001000/zhiyi_models
| File | |
|---|---|
model.safetensors |
all weights, unquantized (166 MB; encoder and head F16, composition read-out F32): quantize the linear layers to Q8_0 when loading (below) to get the accuracy measured here |
config.json |
the structure (with encoder.layer_types), prefix_mask, shared_head, special tokens, sequence settings, ml (language tags, typed-text length, tone stride) and quantize_q8_0: the tensors to quantize |
tokenizer.json |
mmBERT's tokenizer (Gemma vocabulary, 256,000 tokens), unchanged |
unified_vocab.json |
the 3,805 units, 28 letters, 9,067 characters; readings (the 6,163 Simplified characters' pinyin) and under ml the other languages' tables |
test_vectors.safetensors |
16 word-choice / composition inputs with the fp32 ONNX model's outputs, to check an implementation |
candle_ref/ |
a reference forward pass in Rust (candle 0.11), version 0.4.0 |
onnx/int8/ |
the ONNX graphs, int8: laya.int8g.onnx (83 MB, the whole sequence at once), laya.one.int8g.onnx (84 MB, one graph with a KV cache) and laya.one.fused.int8g.onnx (86 MB, the same with ONNX Runtime's fused attention and rotary operators, CPU only), with their tokenizer and JSON files |
example.py |
the quick start below |
LICENSE |
Apache License 2.0 |
Word choice and composition with the whole graph, then word choice with the one graph's context cache (the code is in
example.py):
pip install onnxruntime tokenizers numpy huggingface_hub
python example.py
FILES = ["laya.int8g.onnx", "laya.one.int8g.onnx", "tokenizer.json", "unified_vocab.json"]
D = os.path.join(snapshot_download("zhiyi-ime/zhiyi-ml-pumpkin", allow_patterns=[f"onnx/int8/{f}" for f in FILES]),
"onnx", "int8")
tok = Tokenizer.from_file(os.path.join(D, "tokenizer.json")) # context, tags, typed text and candidates
BOS, EOS, MASK = 2, 1, 4
# 1. Word choice: <bos> context <eos> <mask> x syllables <eos> <mask> cand1 <mask> cand2 ... <eos>
# (laya.int8g.onnx; each candidate's score is read at the <mask> before it)
print(choose("今天天气很好,我们去公园", ["san", "bu"], ["散步", "散布", "三部"]))
# 2. Composition: <bos> "已输入的上文: " + context <eos> <mask> x syllables <eos>; one character per slot
print(compose("明天早上八点", "wo men zai xue xiao men kou jian mian".split()))
# 3. The same word choice with laya.one.int8g.onnx: the context block once, then only the rest on each key
cache = context_cache("今天天气很好,我们去公园") # once per context
print(choose_cached(cache, ["san", "bu"], ["散步", "散布", "三部"])) # on each key
Output (ONNX Runtime 1.24.4, CPU):
[('散步', 2.16...), ('散布', -7.21...), ('三部', -7.98...)]
我们在学校门口见面
[('散步', 2.18...), ('散布', -7.03...), ('三部', -7.98...)]
The calls build the inputs of test_vectors.safetensors cases 0 and 5 (token for token); the fp32 scores of case 0
are 2.18, −7.06 and −7.95, and the two int8 graphs differ from them a little (they are quantized separately). The other
languages use the same graphs: a row in Traditional Chinese, Japanese, Korean or Vietnamese starts with its tag
(<zh-Hant>, <ja>, <ko>, <vi>) after <bos> and carries the typed text as tokens (see Inputs below).
laya.one.int8g.onnx runs two ways with the same weights:
input_ids, unit_ids of the leading block <bos> [tag] context <eos> (batch 1); past_enc_k / past_enc_v (12 × 1 × 6 × 1 × 64) and past_choice_k / past_choice_v
(2 × 1 × 6 × 1 × 64) all zeros with past_mask = [[false]] (a one-step placeholder: DirectML does not take
zero-length tensors), marker_pos = slot_pos = [[0]]. Keep its present_enc_k, present_enc_v,
present_choice_k, present_choice_v (… × n × 64 for the block's n tokens): the context's cache.input_ids, unit_ids, the cache as the four past_* inputs with past_mask all true (1 × n), and marker_pos,
slot_pos counted from the end of the block → logits (word choice) and char_logits (composition), as the whole
graph.laya.one.fused.int8g.onnx has the same inputs and outputs. Use it on the CPU: on DirectML with fixed shapes its fused
attention gives wrong results (ONNX Runtime 1.24.4); on a graphics card use laya.one.int8g.onnx.
Speed (int8, ONNX Runtime 1.24.4, CPU 4 threads, AMD Ryzen 5 9600X, the pages of the public neutral-v2 set; median over 300 pages):
| File | Time | |
|---|---|---|
laya.int8g.onnx (whole graph) |
83 MB | 8.3 ms a page |
laya.one.int8g.onnx (one graph, KV cache) |
84 MB | 6.9 ms once per context, 5.4 ms a key |
laya.one.fused.int8g.onnx (KV cache, fused operators) |
86 MB | 5.5 ms once per context, 4.3 ms a key |
A page of the whole graph also runs the context, so with the cache a key costs 5.4 ms (fused 4.3 ms) instead of 8.3 ms. In PyTorch the one graph equals the whole sequence to 1.5e-5; in int8 (each graph quantized on its own) it scores on average 0.2 points above the whole graph on the 300-row word-choice tests below (each set within ±1.3, the fused graph within ±1.4).
From ML-pumpkin-1026: fine-tuned with the prefix mask (half an epoch), one epoch over all of its rows with the shared head (one rented RTX 5090), then one more epoch over all the training rows (one RTX 5070 Ti): 9.2 million word-choice rows (3.1 million in Traditional Chinese, Japanese, Korean and Vietnamese, and 480 thousand rows typed without any context) and 8.2 million composition rows, every row with the stored scores of the Qwen3.5-9B LoRA teachers; targets 80% from those scores, 20% from the right answer.
Names are the PyTorch ones. The encoder and the head are F16 (as trained), the composition read-out F32, the embeddings F16.
| Tensor | Shape | |
|---|---|---|
encoder.embeddings.tok_embeddings.weight |
126963 × 384 | F16, pruned rows (see vocab_remap) |
vocab_remap |
256000 | I32: token id → embedding row (tokens outside the kept set → <unk>'s row) |
encoder.embeddings.norm.weight |
384 | LayerNorm, no bias |
encoder.layers.N.attn_norm.weight (N ≥ 1; layer 0 has none) |
384 | |
encoder.layers.N.attn.Wqkv.weight |
1152 × 384 | N = 0…11 |
encoder.layers.N.attn.Wo.weight |
384 × 384 | |
encoder.layers.N.mlp_norm.weight |
384 | |
encoder.layers.N.mlp.Wi.weight |
2304 × 384 | |
encoder.layers.N.mlp.Wo.weight |
384 × 1152 | |
encoder.final_norm.weight |
384 | |
unit_emb.weight |
3833 × 384 | row 0 = none, 1-3804 the units of unified_vocab.json, 3805-3832 letters |
tone_emb.weight |
6 × 384 | Zhuyin tones: row 0 = none, 1-5 (5 = neutral) |
type_emb.weight |
3 × 384 | row 0 is the one used (both tasks) |
head.layers.{0,1}.* |
nn.TransformerEncoderLayer, shared by both tasks |
|
scorer.0 (LayerNorm), scorer.1 (384 → 384), scorer.3 (384 → 1) |
word choice | |
out.0 (LayerNorm), out.1 (384 → 384) |
composition | |
char_emb.weight |
9067 × 384 | F16: the token embedding rows of the 9067 characters |
char_bias |
9067 |
The 58 tensors listed in config.json quantize_q8_0 (every linear weight: the encoder's Wqkv, Wo, Wi,
mlp.Wo, the head's in_proj_weight, out_proj, linear1, linear2, scorer.1, out.1) go to Q8_0: blocks
of 32 along the input dimension, one f16 scale per block. With candle:
use candle_core::quantized::{GgmlDType, QMatMul, QTensor};
let w = safetensors.load(name, &device)?.to_dtype(DType::F32)?;
let w = QMatMul::from_qtensor(QTensor::quantize(&w, GgmlDType::Q8_0)?)?;
// w.forward(&x) = x · wᵀ, then add the bias if the layer has one
Keep the embeddings unquantized (they are only indexed) and everything 1-D in F32.
One sequence at a time, as the IME runs it (batch 1, no padding; with padding, mask padded keys in every attention below).
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 both head
layers. Positions start at 0 at <bos> as usual, so the block's keys and values are the same whatever follows.
x = tok_emb[vocab_remap[input_ids]] + unit_emb[unit_ids % 3833] + tone_emb[unit_ids / 3833], then
LayerNorm (encoder.embeddings.norm). A unit id carries a Zhuyin tone t as unit + 3833 · t.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, 3, 6 and 11 attend globally (full_attention), the others only where |i − j| ≤ 64
(sliding_attention).x += Wo(attention); then a, g = split(Wi mlp_norm(x)) (1152 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 the two head.layers (PyTorch
nn.TransformerEncoderLayer, norm_first=True, 6 heads, feed-forward 1536 with ReLU, LayerNorm eps 1e-5,
in_proj_weight = q, k, v stacked; no final norm), with the prefix mask.score = scorer.3(gelu(scorer.1(scorer.0(h0[marker])))).
Higher is better.h0, q = out.1(out.0(h0[slot])) and
char_logits = q · char_embᵀ + char_bias. Compare only the characters the slot's unit can spell in the
row's language.Caching the context. Run the block alone once per context and keep each layer's keys and values (after
RoPE) for its n positions: 12 encoder layers and 2 head layers, each (6, n, 64) for k and v. On each key,
run only positions n … (the typed units, the candidates and the <eos>s, positions continuing from n),
attending to the cached keys and values in front of their own. The last head layer only needs its queries at
the markers and slots. The outputs are the whole sequence's; onnx/int8/laya.one.int8g.onnx is this as one graph.
Token ids are tokenizer.json's, with <bos> (2) as [CLS], <eos> (1) as [SEP], <mask> (4). Text is encoded
without special tokens. A row in Traditional Chinese, Japanese, Korean or Vietnamese starts with its tag as plain
text (<zh-Hant>, <ja>, <ko>, <vi>); Simplified Chinese and English have no tag. The composition prefix
已输入的上文: ("text typed so far: ") is literal model input.
word choice (zh, en) <bos> encode(context)[last 128] <eos> <mask> × typed units <eos> <mask> encode(" 候选1")[:16] … <eos>
word choice (others) <bos> encode(tag) encode(context)[last 128] <eos> encode(typed text)[:24] <eos> <mask> encode(" 候选1")[:16] … <eos>
composition <bos> [encode(tag)] encode("已输入的上文: " + context) <eos> <mask> × slots <eos>
In every sequence the leading block (the prefix mask's) is everything up to and including the first <eos>:
the context. The typed units, the typed text and the candidates follow it.
test_vectors.safetensors holds, for case i = 0…15, i.input_ids (full-vocabulary ids, before the remap),
i.unit_ids, i.marker_pos, i.slot_pos (int64) and the fp32 ONNX model's output (i.logits for word
choice, i.char_logits for composition). Cases 0-7 Chinese and English; 8-13 word choice in Zhuyin,
Cangjie 5, Jyutping, Japanese, Korean and Vietnamese; 14 Zhuyin composition with tones, 15 Japanese
composition. The Q8_0 model agrees with them to about 0.32 and picks the same best candidates and characters.
The model alone (not an IME end to end), first candidate / best character per slot. The first 300 rows of each
Traditional, Japanese, Korean and Vietnamese test file in the engine's order ("Engine" is the engine's own first
candidate), every third row of the Simplified Chinese and English sets; fp32 ONNX = the whole graph exported from
these weights; int8 ONNX = laya.int8g.onnx; Q8_0 = this model.safetensors through candle_ref. The best of each
row is in bold.
| Word choice, first candidate right | Engine | fp32 ONNX | int8 ONNX | Q8_0 (candle_ref) |
|---|---|---|---|---|
| Simplified Chinese, words and word pairs (2175) | 88.3% | 88.4% | 88.2% | |
| Simplified Chinese, long input (749) | 84.2% | 83.7% | 84.4% | |
| English (729) | 89.8% | 89.8% | 89.8% | |
| Simplified Chinese, IME's real candidates (545) | 89.9% | 89.9% | 89.9% | |
| Simplified Chinese homophones with the previous sentence (267) | 92.9% | 92.9% | 92.9% | |
| English word completion (280) | 88.2% | 87.9% | 88.2% | |
| Traditional, pinyin (luna_pinyin) (300) | 62.3% | 84.7% | 84.0% | 85.0% |
| Traditional, Zhuyin (bopomofo_tw) (300) | 85.7% | 89.3% | 88.0% | 89.3% |
| Traditional, Zhuyin (libchewing) (300) | 90.0% | 96.0% | 94.7% | 95.7% |
| Traditional, Jyutping (jyut6ping3) (300) | 69.0% | 90.3% | 90.0% | 90.3% |
| Traditional, Cangjie 5 (300) | 67.0% | 96.7% | 96.7% | 96.7% |
| Traditional, Quick 5 (300) | 92.3% | 89.7% | 88.3% | 89.3% |
| Traditional, Cangjie 3 (300) | 35.7% | 82.0% | 81.7% | 82.0% |
| Traditional, Quick 3 (300) | 39.7% | 77.3% | 76.7% | 77.7% |
| Japanese, conversion (Mozc) (300) | 87.7% | 93.0% | 93.0% | 93.0% |
| Japanese, prediction (Mozc) (300) | 74.3% | 87.0% | 87.0% | 87.0% |
| Japanese, whole sentence (Mozc) (300) | 92.7% | 95.7% | 96.3% | 95.3% |
| Korean, word completion (300) | 44.7% | 65.0% | 65.0% | 65.0% |
| Vietnamese, without diacritics (300) | 73.7% | 89.7% | 89.0% | 89.7% |
| Vietnamese, first letters (300) | 40.7% | 73.7% | 72.0% | 73.7% |
| Composition, whole rows right / characters right | fp32 ONNX | int8 ONNX | Q8_0 (candle_ref) |
|---|---|---|---|
| Simplified, long pinyin in full (300) | 57.7% / 85.6% | 58.3% / 85.7% | 57.3% / 85.6% |
| Traditional, pinyin (300) | 44.0% / 73.7% | 43.0% / 72.4% | 44.0% / 73.6% |
| Traditional, Zhuyin (70% with tones) (300) | 70.0% / 92.3% | 68.3% / 91.7% | 70.0% / 92.3% |
| Traditional, Jyutping (300) | 43.3% / 74.3% | 42.7% / 74.0% | 43.3% / 74.2% |
| Japanese, kana (300) | 76.0% / 96.7% | 72.7% / 96.7% | 75.7% / 96.7% |
Without context (the first word of a text, a new paragraph, a fresh text box): the model alone in PyTorch, the same rows with the context emptied, first candidate right; "with" = the context kept:
| ML-pumpkin-1026 with / without | ML-pumpkin-1103 with / without | |
|---|---|---|
| Simplified Chinese, words and word pairs (6333) | 87.8% / 66.6% | 88.7% / 73.6% |
| Simplified Chinese, long input (2156) | 84.9% / 67.2% | 85.8% / 73.5% |
| English (2144) | 90.0% / 70.1% | 90.1% / 74.9% |
| Recent web text, Chinese words (998) | 91.6% / 66.6% | 92.1% / 74.4% |
| Traditional, pinyin (luna_pinyin, 2999) | 86.2% / 56.2% | 86.3% / 63.8% |
| Traditional, Zhuyin (bopomofo_tw, 3000) | 91.4% / 72.3% | 92.3% / 78.9% |
| Traditional, Jyutping (3000) | 90.5% / 70.1% | 90.9% / 74.3% |
| Traditional, Cangjie 3 (3000) | 84.8% / 53.0% | 85.0% / 59.6% |
| Traditional, Quick 3 (3000) | 79.5% / 36.6% | 79.6% / 47.0% |
End to end in Zhiyi IME's engine with the word n-gram ng1017 (Simplified Chinese and English; the composition head's sentences on; emoji, custom phrases, date / time and U / V mode off; every third row of the word-choice test set, 4,175 rows; first candidate right):
| Frequency only | ng1017 + ML-pumpkin-1026 | ng1017 + ML-Flash-1031 | ng1017 + ML-pumpkin-1103 | |
|---|---|---|---|---|
| Chinese, words and word pairs (2183) | 72.5% | 88.2% | 88.0% | 88.7% |
| Chinese, long input (746) | 50.7% | 75.6% | 76.1% | 76.1% |
| English words (724) | 77.6% | 89.8% | 90.1% | 90.6% |
| Chinese typed as initials only (139) | 39.6% | 77.7% | 79.1% | 82.0% |
| English, first letters only (304) | 48.0% | 76.3% | 77.0% | 78.3% |
The differences between the models are within sampling error (about ±1.6 points on long input, ±1 on words; the initials row has only 139 rows).
On the public neutral word-choice test sets (v2, v3 web, v4 chat, v5 hard; each model's released ONNX file alone, whole page, first candidate right), the four maintained Zhiyi models:
| ML-pumpkin-1103 | Flash (ml-flash-next-preview-1114) | Mini (zhen-mini-next-preview-1116) | Feather (zhen-feather-preview-1121) | |
|---|---|---|---|---|
| v2 | 93.53% | 92.73% | 93.21% | 92.29% |
| v3 | 93.84% | 93.19% | 93.19% | 92.91% |
| v4 | 90.89% | 90.51% | 91.07% | 91.61% |
| v5 | 72.47% | 71.02% | 70.38% | 68.70% |
candle_ref: candle's quantized kernels choose their SIMD code at compile time, so build with
RUSTFLAGS="-C target-cpu=native" (or at least x86-64-v3), otherwise the Q8_0 dot products run scalar code.
cd candle_ref
RUSTFLAGS="-C target-cpu=native" cargo build --release
target/release/zhiyi-ref ../model.safetensors ../test_vectors.safetensors out.safetensors
candle_ref runs the whole sequence with the mask (it does not cache); the outputs are those of the cached run.
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 (this model), Flash
(zhiyi-ml-flash), Mini
(zhiyi-zhen-mini) and Feather
(zhiyi-zhen-feather), each scored with its released ONNX file
(this model: onnx/int8/laya.int8g.onnx). 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.
Teachers (only their scores were used; none of their weights are in these files): Qwen3.5-9B (https://huggingface.co/Qwen/Qwen3.5-9B, Qwen team, Alibaba Cloud, Apache-2.0) fine-tuned with LoRA for word choice and composition. Text and candidate sources: SkyPile-150B, LCCC, C4, SODA, Tatoeba, FineWeb, FineWeb-2, the Cantonese Wikipedia; librime with the Rime schemas, the Cangjie 3 / Quick 3 tables of fcitx5-table-extra, libchewing, Mozc; readings from Mozc's dictionary, pypinyin, OpenCC and SudachiPy. These programs and data only produced training rows; none of them is in these files.
model.safetensors 165 MBonnx/int8/laya.one.fused.int8g.onnx 86 MBonnx/int8/laya.one.int8g.onnx 84 MBonnx/int8/laya.int8g.onnx 83 MBtest_vectors.safetensors 2 MBjhu-clsp/mmBERT-small