Instructions to use RASMUS/MiniCPM5-2B-ONNX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers.js
How to use RASMUS/MiniCPM5-2B-ONNX with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('text-generation', 'RASMUS/MiniCPM5-2B-ONNX');
MiniCPM5-2B — ONNX (q4f16) for WebGPU
An ONNX export of openbmb/MiniCPM5-2B
that runs in a browser on WebGPU through
Transformers.js.
At the time this was built, no export of the 2B existed that a browser could
load. The official ONNX release covers the 1B only, and it is a CPU-shaped fp16
build (MultiHeadAttention, no MatMulNBits, no config.json) in a layout
Transformers.js does not resolve.
Contents
| File | Size |
|---|---|
onnx/model_q4f16.onnx |
316 KB (graph) |
onnx/model_q4f16.onnx_data |
1.83 GB (weights) |
Single variant, q4f16: int4 weights (MatMulNBits) with fp16 graph I/O.
A GPU without the shader-f16 feature cannot run this.
The embedding table is not quantised, because MiniCPM5-2B sets
tie_word_embeddings: false and the model builder quantises that table only for
tied models. Those 267 M parameters cost about 535 MB of the total.
Usage
import { pipeline } from '@huggingface/transformers';
const generator = await pipeline('text-generation', 'RASMUS/MiniCPM5-2B-ONNX', {
device: 'webgpu',
dtype: 'q4f16',
});
const output = await generator(
[{ role: 'user', content: 'Explain WebGPU in two sentences.' }],
{ max_new_tokens: 256 },
);
Measured performance
RTX 4080 Laptop, Chromium 152 on Windows, @huggingface/transformers 4.2.0 over
onnxruntime-web WebGPU. Warmed runs, first run at each prompt length discarded.
| Measurement | Value |
|---|---|
| Prefill, 1024-token prompt | 0.395 ms / prompt token |
| Prefill, 512-token prompt | 0.411 ms / prompt token |
| Prefill, 128-token prompt | 0.611 ms / prompt token |
| Decode | 24.1 ms / token (41.6 tok/s) |
| First token, 64-token prompt | 199 ms |
| Session load, warm cache | 6.5 s |
These are one GPU's numbers, not a general claim.
How it was built
python -m onnxruntime_genai.models.builder \
-i <local openbmb/MiniCPM5-2B> -o out -p int4 -e webgpu -c cache
onnxruntime-genai 0.15.2. -e webgpu is what selects the
GroupQueryAttention branch — the same build on the cpu provider silently
emits MultiHeadAttention instead, which is the defect in the published 1B
export. The graph is 473 nodes: MatMulNBits x211, GroupQueryAttention x42,
no Scan/Loop, and no position_ids input, because GQA fuses RoPE.
Three changes were then needed to make the output loadable by Transformers.js. Each is recorded because each fails in a way that does not name its cause.
- The KV cache head dimension was made concrete. The builder declares it as
the symbol
kv_cache_dim. Transformers.js builds the first empty cache from the session's input metadata and resolves any symbol it does not know to0, soGroupQueryAttentionrejected the tensor on the first forward:Input 'past_key' dimension 3 should be same as head_size, got 0 expected 128. - The chat template was moved into
tokenizer_config.json. Transformers.js readschat_template.jinjaonly for multimodal processors; a text tokenizer readstokenizerConfig.chat_templateand nothing else. - One dead line was removed from the chat template. It assigned
min_count = [...]|min, and@huggingface/jinjahas nominfilter for arrays, so every assistant turn carryingtool_callsfailed to render. The variable is never read.chat_template.jinjahere carries the patched text, identical to the copy insidetokenizer_config.json.
transformers.js_config in config.json declares one external-data chunk and
an fp16 KV cache, both of which Transformers.js requires and neither of which
the builder writes.
Limitations
- English and Chinese. Other languages are not claimed by the base model.
- Quantised. int4 weights change outputs relative to the bf16 original. Spot-checked against the bf16 model on CPU, including a refusal that both produce identically. Not benchmarked for quality.
- Tool calls are XML, not the Pythonic form some other models emit. A parser written for one will not read the other.
Attribution
Base model © OpenBMB, Apache-2.0. This repository redistributes a converted and quantised copy of those weights under the same licence. No weights were retrained or fine-tuned.
- Downloads last month
- 462
Model tree for RASMUS/MiniCPM5-2B-ONNX
Base model
openbmb/MiniCPM5-2B