15B Weights in ~3GB Phone RAM and CMO Gold? MiniCPM5-15B-A2.5B Deep Dive: Native Prefetch-Routing, MLX/LiteRT Pitfalls & 3-OS Auto-Fix Scripts
Let's open with an honest Day-1 reality check: released by OpenBMB under Apache 2.0 in December 2026, MiniCPM5-15B-A2.5B has one of the sharpest gaps between headline efficiency and Day-1 setup traps in the local-LLM ecosystem. On paper, the numbers look unreal for a 15B sparse MoE activating only 2.5B parameters per token: an official 123 / 126 gold-medal certification at CMO 2026, 32 on an IMO 2026 self-eval (clearing the 29-point gold cutoff), a 64.4 average across 36 benchmarks (beating models twice its size such as Qwen3.6-35B-A3B at 59.9), and even 30 tok/s in ~3.1 GB peak app memory on an iPhone 18 Pro Max (up to 52 tok/s unconstrained).
Yet the moment developers pull weights onto a laptop or workstation, four counterintuitive failures pop up almost immediately: stock Ollama crashes with unknown model architecture: 'minicpm5_moe'; Apple Silicon users instinctively install mlx-lm only to find it cannot load the model; 16GB laptop owners expecting "3GB magic" either hit severe page-thrashing on LiteRT int8 (15.08 GB) or watch accuracy collapse on LiteRT int4 (NLL spiking to 4.848); and disabling thinking mode without the right penalties traps llama-server in endless repetition loops.
Cross-checking openbmb/MiniCPM5-15B-A2.5B's config.json against OpenBMB's official deployment cookbooks (llama_cpp.md, ollama.md, mlx.md, litert.md, minicpm5_on_ios.md, and tool_usage.md) explains every single quirk. Below is the plain-English breakdown with 12 real screenshots and Huashu-Design diagrams, grade-school analogies, and zero-dependency Windows 11 / Ubuntu 26.04 / macOS 27 diagnostic and setup scripts.

Figure 1: Original panoramic overview summarizing MiniCPM5-15B-A2.5B's core footprint (15B total / 2.5B active, CMO 123/126 gold, 52 tok/s prefetch-routing, 524,288 context) and four Day-1 traps.
1. Background: Why This Sub-20B Sparse MoE Punching Bag Beats 30B Rivals
Built by OpenBMB (jointly initiated by Tsinghua NLP Lab and ModelBest), MiniCPM5-15B-A2.5B targets fully local, privacy-preserving on-device agents under a permissive Apache 2.0 license.

