Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/script/ci/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ def devkit_extra_areas(path: str) -> set:
("minicpm_v_4_7_moe", "minicpm_v_moe"): ("minicpm-v-4.7-moe",),
("minicpm_v_4_7_bf16", "minicpm_v_bf16"): ("minicpm-v-4.7-bf16",),
("minicpm_ocr",): ("minicpm-ocr",),
("minicpm5_moe", "minicpm5"): ("minicpm5",),
("qwen3_6_moe",): ("qwen3.6-moe",),
# qwen3.8-dflash2 is the same engine with a draft package (Qwen3_8DFlash2 derives from Qwen3_8MTP).
("qwen3_8mtp", "qwen3_8_mtp"): ("qwen3.8-mtp", "qwen3.8-dflash2"),
Expand Down
3 changes: 3 additions & 0 deletions .github/script/ci/devkit_symbol_clash.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
# engine. It starts empty. An HRX wait on this thread fills it and the
# completion check on that same thread reads it back.
"flm::npu::ert_failure_detail",
# The ELF section-name table of aie2p-launchlib's launch/txn/elf.hpp, a constant every
# engine that writes run ELFs (inkling2_npu, minicpm5_moe_npu) compiles from that one header.
"launch::txn::elf_of(launch::txn::ElfText const&)::kNames",
}
SKIPPED_LIBS = ("xrt", "boost")

Expand Down
9 changes: 6 additions & 3 deletions .github/script/ci/test_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,7 @@ def test_engine_library_maps_to_its_family(self):
"src/lib/xrt/libqwen3vl_flash.so": {"qwen3vl-flash"},
"src/lib/hrx/libhy_mem_npu.so": {"hy-memory"},
"src/lib/xrt/inkling2_npu.dll": {"inkling-2", "inkling-2-dflash2"},
"src/lib/hrx/libminicpm5_moe_npu.so": {"minicpm5"},
}
for path, expected in cases.items():
with self.subTest(path=path):
Expand Down Expand Up @@ -1763,9 +1764,11 @@ def test_no_source_includes_an_excluded_file(self):
def test_only_known_units_reach_host_outside_host_mk(self):
# make bitstream parses each unit's Makefile and its makefiles/*.mk.
# These name host/ (or -Ihost) outside host.mk, and were checked: the
# Hy_* prefill_overlay regs and run.exe targets (no bitstream
# prerequisite), and vision_overlay, which XCLBIN_NO_BITSTREAM leaves out.
known = {"Hy_MT2_1.8B/prefill_overlay", "Hy_mem_30BA3B/prefill_overlay", "minicpm_ocr/vision_overlay"}
# Hy_* and MiniCPM5 prefill_overlay regs and run.exe targets (no
# bitstream prerequisite), and vision_overlay, which XCLBIN_NO_BITSTREAM
# leaves out.
known = {"Hy_MT2_1.8B/prefill_overlay", "Hy_mem_30BA3B/prefill_overlay", "MiniCPM5/prefill_overlay",
"minicpm_ocr/vision_overlay"}
seen = set()
for path in tracked(f"{XB}**/Makefile", f"{XB}**/*.mk"):
unit = path[len(XB):].rsplit("/", 1)[0].removesuffix("/makefiles")
Expand Down
2 changes: 2 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ docs_nav:
url: "/docs/benchmarks/hy-memory_results/"
- label: MiniCPM-V 4.7
url: "/docs/benchmarks/minicpm-v-4.7_results/"
- label: MiniCPM5
url: "/docs/benchmarks/minicpm5_results/"
- label: Nemotron Bolt
url: "/docs/benchmarks/nemotron3.5-bolt_results/"
- label: Nemotron Bolt DFlash
Expand Down
1 change: 1 addition & 0 deletions docs/docs/benchmarks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Browse detailed NPU benchmark results for each major model family supported by F
- [Hy-MT3](hy-mt3_results/) (FLM v1.0.14 or later)
- [Hy-Memory](hy-memory_results/)
- [MiniCPM-V 4.7](minicpm-v-4.7_results/)
- [MiniCPM5](minicpm5_results/) (FLM v1.0.15 or later)
- [Nemotron Bolt](nemotron3.5-bolt_results/)
- [Nemotron Bolt DFlash](nemotron3.5-bolt-dflash_results/)
- [Flash Models](flash_results/)
Expand Down
57 changes: 57 additions & 0 deletions docs/docs/benchmarks/minicpm5_results.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
layout: docs
title: MiniCPM5
parent: Benchmarks
nav_order: 24
---

