Repository navigation
feat(minicpm5): MiniCPM5-15B-A2.5B on the NPU (minicpm5:15b-a2.5b) - #1253
Conversation
MiniCPM5 writes <function name="f"><param name="k">v</param></function> with no wrapper tag, and puts a value in CDATA when it holds <, & or a newline. Add the MINICPM_XML kind: detection, a call head that tells a call from prose, a CDATA-aware end of call, the parser and the decoding grammar. minja now counts <param name="argument_needle"> as rendering tool calls, so MiniCPM5's template renders calls and tool responses itself, matching transformers. Co-Authored-By: Claude <noreply@anthropic.com>
Converter (minicpm5_moe), MiniCPM5 moe_decoding + lm_head kernels (one layer xclbin for all 28 layers: layer 0's dense MLP runs as 16 fixed experts), and the minicpm5_moe_npu engine with batched prefill on the prefill overlay. Co-Authored-By: Claude <noreply@anthropic.com>
- MiniCPM5 frontend (thinking on by default, model-card sampler); holds back the "\n" after <think> so a later turn's prompt extends the saved prefix - builtin frontend/backend registration, CMake link, installer entry - model_list entry (min FLM 1.0.15, default context 128K) - server: chat_template_kwargs.enable_thinking is read for minicpm5 too; test_reasoning accepts minicpm5 for the nested switch - dev kit: engines.json, kernel_assignment, change detection + tests - docs: model card, benchmarks page (decode/prefill 1K-32K, quant KLD) Co-Authored-By: Claude <noreply@anthropic.com>
…ay runs Prefill sends a MoE layer's routed experts (plus the shared expert and layer 0's fixed experts) to the prefill overlay as one up_gate and one down run per group instead of one dispatch per expert. Run kernels are built with the launchlib ELF writer on a writer thread ahead of the NPU, and the host gather / GLU / weighted sum of one group overlaps the other group's runs (MC5_BATCH_GROUPS, default 2). Logits are byte-identical to the per-expert path. 2048-token prefill, warm: 8.38 -> 3.44 s; server TTFT at 2K 6.0 -> 3.2 s, at 32K 161 -> 113 s. Co-Authored-By: Claude <noreply@anthropic.com>
New FLM_Xclbin/MiniCPM5/prefill_overlay (attention op as in the Hy-Mem overlay; dq op = dequant_mm_bfp16 with runtime rows and a fused GLU epilogue). The core writes silu(gate) * up directly; sigmoid comes from exp2 plus a Newton reciprocal instead of the vector tanh, which was ~2 % off and cancelled for negative gates. Engine: routed, shared and layer-0 fixed experts plus kvqg / o run on the new overlay; host GLU removed (MINICPM5_MOE_HOST_GLU=1 keeps plain dispatch + host GLU, bit-identical to the previous path); MC5_BATCH_CHECK=1 reports per-group cos. Metadata: kernel_assignment + build_units entry for xclbins-MiniCPM5_prefill_overlay. 2048-token prefill warm 3443 -> 2691 ms (stock 8383), cold 3964 -> 2969; server TTFT 1K 1.46 s, 2K 2.28 s, 32K 102.4 s. Top-100 KLD: harness 0.0420 (stock 0.0430), 2K set 0.1805 vs BF16 (limit 0.1885). Unit gates: row counts 64..2048 bit-exact, 2000-dispatch soak, dq <-> attn switches. Co-Authored-By: Claude <noreply@anthropic.com>
The overlay's attention op ran on columns 0-3 (2 CUs). It now repeats that block on columns 4-7: 4 CUs of 2 columns, 8 q heads per round, and each half of the array gets its own K / V stream (shim 3 / 7 through mem tile 3 / 7 to the half's 16 cores; the half's two CUs share a KV head). Core code, BD ids and the base xclbin layout are unchanged; the op table is regenerated and re-copied into the engine. Unit host: --attn-l L (query rows = keys) and a cos >= 0.999 gate vs the CPU reference (now OMP over rows): 0.99945 at 512, 0.99941 at 2048, 0.99960 at 8192 keys; every run bit-identical to the first across dq <-> attn switches; soak 2000 / 2000. Attention L 512 1319 -> 792 us. Engine: 2048-token prefill attention 435 -> 259 ms, warm 2794 -> 2390 ms (cold 2755); logits byte-identical to the 4-column build (harness cases and 2K set), so top-100 KLD is unchanged (0.0420 / 2K set 0.1805). Server TTFT 2K 2.11 s, 32K 102.4 -> 64.9 s, 126K tokens 647.6 s (needle found). Co-Authored-By: Claude <noreply@anthropic.com>
libgomp's default wait policy spins every worker after a parallel region; with 31 spinning cores the NPU runs, XRT and the batch writer thread were starved. A library cannot change that policy (libgomp reads it at process start), so the prefill's host work now runs on its own pool (prefill_pool(), prefill_threads() wide) whose workers wait on an atomic. Every prefill OpenMP loop moved to it. Host steps: rms_norm, rope (one table per chunk), rope + KV store fused, gate and the router's fp32 tiles in AVX-512 with exact bf16 rounding; overlay copies in and out of the BOs in parallel; the weighted expert sum vectorized. The batched experts sync only what the host touches (x before the up run, the down output after); the GLU output stays on the device. A new batch BO is flushed once when created, so no dirty host line is left to be written back over NPU data. prewarm() at load sets up what the first prefill otherwise did itself (scratch, pool threads, batch run slots, batch BOs for a 4096-token chunk at even routing): +94 ms load, cold 2K prefill 1720 -> 1534 ms. 2048 tokens warm 2390 -> 1505 ms (8383 ms before the prefill work), cold 2755 -> 1534 ms. Logits byte-identical to the previous build on every harness case and the 2K set, so top-100 KLD is unchanged (0.0420 / 2K set 0.1805). Server TTFT 1K 1.00 s, 2K 1.59 s, 32K 57.8 s, 126K 622.9 s (needle found everywhere). Co-Authored-By: Claude <noreply@anthropic.com>
- rest_handler.cpp: keep main's qwen3.5-dflash2 in the template-think family list and add minicpm5. - test_changes.py: MiniCPM5/prefill_overlay names host/ outside host.mk with no bitstream prerequisite, like the Hy_* overlays. - model_info.json: minicpm5:15b-a2.5b from the published package's tree. - minicpm5 benchmark page: numbers from the CI-built engine. Co-Authored-By: Claude <noreply@anthropic.com>
Security scan found no critical or high findings on lines changed by this pull request28 medium, low, or unrated finding(s) are not listed; the scan run has them. View the security scan run for complete reports. “New” means the finding is located in a changed file on an added or modified line; it is not a base-versus-head findings delta. |
launch::txn::elf_of()::kNames is a constant from aie2p-launchlib's launch/txn/elf.hpp. inkling2_npu and minicpm5_moe_npu both write run ELFs and compile it from that one header; the 56 bytes are the same in both libraries. Co-Authored-By: Claude <noreply@anthropic.com>
Dev-kit benchResults of the dev-kit benches in Build and Test run 47296283384 for SummaryDev-kit bench (pr) on
|
| Model | Machine | Context | Decode base → dev-kit | Δ | Prefill base → dev-kit | Δ | Decode Δ vs nightly (same kind) |
|---|---|---|---|---|---|---|---|
| minicpm5:15b-a2.5b | strix | 1k | — → 24.7 | — | — → 858.8 | — | no baseline for this kind |
| minicpm5:15b-a2.5b | strix | 2k | — → 23.9 | — | — → 1051.5 | — | no baseline for this kind |
| minicpm5:15b-a2.5b | strix | 4k | — → 22.5 | — | — → 1088.0 | — | no baseline for this kind |
| minicpm5:15b-a2.5b | strix | 8k | — → 20.1 | — | — → 950.7 | — | no baseline for this kind |
GSM8K accuracy (%)
| Model | Nightly baseline | This run | Δ (points) | Notes |
|---|---|---|---|---|
| minicpm5:15b-a2.5b | — | 100.0 | — |
Linux HRX
Perf (tok/s; dev-kit against the base package on the same runner)
| Model | Machine | Context | Decode base → dev-kit | Δ | Prefill base → dev-kit | Δ | Decode Δ vs nightly (same kind) |
|---|---|---|---|---|---|---|---|
| minicpm5:15b-a2.5b | strix | 1k | — → 24.4 | — | — → 582.3 | — | no baseline for this kind |
| minicpm5:15b-a2.5b | strix | 2k | — → 23.8 | — | — → 809.6 | — | no baseline for this kind |
| minicpm5:15b-a2.5b | strix | 4k | — → 22.6 | — | — → 988.8 | — | no baseline for this kind |
| minicpm5:15b-a2.5b | strix | 8k | — → 20.2 | — | — → 874.3 | — | no baseline for this kind |
GSM8K accuracy (%)
| Model | Nightly baseline | This run | Δ (points) | Notes |
|---|---|---|---|---|
| minicpm5:15b-a2.5b | — | 100.0 | — |
Perf: flm bench, decode and prefill average tok/s per context. A/B is the one perf signal that judges a change; the runners differ by machine kind, so the nightly comparison is informational and only made for the same kind. Accuracy: GSM8K (first 50 questions) and DocVQA (when enabled), greedy; unanswered questions count as wrong. Per-question reports, server logs and CSVs: the devkit-bench-result-* artifacts.
…n failure HRX manages the hw contexts itself and may destroy the prefill overlay's context and create a new one between two overlay runs, right after it releases an executable built before. The new context loads the overlay again with nothing the host wrote into it, so a run written for the op the array was in (a partial switch, or none) waits forever: the 2K prefill of the HRX bench hung on a dequant_mm batch run until the driver's timeout. - On HRX every overlay run now writes the full configuration (minicpm5_moe_prefill_overlay::after() gives OP_NONE). On XRT, which keeps one hw context per xclbin, nothing changes. - A run that does not complete (the driver ended it and reset the array) is made again from a full switch; a second failure throws. Every run reads its inputs and writes only its output, so the result is the same. MC5_FAKE_FAIL_AT=<n>[,<n>...] fails the n-th run, to test that path. Checked: XRT 2K prefill bit-identical to before, also with 12 injected failures (attention, dequant_mm, batch); the full switch on every run (the HRX path, built for XRT) is bit-identical and costs ~6% of a 2K prefill; the HRX bench 4K/2K/1K twice, no run made again, while HRX still creates hw contexts mid-prefill. Co-Authored-By: Claude <noreply@anthropic.com>
# Conflicts: # flm-dev-kit/FLM_Q4NX_Converter/q4nx/constants.py # flm-dev-kit/FLM_Q4NX_Converter/q4nx/models/__init__.py # flm-dev-kit/FLM_Xclbin/rtp_addresses.lock.txt # src/model_info.json
The dev-kit engine libraries and kernels that run 47296283384 built from b649c39, staged into its product builds and tested on the NPU (devkit_swap.py fetch): 6 engine file(s), 3 kernel(s). CI checks these bytes against the run's staging manifests. src/lib/hrx/libminicpm5_moe_npu.so src/lib/hrx/minicpm5_moe_npu.dll src/lib/hrx/minicpm5_moe_npu.lib src/lib/xrt/libminicpm5_moe_npu.so src/lib/xrt/minicpm5_moe_npu.dll src/lib/xrt/minicpm5_moe_npu.lib src/xclbins/MiniCPM5-15B-A2.5B-NPU2/lm_head.xclbin src/xclbins/MiniCPM5-15B-A2.5B-NPU2/moe_layer.xclbin src/xclbins/MiniCPM5-15B-A2.5B-NPU2/prefill_overlay.xclbin Devkit-Swap-Run: 47296283384 Devkit-Swap-Tested: b649c39
The Windows installer ships the MiniCPM5 engine that the swap commit added (src/lib/<runtime>/minicpm5_moe_npu.dll); flm.iss already lists it. Co-Authored-By: Claude <noreply@anthropic.com>
Summary
Adds MiniCPM5-15B-A2.5B (OpenBMB, Apache 2.0) as
minicpm5:15b-a2.5b: 15B MoE with ~2.5B active per token (28 layers, 160 routed experts top-16 + 1 shared, gated GQA attention), 128K default context, thinking on by default, tool calling. Prefill and decode, including the lm_head, run on the NPU. Requires FLM >= 1.0.15.Weights: FastFlowLM/MiniCPM5-15B-A2.5B-NPU2 (HF) and amd/MiniCPM5-15B-A2.5B-NPU2 (ModelScope), 9.2 GB. All matrices Q4_K quantized with the importance matrix published by bartowski (lm_head Q8_0, embedding BF16).
Engine (
minicpm5_moe_npu): converter,MiniCPM5/moe_decoding(one layer xclbin for all 28 layers; layer 0's dense MLP runs as 16 fixed experts) + lm_head kernels, andMiniCPM5/prefill_overlay(bfp16 dequant MM with a fused GLU epilogue, attention on all 8 columns). Prefill batches each layer's experts into a few pipelined overlay runs; host prefill stages run on their own sleeping pool.Chat: new
MINICPM_XMLtool-call kind (<function name="f"><param name="k">v</param></function>, CDATA values): detection, parser, decoding grammar; minja recognizes the template as rendering tool calls itself.chat_template_kwargs.enable_thinkingworks for minicpm5.Catalog / docs:
model_list.json+model_info.jsonentries, installer entry, model card and benchmark page, dev-kit metadata (engines.json, kernel_assignment, build_units) and change-detection tests.HRX: HRX manages the hw contexts itself and may destroy the prefill overlay's context and create a new one between two overlay runs, which loads the overlay again without the routes / descriptors / locks the host wrote. On HRX every overlay run therefore writes the full configuration (~6% of a 2K prefill); on XRT nothing changes. A run that does not complete is made again from a full switch, and only a second failure throws (
MC5_FAKE_FAIL_AT=<n>injects a failure to test this).Performance
Strix Halo, default power mode,
flm benchwith the CI-built engine:2048-token prefill went 8.38 s -> 1.51 s over the prefill commits; every step kept logits byte-identical or within the KLD gate.
Accuracy
Top-100 KLD of the next-token distribution vs BF16 (100 x 512 tokens):
NPU vs a CPU run of the same weights: KLD 0.005-0.020 on chat, multi-turn, math, code, tool-call and 2.7K-token prompts.
Testing
flm pullfrom HF into an empty store verified; ModelScope sha256 of every file matches the package..github/scriptunit tests (580) pass;devkit_check,check_internal_refs,check_sampler_defaultsok.The engine libraries arrive with this PR's swap commit.
🤖 Generated with Claude Code