Figure 2: Authentic screenshot of huggingface.co/openbmb/MiniCPM5-15B-A2.5B showing the minicpm5_moe tag, Apache 2.0 license, and 34 linked quantization builds.
Across OpenBMB's 36-benchmark comparison table, the model achieves remarkable capability density rather than cherry-picking one metric:
- Olympiad-Grade Math: Official 123 / 126 CMO 2026 gold certification, 32 on IMO 2026 self-eval, 97.3 on AIME 2025, 95.8 on AIME 2026, and 64.1 on
IMO-ProofBench(more than double Qwen3.6-35B-A3B's 28.0); - Coding & Autonomous Agents: Hits 68.4 on
SWE-Bench Verified, 52.2 onSWE-Bench Pro Verified(leading even 30B dense baselines), 50.2 onTerminal-Bench v2.1, 26.2 onAutomationBench v1.0.6(over 3x Qwen3.6-35B-A3B's 8.3), and 73.2 onClaw-Gym; - Honest Weaknesses: On
LongBench v2 128K, it scores 51.1 behindQwen3.6-35B-A3B(59.4), and onIFBenchit scores 64.3 versusGemma-4-26B-A4B-it(83.7)—real tradeoffs of compact active capacity.

Figure 3: Authentic crop of the official 36-benchmark table from the Hugging Face model card. Average 64.4 beats Qwen3.6-35B-A3B (59.9) and Qwen3.5-27B (63.2), while transparently trailing on 128K long-context synthesis and strict instruction formatting.

Figure 4: Authentic screenshot of github.com/OpenBMB/MiniCPM housing deployment cookbooks, fine-tuning recipes, Agent Skills, and eval/imo-harness.
2. Symptoms: The Four Day-1 Local Deployment Traps
- Trap 1 · Every Runtime Says "Unknown Architecture"
Stock Ollama (≤ 0.40.19) fails witherror loading model: unknown model architecture: 'minicpm5_moe'. Apple Silicon developers runningmlx-lmhit immediate errors even though the model is text-only, and oldertransformersversions fail to recognizeminicpm5_moe. - Trap 2 · The "3GB RAM Myth" & LiteRT
int4Accuracy Collapse
Desktop users expecting ~3 GB RAM usage pull standardQ4_K_M.gguf(8.49 GiB) or LiteRTint8(15.08 GB) onto 16GB laptops and hit severe page-thrashing—or grab LiteRTint4(7.58 GB) and watch Mean NLL collapse from 1.414 to 4.269–4.848. - Trap 3 · Non-Thinking Repetition Loops & Slow DSpark Drafting
Runningllama-serverwith defaultmin_p=0.05or disabling thinking withoutpresence_penalty=1.5causes infinite sentence loops. Meanwhile, cranking DSpark speculative drafting to 7 tokens on quantized base weights lowers acceptance and drags throughput down. - Trap 4 · Agent Harness HTTP 400s & Raw XML Leaks
Multi-turn Anthropic/v1/messagescalls fail with400: text content blocks must be non-empty, Codex multi-instance routers throwHTTP 400: unknown variant 'namespace', and truncated thinking budgets leak raw<function ...>XML straight into assistant text.

Figure 5: Authentic screenshot of huggingface.co/openbmb/MiniCPM5-15B-A2.5B-GGUF showing desktop GGUF sizes (BF16 27.97 GiB, Q8_0 14.87 GiB, Q4_K_M 8.49 GiB), distinct from phone-targeted LCO-GGUF builds.
3. How It Works (Grade-School Analogies + Exact config.json Blueprint)
Picture a 28-floor specialty clinic, a flash-storage bookshelf with a prefetch aide, and two shared pocket notebooks.

Figure 6: Original everyday analogy diagram showing how native prefetch-routing overlaps flash I/O with active 2.5B compute.
- Layer 0 Front Desk + Layers 1–27 (16 of 160 Specialists + 1 Shared Lead): Layer 0 is a dense 8,192-dim MLP normalizing every token. Layers 1–27 hold 160 routed experts (dim 512 each) plus 1 shared expert, activating only 16 routed + 1 shared (~2.5B parameters) per token with
routed_scaling_factor = 3.66. - LES 1.0 Native Prefetch-Routing (+11% Prediction Accuracy): Instead of stalling while hunting for next-layer experts on flash storage, MiniCPM5 was trained with native prefetch-routing so a lightweight predictor pulls the next layer's experts off flash while the current layer computes—enabling iPhone 18 Pro Max to run
Q3_gud-LCO-GGUFviallama.cpp-omniin 3.1 GB peak RAM at ~30 tok/s. - 32Q : 2KV Gated GQA (524,288 Context): 32 query heads share just 2 key-value heads (
head_dim=128,use_gated_attention=true,rope_theta=5,000,000), cutting KV cache memory drastically so context scales cleanly up to 512K tokens. - JustRL-II + 22-Teacher MOPD: Post-training trained 22 domain RL teachers via JustRL-II and merged them via Multi-Teacher On-Policy Distillation (reverse KL per token), boosting Agent benchmarks by +7.85 points over SFT.

Figure 7: Exact 28-layer MiniCPM5MoEForCausalLM topology verified against Hugging Face config.json.
4. Root Causes & Quantization Matrix
- Root Cause 1 (Runtime Lag & MLX-VLM Split): Desktop
llama.cpprequires PR #32644 (commite18d1b21, buildb12847+); stock Ollama (≤ 0.40.19) lacks it. Transformers requires>= 5.25.0; vLLM needs PRs#69127/#69128; SGLang needs PRs#52071/#52072. On Apple Silicon, MiniCPM5's loader and DSpark live inmlx-vlm@main(PR #2866 & #2870)—nevermlx-lm. - Root Cause 2 (Flash Prefetch vs Desktop Full-Map & LiteRT
int4Cliff): Desktop engines map full weights into RAM/VRAM. On 16GB machines,LiteRT int8(15.08 GB) page-thrashes to near-zero speed, whileLiteRT int4(7.58 GB) degrades Mean NLL to 4.269–4.848 (vs 1.414 Float32). UseLiteRT mixed(8.28 GB, NLL 1.473–1.628, 45.5 tok/s on M5 Metal GPU—never Mac CPU, which hits a slow kernel path!). - Root Cause 3 (
min_p=0.05& Quantized DSpark Greed): Always pass--min-p 0inllama.cppso low-probability escape tokens aren't pruned; in non-thinking mode settemperature=0.7, top_p=0.80, top_k=20, presence_penalty=1.5; and cap quantized DSpark at--spec-draft-n-max 2. - Root Cause 4 (Protocol Sanitization): Strip whitespace-only
textblocks between</think>and<function>when echoing Anthropic turns; upgradesglang-routertosmg >= 1.15.0for Codexnamespace; pre-parse JSON stringtool_call.argumentsbefore Jinjaapply_chat_template(); and setmax_tokens >= 16384for coding agents.

Figure 8: Authentic screenshot of OpenBMB's litert.md documenting mixed vs int8 vs int4 accuracy and 16GB memory limits.

Figure 9: Authentic screenshot of minicpm5_on_ios.md verifying 3.1 GB peak app memory at ~30 tok/s in Memory saver mode and ~52 tok/s in Fastest mode.

Figure 10: Original format & hardware selection matrix across 16GB laptops, 24GB desktops, 32GB+ workstations, and iPhones.

Figure 11: Original Agent protocol pipeline covering dual server parsers (minicpm5 + qwen3), thinking retention for Prefix KV Cache hits, and HTTP 400 fixes.
5. Solutions: 3-OS Zero-Dependency Scripts (Manual & Agent Automation)

Figure 12: Original Day-1 troubleshooting matrix mapping symptom to root cause and verified command fix.
5.1 Method 1: Manual Execution & 3-OS Toolkits
Use the zero-dependency scripts below on Windows 11, Ubuntu 26.04, or macOS 27 to audit RAM/VRAM/disk, catch mlx-lm / Ollama KV bloat / stale URL traps, and generate safe launchers under ~/.minicpm5-local.
1. Windows 11 (Native PowerShell: minicpm5_local_toolkit_windows11.ps1)
# ==============================================================================
# MiniCPM5-15B-A2.5B Local Diagnostic, Backend Guard & Auto-Config — Windows 11
# Zero third-party dependencies (native PowerShell 5.1 / 7+ only)
# Privacy Guard: Never emits hostnames, full non-loopback IPs, or raw API keys.
#
# Modes:
# Human Interactive: powershell -ExecutionPolicy Bypass -File .\minicpm5_local_toolkit_windows11.ps1
# Agent Automated: powershell -ExecutionPolicy Bypass -File .\minicpm5_local_toolkit_windows11.ps1 -Auto -Json -Apply -ScaffoldAgent -Target .
# ==============================================================================
[CmdletBinding()]
param(
[switch]$Auto,
[switch]$Json,
[ValidateSet("thinking", "fast")][string]$Mode = "thinking",
[switch]$Apply,
[switch]$ApplyOllama,
[switch]$ScaffoldAgent,
[string]$Target = "."
)
$ErrorActionPreference = "Stop"
# 1. Hardware & Storage Detection (Sanitized — no hostname or raw IP)
$cs = Get-CimInstance -ClassName Win32_ComputerSystem
$totalRamGB = [math]::Round($cs.TotalPhysicalMemory / 1GB, 1)
$gpuName = "none"
$vramGB = 0.0
$nvidiaSmi = Get-Command nvidia-smi -ErrorAction SilentlyContinue
if ($nvidiaSmi) {
try {
$smiOut = (& nvidia-smi --query-gpu=name,memory.total --format=csv,noheader,nounits 2>$null | Select-Object -First 1)
if ($smiOut) {
$parts = $smiOut -split ","
$gpuName = $parts[0].Trim()
$vramGB = [math]::Round(([double]$parts[1].Trim()) / 1024, 1)
}
} catch {}
}
if ($vramGB -eq 0) {
$vc = Get-CimInstance -ClassName Win32_VideoController | Sort-Object AdapterRAM -Descending | Select-Object -First 1
if ($vc) {
$gpuName = $vc.Name
if ($vc.AdapterRAM -gt 0) {
$vramGB = [math]::Round($vc.AdapterRAM / 1GB, 1)
}
}
}
$targetResolved = (Resolve-Path -Path $Target -ErrorAction SilentlyContinue)
if (-not $targetResolved) { $targetResolved = Get-Location }
$driveLetter = ($targetResolved.Path.Substring(0, 1))
$psDrive = Get-PSDrive -Name $driveLetter -ErrorAction SilentlyContinue
$freeDiskGB = if ($psDrive) { [math]::Round($psDrive.Free / 1GB, 1) } else { 0.0 }
$effectiveBudgetGB = if ($vramGB -ge 12) { $vramGB } else { [math]::Round($totalRamGB * 0.75 + $vramGB, 1) }
if ($effectiveBudgetGB -ge 32) {
$tier = "Tier-A (32GB+)"
$recGguf = "MiniCPM5-15B-A2.5B-BF16.gguf (27.97 GiB) or Q8_0"
$recLitert = "MiniCPM5-15B-A2.5B_int8.litertlm (15.08 GB) or _mixed"
$downloadGB = 27.97
} elseif ($effectiveBudgetGB -ge 22) {
$tier = "Tier-B (24GB)"
$recGguf = "MiniCPM5-15B-A2.5B-Q8_0.gguf (14.87 GiB)"
$recLitert = "MiniCPM5-15B-A2.5B_mixed.litertlm (8.28 GB)"
$downloadGB = 14.87
} elseif ($effectiveBudgetGB -ge 15) {
$tier = "Tier-C (16GB)"
$recGguf = "MiniCPM5-15B-A2.5B-Q4_K_M.gguf (8.49 GiB)"
$recLitert = "MiniCPM5-15B-A2.5B_mixed.litertlm (8.28 GB; NEVER int8 or int4)"
$downloadGB = 8.49
} else {
$tier = "Tier-D (<16GB Tight)"
$recGguf = "MiniCPM5-15B-A2.5B-Q4_K_M.gguf (tight; offload fewer layers or try MiniCPM5-2B)"
$recLitert = "MiniCPM5-15B-A2.5B_mixed.litertlm (tight)"
$downloadGB = 8.49
}
$diskSpaceWarning = ($freeDiskGB -lt 25.0)
# 2. Local Runtime & Day-1 Trap Scan
$llamaServerCmd = Get-Command llama-server -ErrorAction SilentlyContinue
$ollamaCmd = Get-Command ollama -ErrorAction SilentlyContinue
$litertCmd = Get-Command litert-lm -ErrorAction SilentlyContinue
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
$transformersOk = $false
if ($pythonCmd) {
try {
& python -c "import transformers, packaging.version as v; exit(0 if v.parse(transformers.__version__) >= v.parse('5.25.0') else 1)" 2>$null
if ($LASTEXITCODE -eq 0) { $transformersOk = $true }
} catch {}
}
$ollamaFlashAttn = [Environment]::GetEnvironmentVariable("OLLAMA_FLASH_ATTENTION", "User")
if (-not $ollamaFlashAttn) { $ollamaFlashAttn = $env:OLLAMA_FLASH_ATTENTION }
$ollamaKvType = [Environment]::GetEnvironmentVariable("OLLAMA_KV_CACHE_TYPE", "User")
if (-not $ollamaKvType) { $ollamaKvType = $env:OLLAMA_KV_CACHE_TYPE }
$ollamaKvBloatTrap = ($null -ne $ollamaCmd) -and (($ollamaFlashAttn -ne "1") -or ([string]::IsNullOrWhiteSpace($ollamaKvType)))
$staleBaseUrlTrap = (-not [string]::IsNullOrWhiteSpace($env:OPENAI_BASE_URL)) -and ($env:OPENAI_BASE_URL -notmatch "localhost") -and ($env:OPENAI_BASE_URL -notmatch "127\.0\.0\.1")
# 3. Interactive Human Prompt if not -Auto
if (-not $Auto) {
Write-Host "=== MiniCPM5-15B-A2.5B Windows 11 Local Triage ===" -ForegroundColor Cyan
Write-Host "Hardware Tier: $tier | RAM: $totalRamGB GB | VRAM: $vramGB GB ($gpuName)"
Write-Host "GGUF Pick: $recGguf"
Write-Host "LiteRT-LM: $recLitert"
if (-not $Apply) {
$ansApply = Read-Host "Generate local MiniCPM5 launchers & presets under ~\.minicpm5-local? [Y/n]"
if ($ansApply -eq "" -or $ansApply -match "^[Yy]") { $Apply = $true }
}
if ($ollamaCmd -and -not $ApplyOllama) {
$ansOllama = Read-Host "Persist Ollama FlashAttention + q8_0 KV cache env vars? [y/N]"
if ($ansOllama -match "^[Yy]") { $ApplyOllama = $true }
}
if (-not $ScaffoldAgent) {
$ansAgent = Read-Host "Scaffold local MiniCPM5 agent profile in Target directory? [y/N]"
if ($ansAgent -match "^[Yy]") { $ScaffoldAgent = $true }
}
}
# 4. Apply Launchers & Sampling Presets Safely
$cpmDir = Join-Path $HOME ".minicpm5-local"
$launcherCreated = $false
$presetsCreated = $false
$ollamaEnvApplied = $false
$agentScaffolded = $false
$backupFile = "none"
if ($Apply) {
if (-not (Test-Path $cpmDir)) { New-Item -ItemType Directory -Path $cpmDir -Force | Out-Null }
$thinkingScript = @'
# Auto-generated MiniCPM5-15B-A2.5B Thinking Launcher (anti-loop --min-p 0)
param([string]$GgufPath = "$HOME\models\MiniCPM5-15B-A2.5B-Q4_K_M.gguf")
$ErrorActionPreference = "Stop"
llama-server -m $GgufPath -a MiniCPM5-15B-A2.5B `
--host localhost --port 8080 -ngl 99 -fa on -c 8192 --jinja `
--temp 1.0 --top-p 0.95 --min-p 0.0 --repeat-penalty 1.0
'@
$fastScript = @'
# Auto-generated MiniCPM5-15B-A2.5B Non-Thinking Fast Launcher (presence_penalty=1.5)
param([string]$GgufPath = "$HOME\models\MiniCPM5-15B-A2.5B-Q4_K_M.gguf")
$ErrorActionPreference = "Stop"
llama-server -m $GgufPath -a MiniCPM5-15B-A2.5B `
--host localhost --port 8080 -ngl 99 -fa on -c 8192 --jinja `
--temp 0.7 --top-p 0.80 --top-k 20 --min-p 0.0 --presence-penalty 1.5 --repeat-penalty 1.0
'@
$thinkPath = Join-Path $cpmDir "launch-minicpm5-thinking.ps1"
$fastPath = Join-Path $cpmDir "launch-minicpm5-fast.ps1"
if (Test-Path $thinkPath) {
$backupFile = "$thinkPath.bak.$(Get-Date -Format 'yyyyMMddHHmmss')"
Copy-Item $thinkPath $backupFile -Force
}
Set-Content -Path $thinkPath -Value $thinkingScript -Encoding UTF8
Set-Content -Path $fastPath -Value $fastScript -Encoding UTF8
$launcherCreated = $true
$presetsJson = @{
model = "MiniCPM5-15B-A2.5B"
thinking_general = @{ temperature = 1.0; top_p = 0.95; min_p = 0.0; repetition_penalty_if_loop = 1.05 }
non_thinking_general = @{ temperature = 0.7; top_p = 0.80; top_k = 20; min_p = 0.0; presence_penalty = 1.5; repetition_penalty = 1.0 }
dspark_quantized_safe = @{ spec_type = "draft-dspark"; spec_draft_n_max = 2; spec_draft_p_min = 0 }
agent_protocol_guards = @{
vllm_sglang_parsers = "--tool-call-parser minicpm5 --reasoning-parser qwen3"
coding_min_max_tokens = 16384
}
} | ConvertTo-Json -Depth 4
Set-Content -Path (Join-Path $cpmDir "sampling-presets.json") -Value $presetsJson -Encoding UTF8
$presetsCreated = $true
}
if ($ApplyOllama) {
[Environment]::SetEnvironmentVariable("OLLAMA_FLASH_ATTENTION", "1", "User")
[Environment]::SetEnvironmentVariable("OLLAMA_KV_CACHE_TYPE", "q8_0", "User")
$env:OLLAMA_FLASH_ATTENTION = "1"
$env:OLLAMA_KV_CACHE_TYPE = "q8_0"
$ollamaEnvApplied = $true
$ollamaKvBloatTrap = $false
}
if ($ScaffoldAgent) {
$agentDir = Join-Path $targetResolved.Path ".claude\agents"
if (-not (Test-Path $agentDir)) { New-Item -ItemType Directory -Path $agentDir -Force | Out-Null }
$agentProfile = @"
---
name: minicpm5-local-worker
description: Local MiniCPM5-15B-A2.5B Windows 11 execution & protocol guard profile
---
- Local endpoint: ``http://localhost:8080/v1``
- Requires llama.cpp build >= b12847 (PR #32644) for ``minicpm5_moe``.
- Always pass ``--min-p 0``; use ``presence_penalty=1.5`` when thinking is off.
- Set ``max_tokens >= 16384`` for coding tasks and preserve historical thinking blocks.
"@
Set-Content -Path (Join-Path $agentDir "minicpm5-local-worker.md") -Value $agentProfile -Encoding UTF8
$agentScaffolded = $true
}
# 5. Output
$result = [ordered]@{
os = "Windows 11"
ram_gb = $totalRamGB
gpu = $gpuName
vram_gb = $vramGB
free_disk_gb = $freeDiskGB
tier = $tier
recommended_gguf = $recGguf
recommended_litert = $recLitert
estimated_download_gb = $downloadGB
traps = [ordered]@{
disk_space_warning = $diskSpaceWarning
llama_server_found = ($null -ne $llamaServerCmd)
ollama_found = ($null -ne $ollamaCmd)
litert_lm_found = ($null -ne $litertCmd)
transformers_5_25_ready = $transformersOk
ollama_kv_bloat_trap = $ollamaKvBloatTrap
stale_base_url_trap = $staleBaseUrlTrap
}
actions = [ordered]@{
launcher_created = $launcherCreated
presets_created = $presetsCreated
ollama_env_applied = $ollamaEnvApplied
agent_scaffolded = $agentScaffolded
backup_file = $backupFile
}
}
if ($Json) {
$result | ConvertTo-Json -Depth 5
} else {
Write-Host ""
Write-Host "=== Summary & Next Steps ===" -ForegroundColor Green
Write-Host "Tier : $tier"
Write-Host "Launchers Dir : $cpmDir"
Write-Host "Remember : Always pass --min-p 0 to llama-server; never run LiteRT int4."
}
powershell -ExecutionPolicy Bypass -File .\minicpm5_local_toolkit_windows11.ps1
2. Ubuntu 26.04 (Native Bash: minicpm5_local_toolkit_ubuntu2604.sh)
#!/usr/bin/env bash
# ==============================================================================
# MiniCPM5-15B-A2.5B Local Diagnostic, Backend Guard & Auto-Config — Ubuntu 26.04
# Zero third-party dependencies (GNU bash, awk, grep, sed, free, df, tr)
# Privacy Guard: Never emits hostnames, full non-loopback IPs, or raw API keys.
#
# Modes:
# Human Interactive: bash ./minicpm5_local_toolkit_ubuntu2604.sh
# Agent Automated: bash ./minicpm5_local_toolkit_ubuntu2604.sh --auto --json --apply --scaffold-agent --target .
# ==============================================================================
set -euo pipefail
AUTO=0
JSON_MODE=0
APPLY=0
APPLY_OLLAMA=0
SCAFFOLD_AGENT=0
TARGET_DIR="."
while [[ $# -gt 0 ]]; do
case "$1" in
--auto) AUTO=1; shift ;;
--json) JSON_MODE=1; shift ;;
--apply) APPLY=1; shift ;;
--apply-ollama) APPLY_OLLAMA=1; shift ;;
--scaffold-agent) SCAFFOLD_AGENT=1; shift ;;
--target) TARGET_DIR="${2:-.}"; shift 2 ;;
-h|--help)
cat <<'EOF'
Usage: bash minicpm5_local_toolkit_ubuntu2604.sh [options]
--auto Non-interactive mode for AI Agents
--json Emit sanitized JSON output
--apply Generate ~/.minicpm5-local launchers & sampling presets
--apply-ollama Write ~/.minicpm5-local/ollama-override.conf for systemd
--scaffold-agent Write .claude/agents/minicpm5-local-worker.md in --target
--target <dir> Target workspace directory (default: .)
EOF
exit 0
;;
*) echo "Unknown option: $1" >&2; exit 1 ;;
esac
done
# 1. Hardware & Disk Detection (Sanitized)
RAM_KB="$(awk '/MemTotal:/ {print $2}' /proc/meminfo 2>/dev/null || echo 0)"
RAM_GB="$(awk -v k="${RAM_KB:-0}" 'BEGIN {printf "%.1f", k/1024/1024}')"
GPU_NAME="none"
VRAM_GB="0.0"
if command -v nvidia-smi >/dev/null 2>&1; then
SMI_LINE="$(nvidia-smi --query-gpu=name,memory.total --format=csv,noheader,nounits 2>/dev/null | head -n 1 || true)"
if [[ -n "$SMI_LINE" ]]; then
GPU_NAME="$(echo "$SMI_LINE" | awk -F',' '{gsub(/^[ \t]+|[ \t]+$/, "", $1); print $1}')"
VRAM_MB="$(echo "$SMI_LINE" | awk -F',' '{gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}')"
VRAM_GB="$(awk -v m="${VRAM_MB:-0}" 'BEGIN {printf "%.1f", m/1024}')"
fi
fi
mkdir -p "$TARGET_DIR" 2>/dev/null || true
FREE_DISK_KB="$(df -Pk "$TARGET_DIR" | awk 'NR==2 {print $4}')"
FREE_DISK_GB="$(awk -v k="${FREE_DISK_KB:-0}" 'BEGIN {printf "%.1f", k/1024/1024}')"
BUDGET_GB="$(awk -v v="$VRAM_GB" -v r="$RAM_GB" 'BEGIN {if (v >= 12) printf "%.1f", v; else printf "%.1f", r*0.75 + v}')"
TIER="Tier-D (<16GB Tight)"
REC_GGUF="MiniCPM5-15B-A2.5B-Q4_K_M.gguf (tight; offload partial layers or use MiniCPM5-2B)"
REC_VLLM="GPTQ 4-bit (cap --max-model-len 32768)"
REC_LITERT="MiniCPM5-15B-A2.5B_mixed.litertlm (8.28 GB)"
DL_GB="8.49"
if awk -v b="$BUDGET_GB" 'BEGIN {exit !(b >= 32)}'; then
TIER="Tier-A (32GB+)"
REC_GGUF="MiniCPM5-15B-A2.5B-BF16.gguf (27.97 GiB) or Q8_0"
REC_VLLM="openbmb/MiniCPM5-15B-A2.5B (BF16 + DSpark)"
REC_LITERT="MiniCPM5-15B-A2.5B_int8.litertlm (15.08 GB) or _mixed"
DL_GB="27.97"
elif awk -v b="$BUDGET_GB" 'BEGIN {exit !(b >= 22)}'; then
TIER="Tier-B (24GB)"
REC_GGUF="MiniCPM5-15B-A2.5B-Q8_0.gguf (14.87 GiB)"
REC_VLLM="openbmb/MiniCPM5-15B-A2.5B-GPTQ (4-bit + DSpark)"
REC_LITERT="MiniCPM5-15B-A2.5B_mixed.litertlm (8.28 GB)"
DL_GB="14.87"
elif awk -v b="$BUDGET_GB" 'BEGIN {exit !(b >= 15)}'; then
TIER="Tier-C (16GB)"
REC_GGUF="MiniCPM5-15B-A2.5B-Q4_K_M.gguf (8.49 GiB)"
REC_VLLM="openbmb/MiniCPM5-15B-A2.5B-GPTQ (cap --max-model-len 16384)"
REC_LITERT="MiniCPM5-15B-A2.5B_mixed.litertlm (8.28 GB; NEVER int8/int4)"
DL_GB="8.49"
fi
DISK_WARN="false"
if awk -v d="$FREE_DISK_GB" 'BEGIN {exit !(d < 25)}'; then
DISK_WARN="true"
fi
# 2. Local Runtime & Day-1 Trap Scan
LLAMA_FOUND="false"; command -v llama-server >/dev/null 2>&1 && LLAMA_FOUND="true"
OLLAMA_FOUND="false"; command -v ollama >/dev/null 2>&1 && OLLAMA_FOUND="true"
LITERT_FOUND="false"; command -v litert-lm >/dev/null 2>&1 && LITERT_FOUND="true"
TRANSFORMERS_OK="false"
if command -v python3 >/dev/null 2>&1; then
python3 -c "import transformers, packaging.version as v; exit(0 if v.parse(transformers.__version__) >= v.parse('5.25.0') else 1)" >/dev/null 2>&1 && TRANSFORMERS_OK="true"
fi
OLLAMA_KV_BLOAT_TRAP="false"
if [[ "$OLLAMA_FOUND" == "true" ]]; then
if [[ "${OLLAMA_FLASH_ATTENTION:-}" != "1" || -z "${OLLAMA_KV_CACHE_TYPE:-}" ]]; then
OLLAMA_KV_BLOAT_TRAP="true"
fi
fi
STALE_BASE_URL_TRAP="false"
if [[ -n "${OPENAI_BASE_URL:-}" && ! "${OPENAI_BASE_URL}" =~ localhost && ! "${OPENAI_BASE_URL}" =~ 127\.0\.0\.1 ]]; then
STALE_BASE_URL_TRAP="true"
fi
# 3. Interactive Human Prompt
if (( AUTO == 0 )); then
echo "=== MiniCPM5-15B-A2.5B Ubuntu 26.04 Local Triage ==="
echo "Hardware Tier: ${TIER} | RAM: ${RAM_GB} GB | VRAM: ${VRAM_GB} GB (${GPU_NAME})"
echo "GGUF Pick: ${REC_GGUF}"
echo "vLLM/SGLang: ${REC_VLLM}"
echo "LiteRT-LM: ${REC_LITERT}"
if (( APPLY == 0 )); then
read -r -p "Generate local MiniCPM5 launchers & presets in ~/.minicpm5-local? [Y/n] " ans_apply
if [[ -z "$ans_apply" || "$ans_apply" =~ ^[Yy]$ ]]; then APPLY=1; fi
fi
if [[ "$OLLAMA_FOUND" == "true" && $APPLY_OLLAMA -eq 0 ]]; then
read -r -p "Generate Ollama systemd override snippet (~/.minicpm5-local/ollama-override.conf)? [y/N] " ans_ol
if [[ "$ans_ol" =~ ^[Yy]$ ]]; then APPLY_OLLAMA=1; fi
fi
if (( SCAFFOLD_AGENT == 0 )); then
read -r -p "Scaffold local MiniCPM5 worker profile in target directory? [y/N] " ans_ag
if [[ "$ans_ag" =~ ^[Yy]$ ]]; then SCAFFOLD_AGENT=1; fi
fi
fi
# 4. Apply Configs Safely
CPM_DIR="${HOME}/.minicpm5-local"
LAUNCHER_CREATED="false"
PRESETS_CREATED="false"
OLLAMA_CONF_CREATED="false"
AGENT_SCAFFOLDED="false"
BACKUP_FILE="none"
if (( APPLY == 1 )); then
mkdir -p "$CPM_DIR"
THINK_SH="${CPM_DIR}/launch-minicpm5-thinking.sh"
FAST_SH="${CPM_DIR}/launch-minicpm5-fast.sh"
VLLM_SH="${CPM_DIR}/launch-minicpm5-vllm.sh"
MODELFILE_PATH="${CPM_DIR}/Modelfile.minicpm5-q4km"
if [[ -f "$THINK_SH" ]]; then
BACKUP_FILE="${THINK_SH}.bak.$(date +%Y%m%d%H%M%S)"
cp "$THINK_SH" "$BACKUP_FILE"
fi
cat > "$THINK_SH" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
GGUF_PATH="${1:-$HOME/models/MiniCPM5-15B-A2.5B-Q4_K_M.gguf}"
exec llama-server -m "$GGUF_PATH" -a MiniCPM5-15B-A2.5B \
--host localhost --port 8080 -ngl 99 -fa on -c 8192 --jinja \
--temp 1.0 --top-p 0.95 --min-p 0.0 --repeat-penalty 1.0
EOF
chmod +x "$THINK_SH"
cat > "$FAST_SH" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
GGUF_PATH="${1:-$HOME/models/MiniCPM5-15B-A2.5B-Q4_K_M.gguf}"
exec llama-server -m "$GGUF_PATH" -a MiniCPM5-15B-A2.5B \
--host localhost --port 8080 -ngl 99 -fa on -c 8192 --jinja \
--temp 0.7 --top-p 0.80 --top-k 20 --min-p 0.0 --presence-penalty 1.5 --repeat-penalty 1.0
EOF
chmod +x "$FAST_SH"
cat > "$VLLM_SH" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
MODEL_ID="${1:-openbmb/MiniCPM5-15B-A2.5B-GPTQ}"
exec vllm serve "$MODEL_ID" --served-model-name MiniCPM5-15B-A2.5B \
--host localhost --port 8000 --max-model-len 32768 \
--enable-auto-tool-choice --tool-call-parser minicpm5 --reasoning-parser qwen3
EOF
chmod +x "$VLLM_SH"
cat > "$MODELFILE_PATH" <<'EOF'
FROM ./MiniCPM5-15B-A2.5B-Q4_K_M.gguf
TEMPLATE """{{- if .Messages -}}
{{- range .Messages -}}
<|im_start|>{{ .Role }}
{{ .Content }}<|im_end|>
{{ end -}}
<|im_start|>assistant
{{ end -}}"""
PARAMETER stop "<|im_end|>"
PARAMETER stop "</s>"
PARAMETER temperature 1.0
PARAMETER top_p 0.95
PARAMETER num_ctx 8192
EOF
cat > "${CPM_DIR}/sampling-presets.json" <<'EOF'
{
"model": "MiniCPM5-15B-A2.5B",
"thinking_general": {"temperature": 1.0, "top_p": 0.95, "min_p": 0.0, "repetition_penalty_if_loop": 1.05},
"non_thinking_general": {"temperature": 0.7, "top_p": 0.80, "top_k": 20, "min_p": 0.0, "presence_penalty": 1.5, "repetition_penalty": 1.0},
"thinking_creative": {"temperature": 0.7, "top_p": 0.95, "min_p": 0.0, "repetition_penalty": 1.05},
"dspark_quantized_safe": {"spec_type": "draft-dspark", "spec_draft_n_max": 2, "spec_draft_p_min": 0},
"agent_protocol_guards": {
"vllm_sglang_parsers": "--tool-call-parser minicpm5 --reasoning-parser qwen3",
"coding_min_max_tokens": 16384,
"anthropic_echo_rule": "Strip whitespace-only text blocks while preserving thinking and tool_use blocks"
}
}
EOF
LAUNCHER_CREATED="true"
PRESETS_CREATED="true"
fi
if (( APPLY_OLLAMA == 1 )); then
mkdir -p "$CPM_DIR"
cat > "${CPM_DIR}/ollama-override.conf" <<'EOF'
[Service]
Environment="OLLAMA_FLASH_ATTENTION=1"
Environment="OLLAMA_KV_CACHE_TYPE=q8_0"
EOF
OLLAMA_CONF_CREATED="true"
fi
if (( SCAFFOLD_AGENT == 1 )); then
AGENT_DIR="${TARGET_DIR}/.claude/agents"
mkdir -p "$AGENT_DIR"
cat > "${AGENT_DIR}/minicpm5-local-worker.md" <<EOF
---
name: minicpm5-local-worker
description: Local MiniCPM5-15B-A2.5B Ubuntu 26.04 execution & protocol guard profile
---
- Local endpoint: \`http://localhost:8080/v1\` (llama.cpp) or \`http://localhost:8000/v1\` (vLLM/SGLang)
- Always launch vLLM/SGLang with \`--tool-call-parser minicpm5 --reasoning-parser qwen3\`.
- Always pass \`--min-p 0\` to \`llama-server\`; use \`presence_penalty=1.5\` when thinking is disabled.
- Set \`max_tokens >= 16384\` for coding tasks and preserve historical thinking blocks.
EOF
AGENT_SCAFFOLDED="true"
fi
# 5. Output
if (( JSON_MODE == 1 )); then
cat <<EOF
{
"os": "Ubuntu 26.04",
"ram_gb": ${RAM_GB},
"gpu": "${GPU_NAME}",
"vram_gb": ${VRAM_GB},
"free_disk_gb": ${FREE_DISK_GB},
"tier": "${TIER}",
"recommended_gguf": "${REC_GGUF}",
"recommended_vllm": "${REC_VLLM}",
"recommended_litert": "${REC_LITERT}",
"estimated_download_gb": ${DL_GB},
"traps": {
"disk_space_warning": ${DISK_WARN},
"llama_server_found": ${LLAMA_FOUND},
"ollama_found": ${OLLAMA_FOUND},
"litert_lm_found": ${LITERT_FOUND},
"transformers_5_25_ready": ${TRANSFORMERS_OK},
"ollama_kv_bloat_trap": ${OLLAMA_KV_BLOAT_TRAP},
"stale_base_url_trap": ${STALE_BASE_URL_TRAP}
},
"actions": {
"launcher_created": ${LAUNCHER_CREATED},
"presets_created": ${PRESETS_CREATED},
"ollama_override_created": ${OLLAMA_CONF_CREATED},
"agent_scaffolded": ${AGENT_SCAFFOLDED},
"backup_file": "${BACKUP_FILE}"
}
}
EOF
else
echo ""
echo "=== Summary & Next Steps ==="
echo "Hardware Tier : ${TIER} (RAM ${RAM_GB} GB / VRAM ${VRAM_GB} GB)"
echo "Traps Detected : ollama_kv_bloat=${OLLAMA_KV_BLOAT_TRAP}, transformers_ok=${TRANSFORMERS_OK}"
echo "Launchers : ${CPM_DIR}/launch-minicpm5-{thinking,fast,vllm}.sh"
fi
chmod +x ./minicpm5_local_toolkit_ubuntu2604.sh && bash ./minicpm5_local_toolkit_ubuntu2604.sh
3. macOS 27 (Native Zsh: minicpm5_local_toolkit_macos27.zsh)
#!/usr/bin/env zsh
# ==============================================================================
# MiniCPM5-15B-A2.5B Local Diagnostic, MLX-VLM / LiteRT Guard & Auto-Config — macOS 27
# Zero third-party dependencies (macOS built-in zsh, sysctl, df, awk, grep, sed)
# Privacy Guard: Never emits hostnames, full non-loopback IPs, or raw API keys.
#
# Modes:
# Human Interactive: zsh ./minicpm5_local_toolkit_macos27.zsh
# Agent Automated: zsh ./minicpm5_local_toolkit_macos27.zsh --auto --json --apply --scaffold-agent --target .
# ==============================================================================
set -euo pipefail
AUTO=0
JSON_MODE=0
APPLY=0
APPLY_OLLAMA=0
SCAFFOLD_AGENT=0
TARGET_DIR="."
while [[ $# -gt 0 ]]; do
case "$1" in
--auto) AUTO=1; shift ;;
--json) JSON_MODE=1; shift ;;
--apply) APPLY=1; shift ;;
--apply-ollama) APPLY_OLLAMA=1; shift ;;
--scaffold-agent) SCAFFOLD_AGENT=1; shift ;;
--target) TARGET_DIR="${2:-.}"; shift 2 ;;
-h|--help)
cat <<'EOF'
Usage: zsh minicpm5_local_toolkit_macos27.zsh [options]
--auto Non-interactive mode for AI Agents
--json Emit sanitized JSON output
--apply Generate ~/.minicpm5-local launchers & sampling presets
--apply-ollama Export Ollama FlashAttention + q8_0 KV cache into ~/.zshrc
--scaffold-agent Write .claude/agents/minicpm5-local-worker.md in --target
--target <dir> Target workspace directory (default: .)
EOF
exit 0
;;
*) print -u2 -- "Unknown option: $1"; exit 1 ;;
esac
done
# 1. Apple Silicon Unified Memory & Disk Detection (Sanitized)
ARCH="$(uname -m)"
MEM_BYTES="$(sysctl -n hw.memsize 2>/dev/null || echo 0)"
RAM_GB="$(awk -v b="$MEM_BYTES" 'BEGIN {printf "%.1f", b/1024/1024/1024}')"
CHIP_NAME="$(sysctl -n machdep.cpu.brand_string 2>/dev/null || echo 'Apple Silicon')"
mkdir -p "$TARGET_DIR" 2>/dev/null || true
FREE_DISK_KB="$(df -Pk "$TARGET_DIR" | awk 'NR==2 {print $4}')"
FREE_DISK_GB="$(awk -v k="${FREE_DISK_KB:-0}" 'BEGIN {printf "%.1f", k/1024/1024}')"
TIER="Tier-D (<16GB Tight)"
REC_GGUF="MiniCPM5-15B-A2.5B-Q4_K_M.gguf (tight; consider MiniCPM5-2B)"
REC_MLX="none (insufficient unified memory for 15B MLX + KV)"
REC_LITERT="MiniCPM5-15B-A2.5B_mixed.litertlm (tight; free swap first)"
DL_GB="8.49"
if awk -v r="$RAM_GB" 'BEGIN {exit !(r >= 32)}'; then
TIER="Tier-A (32GB+ Unified)"
REC_GGUF="MiniCPM5-15B-A2.5B-Q8_0.gguf (or BF16 27.97 GiB)"
REC_MLX="openbmb/MiniCPM5-15B-A2.5B-MLX + DSpark"
REC_LITERT="MiniCPM5-15B-A2.5B_mixed.litertlm or _int8.litertlm (Metal GPU)"
DL_GB="14.87"
elif awk -v r="$RAM_GB" 'BEGIN {exit !(r >= 22)}'; then
TIER="Tier-B (24GB Unified)"
REC_GGUF="MiniCPM5-15B-A2.5B-Q8_0.gguf (14.87 GiB) or Q4_K_M"
REC_MLX="openbmb/MiniCPM5-15B-A2.5B-MLX (via mlx-vlm@main)"
REC_LITERT="MiniCPM5-15B-A2.5B_mixed.litertlm (8.28 GB, Metal GPU)"
DL_GB="14.87"
elif awk -v r="$RAM_GB" 'BEGIN {exit !(r >= 15)}'; then
TIER="Tier-C (16GB Unified)"
REC_GGUF="MiniCPM5-15B-A2.5B-Q4_K_M.gguf (8.49 GiB, num_ctx 8192)"
REC_MLX="openbmb/MiniCPM5-15B-A2.5B-MLX (target only, skip DSpark)"
REC_LITERT="MiniCPM5-15B-A2.5B_mixed.litertlm (8.28 GB GPU only; NEVER int8/int4)"
DL_GB="8.49"
fi
DISK_WARN="false"
if awk -v d="$FREE_DISK_GB" 'BEGIN {exit !(d < 25)}'; then
DISK_WARN="true"
fi
# 2. Local Runtime & Day-1 Trap Scan
LLAMA_FOUND="false"; command -v llama-server >/dev/null 2>&1 && LLAMA_FOUND="true"
OLLAMA_FOUND="false"; command -v ollama >/dev/null 2>&1 && OLLAMA_FOUND="true"
LITERT_FOUND="false"; command -v litert-lm >/dev/null 2>&1 && LITERT_FOUND="true"
MLX_VLM_READY="false"
MLX_LM_TRAP="false"
TRANSFORMERS_OK="false"
if command -v python3 >/dev/null 2>&1; then
python3 -c "from mlx_vlm.models.minicpm5_moe import Model" >/dev/null 2>&1 && MLX_VLM_READY="true"
python3 -c "import mlx_lm" >/dev/null 2>&1 && [[ "$MLX_VLM_READY" == "false" ]] && MLX_LM_TRAP="true"
python3 -c "import transformers, packaging.version as v; exit(0 if v.parse(transformers.__version__) >= v.parse('5.25.0') else 1)" >/dev/null 2>&1 && TRANSFORMERS_OK="true"
fi
OLLAMA_KV_BLOAT_TRAP="false"
if [[ "$OLLAMA_FOUND" == "true" ]]; then
if [[ "${OLLAMA_FLASH_ATTENTION:-}" != "1" || -z "${OLLAMA_KV_CACHE_TYPE:-}" ]]; then
OLLAMA_KV_BLOAT_TRAP="true"
fi
fi
STALE_BASE_URL_TRAP="false"
if [[ -n "${OPENAI_BASE_URL:-}" && ! "${OPENAI_BASE_URL}" =~ localhost && ! "${OPENAI_BASE_URL}" =~ 127\.0\.0\.1 ]]; then
STALE_BASE_URL_TRAP="true"
fi
# 3. Interactive Human Prompt
if (( AUTO == 0 )); then
print -P "%B=== MiniCPM5-15B-A2.5B macOS 27 Local Triage ===%b"
print -r -- "Unified Memory Tier: ${TIER} (${RAM_GB} GB) | Free Disk: ${FREE_DISK_GB} GB"
print -r -- "GGUF Pick: ${REC_GGUF}"
print -r -- "Apple Silicon MLX: ${REC_MLX} (requires mlx-vlm@main, NOT mlx-lm!)"
print -r -- "LiteRT-LM Pick: ${REC_LITERT}"
if (( APPLY == 0 )); then
read -r "ans_apply?Generate local MiniCPM5 launchers & presets in ~/.minicpm5-local? [Y/n] "
if [[ -z "$ans_apply" || "$ans_apply" == [Yy]* ]]; then APPLY=1; fi
fi
if [[ "$OLLAMA_FOUND" == "true" && $APPLY_OLLAMA -eq 0 ]]; then
read -r "ans_ol?Append Ollama FlashAttention + q8_0 KV cache exports to ~/.zshrc? [y/N] "
if [[ "$ans_ol" == [Yy]* ]]; then APPLY_OLLAMA=1; fi
fi
if (( SCAFFOLD_AGENT == 0 )); then
read -r "ans_ag?Scaffold local MiniCPM5 worker profile in target directory? [y/N] "
if [[ "$ans_ag" == [Yy]* ]]; then SCAFFOLD_AGENT=1; fi
fi
fi
# 4. Apply Configs Safely
CPM_DIR="${HOME}/.minicpm5-local"
LAUNCHER_CREATED="false"
PRESETS_CREATED="false"
OLLAMA_ENV_APPLIED="false"
AGENT_SCAFFOLDED="false"
BACKUP_FILE="none"
if (( APPLY == 1 )); then
mkdir -p "$CPM_DIR"
THINK_ZSH="${CPM_DIR}/launch-minicpm5-thinking.zsh"
FAST_ZSH="${CPM_DIR}/launch-minicpm5-fast.zsh"
MLX_ZSH="${CPM_DIR}/launch-minicpm5-mlxvlm.zsh"
MODELFILE_PATH="${CPM_DIR}/Modelfile.minicpm5-q4km"
if [[ -f "$THINK_ZSH" ]]; then
BACKUP_FILE="${THINK_ZSH}.bak.$(date +%Y%m%d%H%M%S)"
cp "$THINK_ZSH" "$BACKUP_FILE"
fi
cat > "$THINK_ZSH" <<'EOF'
#!/usr/bin/env zsh
set -euo pipefail
GGUF_PATH="${1:-$HOME/models/MiniCPM5-15B-A2.5B-Q4_K_M.gguf}"
exec llama-server -m "$GGUF_PATH" -a MiniCPM5-15B-A2.5B \
--host localhost --port 8080 -ngl 99 -fa on -c 8192 --jinja \
--temp 1.0 --top-p 0.95 --min-p 0.0 --repeat-penalty 1.0
EOF
chmod +x "$THINK_ZSH"
cat > "$FAST_ZSH" <<'EOF'
#!/usr/bin/env zsh
set -euo pipefail
GGUF_PATH="${1:-$HOME/models/MiniCPM5-15B-A2.5B-Q4_K_M.gguf}"
exec llama-server -m "$GGUF_PATH" -a MiniCPM5-15B-A2.5B \
--host localhost --port 8080 -ngl 99 -fa on -c 8192 --jinja \
--temp 0.7 --top-p 0.80 --top-k 20 --min-p 0.0 --presence-penalty 1.5 --repeat-penalty 1.0
EOF
chmod +x "$FAST_ZSH"
cat > "$MLX_ZSH" <<'EOF'
#!/usr/bin/env zsh
set -euo pipefail
# Must use mlx-vlm@main (PR #2866 + PR #2870), NOT mlx-lm!
export MODEL="${1:-openbmb/MiniCPM5-15B-A2.5B-MLX}"
exec python3 -m mlx_vlm.server --model "$MODEL" --port 8080
EOF
chmod +x "$MLX_ZSH"
cat > "$MODELFILE_PATH" <<'EOF'
FROM ./MiniCPM5-15B-A2.5B-Q4_K_M.gguf
TEMPLATE """{{- if .Messages -}}
{{- range .Messages -}}
<|im_start|>{{ .Role }}
{{ .Content }}<|im_end|>
{{ end -}}
<|im_start|>assistant
{{ end -}}"""
PARAMETER stop "<|im_end|>"
PARAMETER stop "</s>"
PARAMETER temperature 1.0
PARAMETER top_p 0.95
PARAMETER num_ctx 8192
EOF
cat > "${CPM_DIR}/sampling-presets.json" <<'EOF'
{
"model": "MiniCPM5-15B-A2.5B",
"thinking_general": {"temperature": 1.0, "top_p": 0.95, "min_p": 0.0, "repetition_penalty_if_loop": 1.05},
"non_thinking_general": {"temperature": 0.7, "top_p": 0.80, "top_k": 20, "min_p": 0.0, "presence_penalty": 1.5, "repetition_penalty": 1.0},
"thinking_creative": {"temperature": 0.7, "top_p": 0.95, "min_p": 0.0, "repetition_penalty": 1.05},
"dspark_quantized_safe": {"spec_type": "draft-dspark", "spec_draft_n_max": 2, "spec_draft_p_min": 0},
"agent_protocol_guards": {
"vllm_sglang_parsers": "--tool-call-parser minicpm5 --reasoning-parser qwen3",
"coding_min_max_tokens": 16384,
"anthropic_echo_rule": "Strip whitespace-only text blocks while preserving thinking and tool_use blocks"
}
}
EOF
LAUNCHER_CREATED="true"
PRESETS_CREATED="true"
fi
if (( APPLY_OLLAMA == 1 )); then
ZSHRC="${HOME}/.zshrc"
touch "$ZSHRC"
if ! grep -q "OLLAMA_FLASH_ATTENTION" "$ZSHRC"; then
cat >> "$ZSHRC" <<'EOF'
# MiniCPM5-15B-A2.5B Metal KV Cache Guard
export OLLAMA_FLASH_ATTENTION=1
export OLLAMA_KV_CACHE_TYPE=q8_0
EOF
fi
export OLLAMA_FLASH_ATTENTION=1
export OLLAMA_KV_CACHE_TYPE=q8_0
OLLAMA_ENV_APPLIED="true"
OLLAMA_KV_BLOAT_TRAP="false"
fi
if (( SCAFFOLD_AGENT == 1 )); then
AGENT_DIR="${TARGET_DIR}/.claude/agents"
mkdir -p "$AGENT_DIR"
cat > "${AGENT_DIR}/minicpm5-local-worker.md" <<EOF
---
name: minicpm5-local-worker
description: Local MiniCPM5-15B-A2.5B Apple Silicon execution & protocol guard profile
---
- Local endpoint: \`http://localhost:8080/v1\`
- Apple Silicon MLX runtime: use \`mlx-vlm\` main branch (PR #2866/#2870), never \`mlx-lm\`.
- LiteRT-LM runtime: use \`MiniCPM5-15B-A2.5B_mixed.litertlm\` on Metal GPU (never \`int4\` or Mac CPU \`mixed\`).
- Coding agent budget: set \`max_tokens >= 16384\`, keep \`--min-p 0\`, and echo historical thinking blocks.
EOF
AGENT_SCAFFOLDED="true"
fi
# 5. Output
if (( JSON_MODE == 1 )); then
cat <<EOF
{
"os": "macOS 27",
"arch": "${ARCH}",
"chip": "${CHIP_NAME}",
"unified_memory_gb": ${RAM_GB},
"free_disk_gb": ${FREE_DISK_GB},
"tier": "${TIER}",
"recommended_gguf": "${REC_GGUF}",
"recommended_mlx": "${REC_MLX}",
"recommended_litert": "${REC_LITERT}",
"estimated_download_gb": ${DL_GB},
"traps": {
"disk_space_warning": ${DISK_WARN},
"llama_server_found": ${LLAMA_FOUND},
"ollama_found": ${OLLAMA_FOUND},
"litert_lm_found": ${LITERT_FOUND},
"mlx_vlm_minicpm5_ready": ${MLX_VLM_READY},
"mlx_lm_without_mlx_vlm_trap": ${MLX_LM_TRAP},
"transformers_5_25_ready": ${TRANSFORMERS_OK},
"ollama_kv_bloat_trap": ${OLLAMA_KV_BLOAT_TRAP},
"stale_base_url_trap": ${STALE_BASE_URL_TRAP}
},
"actions": {
"launcher_created": ${LAUNCHER_CREATED},
"presets_created": ${PRESETS_CREATED},
"ollama_env_applied": ${OLLAMA_ENV_APPLIED},
"agent_scaffolded": ${AGENT_SCAFFOLDED},
"backup_file": "${BACKUP_FILE}"
}
}
EOF
else
print -r -- ""
print -P "%B=== Summary & Next Steps ===%b"
print -r -- "Unified Memory : ${RAM_GB} GB (${CHIP_NAME}) -> ${TIER}"
print -r -- "Traps Detected : mlx_lm_trap=${MLX_LM_TRAP}, ollama_kv_bloat=${OLLAMA_KV_BLOAT_TRAP}, transformers_ok=${TRANSFORMERS_OK}"
print -r -- "Launchers : ${CPM_DIR}/launch-minicpm5-{thinking,fast,mlxvlm}.zsh"
print -r -- "Agent Guide : Pass --min-p 0 for llama-server; never use LiteRT int4 or Mac CPU mixed."
fi
chmod +x ./minicpm5_local_toolkit_macos27.zsh && zsh ./minicpm5_local_toolkit_macos27.zsh
5.2 Method 2: AI Agent Auto-Configuration Prompt
Run the zero-dependency MiniCPM5-15B-A2.5B local diagnostic and setup script for the current OS:
- Windows 11: powershell -ExecutionPolicy Bypass -File .\minicpm5_local_toolkit_windows11.ps1 -Auto -Json -Apply -ApplyOllama -ScaffoldAgent -Target .
- Ubuntu 26.04: bash ./minicpm5_local_toolkit_ubuntu2604.sh --auto --json --apply --apply-ollama --scaffold-agent --target .
- macOS 27: zsh ./minicpm5_local_toolkit_macos27.zsh --auto --json --apply --apply-ollama --scaffold-agent --target .
Then verify:
1. disk_space_warning is false and share exact pull/run commands matching tier (never recommend LiteRT int4 or LiteRT int8 on 16GB machines);
2. If mlx_lm_without_mlx_vlm_trap is true on macOS, instruct switching to mlx-vlm@main (PR #2866/#2870);
3. Report ollama_kv_bloat_trap and stale_base_url_trap status; remind that stock Ollama below PR #32644 needs a llama-server engine swap;
4. Confirm ~/.minicpm5-local launchers and sampling-presets.json include --min-p 0 and presence_penalty=1.5 for fast mode;
5. Confirm .claude/agents/minicpm5-local-worker.md was scaffolded in --target.
6. FAQ: 7 Practical Questions Answered
Q1: Which format should a 16GB laptop or 16GB Mac choose?
Pick MiniCPM5-15B-A2.5B-Q4_K_M.gguf (8.49 GiB) or MiniCPM5-15B-A2.5B_mixed.litertlm (8.28 GB) on Metal GPU (45.5 tok/s on Apple M5). Never run 15.08 GB LiteRT int8 on 16GB RAM (severe page-thrashing) and avoid LiteRT int4 (NLL degrades to 4.269–4.848).
Q2: Why does Ollama say unknown model architecture: 'minicpm5_moe'?
minicpm5_moe landed in llama.cpp PR #32644 (e18d1b21 / b12847+) on Nov 29, 2026. Upgrade Ollama to a release bundling that commit or swap its embedded llama-server binary using OpenBMB's ollama.md guide.
Q3: Why does Apple Silicon use mlx-vlm instead of mlx-lm for a text-only model?
OpenBMB integrated the minicpm5_moe loader and DSpark drafter into Neywa-Labs/mlx-vlm main (PR #2866 and PR #2870 for tool parsing). Older mlx-vlm 0.8.2 and mlx-lm lack the model class.
Q4: How do I actually run the ~3GB RAM mode on iPhone?
Install MiniCPM-V Demo via TestFlight on iOS 16+ (8GB+ RAM; 12GB recommended), download MiniCPM5-15B-A2.5B-Q3_gud-LCO-GGUF (~6.8 GB), keep Memory saver + Expert predictor enabled, and stay out of Fastest mode on 8GB phones.
Q5: Should I strip historical <think> blocks in multi-turn agent loops?
No—echoing historical thinking blocks preserves multi-step reasoning continuity and keeps prompt prefixes identical so Prefix KV Cache (RadixCache) hits remain high.
Q6: Can I quantize my own int4 weights without losing accuracy?
MoE routing and non-expert linear layers are sensitive to naive 4-bit quantization. Stick to official Q4_K_M, Q8_0, LCO-GGUF, MLX, or LiteRT mixed—or calibrate with llama-imatrix (~7M tokens) before quantizing.
Q7: Is there a hosted API or demo if my local hardware has under 16GB RAM?
Yes: try the official Hugging Face Space (openbmb/MiniCPM5-15B-A2.5B-Demo) or ModelBest's OpenAI-compatible platform at https://api.modelbest.cn/v1.
References
- Hugging Face Model Card & Benchmarks: openbmb/MiniCPM5-15B-A2.5B
- Official Derivatives: GGUF / Q3_gud-LCO-GGUF / MLX / LiteRT / DSpark
- GitHub Repository & Deployment Cookbooks: OpenBMB/MiniCPM (llama_cpp.md, ollama.md, mlx.md, litert.md, minicpm5_on_ios.md, tool_usage.md)
- ModelScope & API Platform: ModelScope / ModelBest Platform