Hybrid CPU+GPU MoE (KTransformers / ik_llama.cpp) & Edge NPU (Hailo-10H / RK3588) Troubleshooting: Fixing Auto-NUMA Thrashing, -ot Regex OOMs & CMA Errors
Root-cause diagnostics and verified fixes for 50–65% Linux Auto-NUMA slowdown (`kernel.numa_balancing=0`) on EPYC/Xeon MoE servers, `ik_llama.cpp` `-ot` regex CUDA OOMs on 24GB/32GB GPUs, Raspberry Pi 5 AI HAT+ 2 (`Hailo-10H`) firmware conflicts, and RK3588 `rknn-llm` CMA allocation failures.
AMD EPYC 9004/9005 / Intel Xeon DDR5 + Single RTX GPU | Raspberry Pi 5 + AI HAT+ 2 (Hailo-10H 8GB) | Rockchip RK3588 (16GB/32GB)
All NUMA sysctl commands, `-ot` regex overrides, and CMA memory compactions execute locally offline.
- On 24GB GPUs (RTX 3090/4090), offloading all 61 layers of `DeepSeek-R1-671B` shared/attention weights with `-ngl 99` requires `-mla 3 -fa -ctk q8_0` to keep VRAM under 22GB at 32K context.
- On Rockchip RK3588, expanding the kernel CMA pool beyond `cma=512M` or `1024M` requires updating `/boot/armbianEnv.txt` and rebooting if runtime memory compaction cannot free a large enough contiguous block.
1. Fixing Hybrid CPU+GPU MoE Slowdowns (`kernel.numa_balancing=0`) & `-ot` Regex CUDA OOMs
# 1. Stop Auto-NUMA page migration thrashing on EPYC / Threadripper / Xeon: sudo sysctl -w kernel.numa_balancing=0 echo "kernel.numa_balancing=0" | sudo tee /etc/sysctl.d/99-llm-numa.conf # 2. Exact ik_llama.cpp command to keep VRAM <= 18.5GB on a single 24GB/32GB GPU: numactl --interleave=all ./build/bin/llama-server \ -m /mnt/nvme/models/DeepSeek-R1-671B-IQ4_XS.gguf \ -ngl 99 \ -ot "blk\.[0-9]+\.ffn_.*_exps\.weight=CPU" \ -mla 3 -fa -fmoe \ -ctk q8_0 -ctv q8_0 -c 32768 -t 32
2. Fixing Edge NPU Failures: Pi 5 AI HAT+ 2 (`Hailo-10H` vs `Hailo-8`) & RK3588 CMA Exhaustion
| Hardware & Stack | Symptom / Error Log | Root Cause | Verified Fix |
|---|---|---|---|
| EPYC / Xeon DDR5 + Single GPU (`671B/235B`) | Decode drops from 15 tok/s to <5 tok/s; high kernel CPU | Linux `kernel.numa_balancing=1` migrates 4KB pages across nodes | `sudo sysctl -w kernel.numa_balancing=0` + `numactl --interleave=all` |
| Single 24GB/32GB GPU + System RAM (`ik_llama.cpp`) | `ggml_backend_cuda_buffer_type_alloc_buffer: failed` (OOM) | `-ot` regex missed expert tensors or FP16 MLA KV cache overflowed | `-ot "blk\.[0-9]+\.ffn_.*_exps\.weight=CPU" -mla 3 -ctk q8_0` |
| Raspberry Pi 5 + AI HAT+ 2 (`Hailo-10H` 8GB) | `HAILO_INVALID_FIRMWARE` or `hailo-ollama` fails to init | Legacy `hailo-all` (Hailo-8) installed instead of `hailo-h10-all` | `sudo apt purge hailo-all && sudo apt install hailo-h10-all` |
| Rockchip RK3588 (`rknn-llm` 6 TOPS NPU) | `rknn_init failed (-1)` or `DMA_BUF_IOCTL_ALLOC failed` | 64KB `ulimit -l` memlock cap or fragmented CMA physical RAM | `ulimit -l unlimited` + `vm.drop_caches=3` + `vm.compact_memory=1` |
3. Automated Hybrid MoE & Edge NPU Doctor Script
Frequently Asked Questions & Edge Cases
Q: What if my 24GB GPU still runs out of VRAM on `DeepSeek-R1-671B` when I raise context from 16K to 64K?
Even with routed experts on CPU, layers `0–2` in DeepSeek-R1 are **dense FFN layers** (~4.5 GB) plus 61 layers of shared experts and attention. To free another 4–6 GB of VRAM for a 64K KV cache on a 24GB card, either lower `-ngl` from `99` to `48` (offloading the last 13 layers’ shared/attention tensors to CPU) or add `-ot "blk\.[4-5][0-9]\.ffn_.*=CPU"`!
Q: Can I hot-swap between YOLOv8 vision models and `hailo-ollama` LLMs on the Raspberry Pi AI HAT+ 2 (`Hailo-10H`)?
Yes! HailoRT 5.x supports multi-context scheduling across the 8GB onboard LPDDR4X memory, or you can unload the active LLM via `curl -X POST http://127.0.0.1:11434/api/generate -d '{"model":"qwen2.5-instruct:1.5b","keep_alive":0}'` to release 100% of NPU cores and memory for high-FPS vision pipelines.
Hybrid CPU+GPU MoE (`NUMA` / `-ot` Regex) & Edge NPU (`Hailo-10H` / `RK3588 CMA`) Doctor
Detects cross-socket NUMA balancing stalls on EPYC/Xeon MoE servers, validates ik_llama.cpp -ot tensor regex syntax, and checks Hailo-10H PCIe Gen 3 & RK3588 CMA contiguous memory.
#!/usr/bin/env bash
# Tinker AI — Hybrid CPU+GPU MoE NUMA & Edge NPU (Hailo-10H / RK3588) Doctor (Guide #36)
set -euo pipefail
MIN_CMA="256"
MAX_VRAM="22500"
echo "=== [1/4] Checking Linux Auto-NUMA Balancing & Socket Interleaving ==="
if [ -f /proc/sys/kernel/numa_balancing ]; then
NB=$(cat /proc/sys/kernel/numa_balancing)
echo "kernel.numa_balancing = $NB"
if [ "$NB" = "1" ]; then
echo "[WARN] Auto-NUMA balancing is ON (1)! On multi-node EPYC/Xeon running KTransformers or ik_llama.cpp, this causes 50-65% decode slowdown. Fix: sudo sysctl -w kernel.numa_balancing=0"
else
echo "[OK] Auto-NUMA balancing is disabled."
fi
fi
echo "=== [2/4] Checking GPU Free VRAM vs Hybrid MoE Attention + KV Budget ($MAX_VRAM MB) ==="
if command -v nvidia-smi >/dev/null 2>&1; then
nvidia-smi --query-gpu=index,name,memory.used,memory.free --format=csv
echo "Tip: If ik_llama.cpp -ngl 99 OOMs on 671B/235B MoE, ensure regex matches routed experts: -ot 'blk\.[0-9]+\.ffn_.*_exps\.weight=CPU'"
fi
echo "=== [3/4] Checking Hailo-10H (AI HAT+ 2) PCIe Link Width & Firmware ==="
if command -v hailortcli >/dev/null 2>&1; then
hailortcli fw-control identify || echo "[WARN] hailortcli failed: verify hailo-h10-all package (do not mix with hailo-all for Hailo-8)!"
fi
echo "=== [4/4] Checking Contiguous Memory Allocator (CMA >= $MIN_CMA MB) & Memlock Limits ==="
grep -i "Cma" /proc/meminfo || true
echo "Current max locked memory (ulimit -l): $(ulimit -l)"