## ⚡ Performance and Efficiency Benchmarks

This section reports the performance on NPU with FastFlowLM (FLM).

> **Note:**
> - Results are based on the FastFlowLM release that adds MiniCPM5-15B-A2.5B (v1.0.15).
> - Under FLM's default NPU power mode (Performance)
> - Decoding runs every layer (attention, router, the 16 routed experts and the shared expert) and the LM head on the NPU.
> - Newer versions may deliver improved performance.
---

### **Test System:**

AMD Ryzen™ AI MAX+ PRO 395 (Strix Halo) with 128 GB DRAM; performance is comparable to other Strix Halo and Strix Point systems.

---

### 🚀 Decoding Speed (TPS, or Tokens per Second, starting @ different context lengths)

| **Model** | **HW** | **1k** | **2k** | **4k** | **8k** | **16k** | **32k** |
|------------------|--------------------|--------:|--------:|--------:|--------:|---------:|---------:|
| **MiniCPM5-15B-A2.5B** | XDNA2 | 24.9 | 24.2 | 22.7 | 20.2 | 16.7 | 12.4 |

---

### 🚀 Prefill Speed (TPS, or Tokens per Second, with different prompt lengths)

| **Model** | **HW** | **1k** | **2k** | **4k** | **8k** | **16k** | **32k** |
|------------------|--------------------|--------:|--------:|--------:|--------:|---------:|---------:|
| **MiniCPM5-15B-A2.5B** | XDNA2 | 1032 | 1267 | 1331 | 1132 | 867 | 594 |

---

## 🎯 Accuracy

The FLM package quantizes the BF16 model to Q4_K throughout (Q8_0 LM head), using the importance matrix published by
bartowski. KL divergence of the next-token distribution against the BF16 model (100 windows of 512 tokens):

| **Weights** | **WikiText-2** | **Code** |
|-----------------------------------------------|---------------:|---------:|
| Official Q4_K_M GGUF (mixed Q4_K / Q6_K) | 0.053 | 0.032 |
| All Q4_K, no importance matrix | 0.189 | 0.095 |
| All Q4_K with the importance matrix (FLM) | 0.097 | 0.052 |

> **Note:**
> - The importance matrix halves the error of a plain all-Q4_K quantization; all-Q4_K keeps every layer on the
> fast Q4_K NPU kernels.
> - On the NPU (bf16 compute) the logits match a CPU run of the same Q4_K weights closely: KL 0.005 to 0.020 over
> short chat, multi-turn, math, code, tool-call and 2.7k-token document prompts.
31 changes: 31 additions & 0 deletions docs/docs/models/minicpm.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,34 @@ flm run minicpm-v-4.7-moe:35b-a3b
- Video and audio input are not supported. Speculative decoding (DSpark) is not used.

---

## 🧩 Model Card: [MiniCPM5-15B-A2.5B](https://huggingface.co/openbmb/MiniCPM5-15B-A2.5B)

