MiniCPM-V-4.7-1B text model, ONNX for browser WebGPU

The language model of openbmb/MiniCPM-V-4.7-1B, converted to ONNX for Transformers.js on WebGPU. It was made to test MiniCPM-V-4.7-1B as the coding agent of the MiniCPM5-2B WebGPU Pi Space. Text only: the vision tower and resampler are not included, so it cannot read images.

dtype Weights Files Size
q4f16 int4 linear layers, fp16 embedding onnx/model_q4f16.onnx + _data 0.99 GB
fp16 all fp16 onnx/model_fp16.onnx + _data 2.07 GB

Sizes include the tokenizer and configs, as downloaded.

Our conversion

Converted directly from the official BF16 checkpoint openbmb/MiniCPM-V-4.7-1B@b0918c7, not from community-converted weights.

  • Source model.safetensors SHA-256, checked before packaging: 8c4921ac83182c85190ad10c3aeb118d51e385d2d98ec13b88b514bbf6cac002.
  • Graph: the fused-op Qwen3.5 text graph of onnx-community/Qwen3.5-0.8B-Text-ONNX (GroupQueryAttention, SkipSimplifiedLayerNormalization, CausalConvWithState, LinearAttention). Every architectural hyper-parameter matches. Every weight initializer is replaced by the MiniCPM-V-4.7-1B weight under a transform derived exactly from the template's own source (conversion/derive_mapping.py, conversion/build_v47_onnx.py). The LM head is untied, as in the checkpoint.
  • q4f16: ONNX Runtime MatMulNBitsQuantizer with the settings ONNX Runtime GenAI 0.15.2 used for Mike0021/MiniCPM5-2B-ONNX: symmetric int4, block size 32, accuracy level 4, every MatMul including the LM head. The fp16 embedding is split losslessly into four column shards to fit WebGPU binding limits (conversion/quantize_q4f16.py).
  • Last-position logits are selected before the LM head (conversion/last_position_head.py). Transformers.js 4.2.0 otherwise computes logits for every prompt position, which fails beyond about 4.3K prompt tokens in the browser.
  • FP16 activations, KV cache and recurrent state.

manifest.json lists the size and SHA-256 of every file. They are byte-identical to the files used in the benchmark.

Validation

Teacher-forced checks: the converted graph runs a real prefill followed by cached one-token decoding over the reference's own greedy continuation, and the logits are compared at every predicted position. They cover short continuations only, not long sampled conversations.

Comparison Prompts Top-token agreement Mean KL
fp16 ONNX (ONNX Runtime CPU) vs fp32 PyTorch 6 short 36/36 4.0e-06
q4f16 ONNX vs official BF16 PyTorch 6 short 31/36 0.260
q4f16 ONNX vs official BF16 PyTorch 24 agent task prompts × 16 positions 282/384 0.345

The fp16 graph matches PyTorch. Int4 quantization costs this 1B model noticeably more than it costs MiniCPM5-2B under the same settings (348/384 on the same task-prompt check). Prefer fp16 when quality matters more than download size. The chat template renders identically in the browser and in Python transformers, down to the token IDs, including tool calls. Raw results are in validation/.

Tested in Chromium on WebGPU with Transformers.js 4.2.0 and its ONNX Runtime Web build (as bundled in the Space), on an AMD Radeon 8060S.

Usage

import { AutoTokenizer, AutoModelForCausalLM } from "@huggingface/transformers";

const id = "Mike0021/MiniCPM-V-4.7-1B-text-ONNX";
const tokenizer = await AutoTokenizer.from_pretrained(id);
const model = await AutoModelForCausalLM.from_pretrained(id, { device: "webgpu", dtype: "q4f16" }); // or "fp16"

const inputs = tokenizer.apply_chat_template(
  [{ role: "user", content: "Write a shell one-liner that counts the lines of every .csv file." }],
  { add_generation_prompt: true, enable_thinking: false, return_dict: true },
);
// Sampling recommended on the model card: temperature 0.7, top_p 0.95, top_k 100, repetition_penalty 1.03.
const output = await model.generate({ ...inputs, max_new_tokens: 512, do_sample: true, temperature: 0.7, top_p: 0.95, top_k: 100, repetition_penalty: 1.03 });
console.log(tokenizer.batch_decode(output.slice(null, [inputs.input_ids.dims.at(-1), null]), { skip_special_tokens: true })[0]);

Results in the coding-agent benchmark

The benchmark ran 24 short coding tasks (shell, JavaScript, web, small projects), 5 trials each, inside the agent of the MiniCPM5-2B WebGPU Pi Space, with its limits unchanged: 2,048 output tokens per model call, an 8,192-token conversation, 12 turns, and a strict tool-call parser that ends a request on the first malformed call. Hidden tests graded each run. It measures these models as that Space's agent on one machine (AMD Radeon 8060S, Chromium), not general coding ability.

Configuration Passing runs
q4f16, thinking off (model-card default) 0/120
q4f16, thinking on 0/120
fp16, thinking off 1/120
q4f16, lenient tool-call parser 0/120
For reference: MiniCPM5-2B (the Space's model), thinking on 69/120

In the default configuration, 57% of runs ended on a tool call the parser rejected (invented tools, repeated or unclosed parameters), and most of the rest finished with wrong results. The fp16 row shows quantization alone does not explain this. This says nothing about the model's image understanding, which this package cannot use.

License

Apache 2.0, as for openbmb/MiniCPM-V-4.7-1B. The conversion and validation scripts in conversion/ are provided as is, for reference.

Downloads last month
131
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Mike0021/MiniCPM-V-4.7-1B-text-ONNX

Quantized
(51)
this model