- **Type:** Text-to-Text (Mixture of Experts: 15B parameters, about 2.5B active per token)
- **Think:** Toggleable (on by default, as in the model's chat template)
- **Tool Calling Support:** Yes
- **Prefix cache (server mode):** Yes (see [Prefix Cache (Prompt Reuse)](https://fastflowlm.com/docs/instructions/server/prefix_cache/))
- **Base Model:** [openbmb/MiniCPM5-15B-A2.5B](https://huggingface.co/openbmb/MiniCPM5-15B-A2.5B) (Apache-2.0)
- **Quantization:** Q4_K (Q8_0 LM head), with the importance matrix from [bartowski/MiniCPM5-15B-A2.5B-GGUF](https://huggingface.co/bartowski/MiniCPM5-15B-A2.5B-GGUF)
- **Memory:** about 16 GB at the default 128k context, up to about 21.5 GB while it holds a full 128k prompt
- **Max Context Length:** 128k tokens
- **Default Context Length:** 128k tokens ([change default](https://fastflowlm.com/docs/instructions/cli/#-change-default-context-length-max))
- **[Set Context Length at Launch](https://fastflowlm.com/docs/instructions/cli/#-set-context-length-at-launch)**
- **Minimum FLM version:** v1.0.15 (first release that supports this model)

▶️ Run with FastFlowLM in PowerShell:

```powershell
flm run minicpm5:15b-a2.5b
```

📝 **Note**

- **Requires FastFlowLM v1.0.15 or later.**
- Thinking is on unless you turn it off: `think: false` in a request, `"chat_template_kwargs": {"enable_thinking": false}` (OpenAI API), or the interactive toggle.
- Sampling follows the model card's thinking-mode settings: temperature 1.0, top_p 0.95, min_p 0 (top_k 50).
- Tool calls use the model's own XML format (`<function name="..."><param name="...">...</param></function>`); the server returns them as OpenAI `tool_calls`.
- Text only. Speculative decoding is not used.
- Speeds: see [MiniCPM5 benchmarks](https://fastflowlm.com/docs/benchmarks/minicpm5_results/).

---
3 changes: 2 additions & 1 deletion docs/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sections:
FastFlowLM curates the most requested families and publishes tuned manifests under `flm pull <model>`.
We validate every build on Ryzen™ AI laptops and provide matching cards—see them [here](/docs/models/).
The catalog already covers models spanning Qwen3.8 (27B, MTP and DFlash 2 speculative decoding), Qwen3.6 (MoE), Qwen3.5 (Vision), Gemma4 (omni), Nemotron Bolt (DFlash speculative decoding), Qwen3, GPT-OSS-20B (MoE), DeepSeek-R1, Whisper
(Audio), Hy-MT2, Hy-MT3 (Translation), MiniCPM-V 4.7 (Vision, 1B and 35B-A3B MoE), MedGemma (Medical), Inkling-2 (Vision, 26B-A3B MoE, DFlash 2 speculative decoding), Decision 3.0 (d3-edge, d3-lite, d3-nano, d3-mini, d3-flash, d3-turbo, d3-ultra, the System One
(Audio), Hy-MT2, Hy-MT3 (Translation), MiniCPM-V 4.7 (Vision, 1B and 35B-A3B MoE), MiniCPM5 (15B-A2.5B MoE, tool use), MedGemma (Medical), Inkling-2 (Vision, 26B-A3B MoE, DFlash 2 speculative decoding), Decision 3.0 (d3-edge, d3-lite, d3-nano, d3-mini, d3-flash, d3-turbo, d3-ultra, the System One
decision model of vLLM Semantic Router), and other leading open families.
ctas:
- label: "View model docs"
Expand All @@ -30,6 +30,7 @@ sections:
- "Qwen3.5 (Vision)"
- "Qwen 3 (Vision)"
- "MiniCPM-V 4.7 (Vision, incl. 35B-A3B MoE)"
- "MiniCPM5 (MoE, tool use)"
- "Inkling-2 (Vision, MoE, tool use; DFlash 2 speculative decoding)"
- "GPT-OSS (MoE)"
- "LFM2 / LFM3 (Liquid AI)"
Expand Down
28 changes: 28 additions & 0 deletions flm-dev-kit/FLM_DLL/build_minicpm5_moe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/bash
# Copyright © Advanced Micro Devices, Inc., or its affiliates. All rights reserved.
# Portions of this file consist of AI-generated content.

# MiniCPM5-15B-A2.5B. Every stage runs on its own xclbin, so no host compute
# modules (mha / gemm / dequant / lm_head) are linked; q4nx is the weight reader.
cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" || exit 1
failed_dirs=()
target_dirs=(q4nx minicpm5_moe_npu)

for name in "${target_dirs[@]}"; do
dir="detail/${name}"
if [ -f "${dir}/Makefile" ]; then
if ! (cd "$dir" && make clean && make -j4); then
failed_dirs+=("$dir")
fi
fi
done

if [ ${#failed_dirs[@]} -ne 0 ]; then
echo "Build failures in:"
for dir in "${failed_dirs[@]}"; do
echo " - $dir"
done
exit 1
else
echo "All builds succeeded."
fi
177 changes: 177 additions & 0 deletions flm-dev-kit/FLM_DLL/detail/minicpm5_moe_npu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Copyright © Advanced Micro Devices, Inc., or its affiliates. All rights reserved.
# Portions of this file consist of AI-generated content.

cmake_minimum_required(VERSION 3.22)
project(minicpm5_moe_npu VERSION 1.0.0 LANGUAGES CXX)

# Set build type to Release
set(CMAKE_BUILD_TYPE Release)

# Set C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find and enable OpenMP for multi-threading
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
message(STATUS "OpenMP found - enabling multi-threading support")
else()
message(WARNING "OpenMP not found - optimized functions will run single-threaded")
endif()

# Force x64 architecture on Windows
if(WIN32)
set(CMAKE_GENERATOR_PLATFORM x64)
set(CMAKE_VS_PLATFORM_NAME "x64")
endif()

# Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/../../build/minicpm5_moe_npu/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/../../build/minicpm5_moe_npu/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/../../build/minicpm5_moe_npu/lib)

# Force output directories to be absolute
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})

# ———————————————————————————————————————————————
# User-tweakable XRT settings (override on cmake command-line)
# ———————————————————————————————————————————————
option(FLM_USE_HRX "Build FLM engine libs against the HRX amdxdna runtime instead of XRT" OFF)
if(FLM_USE_HRX)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/flm_hrx.cmake)
# Stale CMake cache can leak XRT headers into an HRX reconfigure.
set(XRT_INCLUDE_DIR "" CACHE PATH "Where XRT headers live" FORCE)
set(XRT_LIB_DIR "" CACHE PATH "Where XRT libs live" FORCE)
set(FLM_NPU_CORE_LIB ${HRX_LIBRARIES})
set(FLM_NPU_AIEBU_LIB "")
else()
include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/flm_xrt_win.cmake)
set(HRX_INCLUDE_DIRS "")
set(FLM_NPU_CORE_LIB xrt_coreutil)
set(FLM_NPU_AIEBU_LIB aiebu_static)
endif()

# ———————————————————————————————————————————————
# Gather your sources
# ———————————————————————————————————————————————
file(GLOB SOURCES
"*.cpp"
)
file(GLOB HEADERS "../../include/*.hpp" "*.hpp")


# ———————————————————————————————————————————————
# Define the library
# ———————————————————————————————————————————————
add_library(minicpm5_moe_npu SHARED ${SOURCES} ${HEADERS})



# HRX uses the dynamic CRT, the same one as flm and hrx. std::codecvt::id
# then stays in msvcp140.dll, so WINDOWS_EXPORT_ALL_SYMBOLS does not publish it.
# The XRT build links aiebu_static (/MT) and keeps the static CRT.
if(MSVC)
if(FLM_USE_HRX)
set_property(TARGET minicpm5_moe_npu PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
target_compile_options(minicpm5_moe_npu PRIVATE $<$<CONFIG:Debug>:/MDd>$<$<NOT:$<CONFIG:Debug>>:/MD>)
else()
set_property(TARGET minicpm5_moe_npu PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_compile_options(minicpm5_moe_npu PRIVATE /MT$<$<CONFIG:Debug>:d>)
endif()
endif()


set_target_properties(minicpm5_moe_npu PROPERTIES
PREFIX ""
SUFFIX ".dll"
IMPORT_PREFIX ""
IMPORT_SUFFIX ".lib"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/../../build/minicpm5_moe_npu/lib"
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/../../build/minicpm5_moe_npu/lib"
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/../../build/minicpm5_moe_npu/lib"
WINDOWS_EXPORT_ALL_SYMBOLS ON
)

# ———————————————————————————————————————————————
# Library specific settings
# ———————————————————————————————————————————————
target_include_directories(minicpm5_moe_npu PUBLIC
${CMAKE_SOURCE_DIR}/../../include
${CMAKE_SOURCE_DIR}/../../../aie2p-launchlib/launchlib/include
${XRT_INCLUDE_DIR} ${HRX_INCLUDE_DIRS} ${FLM_BOOST_INCLUDE_DIR}
)

# Prefill backend, same default as the Makefile: OFF = batched prefill (NPU
# prefill_overlay), ON = the decode overlays one token at a time. See minicpm5_moe_prefill.hpp.
option(PREFILL_WITH_MV "minicpm5_moe: token-by-token (decode-overlay) prefill" OFF)
if(PREFILL_WITH_MV)
target_compile_definitions(minicpm5_moe_npu PUBLIC PREFILL_WITH_MV)
endif()

# Add AVX2 specific definitions and flags
target_compile_definitions(minicpm5_moe_npu PUBLIC
DISABLE_ABI_CHECK=1
USEAVX2=1
USEAVX512=1
_WIN32
__WINDOWS__
_ENABLE_EXTENDED_ALIGNED_STORAGE
)

# Enhanced compiler options for AVX-512
target_compile_options(minicpm5_moe_npu PUBLIC
$<$<BOOL:${MSVC}>:/arch:AVX512 /O2 /fp:fast>
$<$<NOT:$<BOOL:${MSVC}>>:-mavx512f -mavx512vl -mavx512bw -mavx512dq -mfma -O3>
)

# Add OpenMP compiler flags if available
if(OpenMP_CXX_FOUND)
target_compile_options(minicpm5_moe_npu PUBLIC
$<$<BOOL:${MSVC}>:/openmp>
$<$<NOT:$<BOOL:${MSVC}>>:-fopenmp>
)
endif()

# Link OpenMP if available
if(OpenMP_CXX_FOUND)
target_link_libraries(minicpm5_moe_npu PUBLIC OpenMP::OpenMP_CXX)
endif()

# Add AVX2 specific link flags for MSVC
if(MSVC)
set_target_properties(minicpm5_moe_npu PROPERTIES
LINK_FLAGS "/MACHINE:X64"
)
# Add C++ standard library for RTTI and other symbols
target_link_libraries(minicpm5_moe_npu PUBLIC
$<$<BOOL:${MSVC}>:msvcrt.lib>
)
endif()

target_link_directories(minicpm5_moe_npu PUBLIC
${XRT_LIB_DIR}
${FLM_AIEBU_LIB_DIR}
)

# No host compute modules (gemm / mha / dequant). q4_npu_eXpress is still needed:
# SafeTensors::load_weights lives in q4nx/safe_tensors.cpp, and a DLL must resolve
# it at link time (the Linux .so picks it up from libq4_npu_eXpress.so at load time)
set(Q4NPU_EXPRESS_LIB_PATH ${CMAKE_SOURCE_DIR}/../../build/lib/q4_npu_eXpress.lib)
target_link_libraries(minicpm5_moe_npu PUBLIC
${FLM_NPU_CORE_LIB}
${FLM_NPU_AIEBU_LIB}
${Q4NPU_EXPRESS_LIB_PATH}
)

# Copy the built library to build/lib directory
add_custom_command(TARGET minicpm5_moe_npu POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/../../build/lib
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:minicpm5_moe_npu>
${CMAKE_SOURCE_DIR}/../../build/lib/minicpm5_moe_npu.dll
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_IMPORT_FILE:minicpm5_moe_npu>
${CMAKE_SOURCE_DIR}/../../build/lib/minicpm5_moe_npu.lib
)
Loading
Loading