zheqiushui's picture
AX8860 llama.cpp package
8d0d264 verified
Raw History Blame Contribute Delete
15.6 kB
#!/bin/sh
# Repeatable AX8860 benchmark for the packaged VoxCPM2 model.
# Run under the board's NPU job lock. Every number in README.md is printed here.
H=$(cd "$(dirname "$0")" && pwd)
OUT=$H/bench
PORT=${PORT:-18277}
mkdir -p "$OUT"
export LD_LIBRARY_PATH=/opt/lib
export GGML_AXERA_KERNEL_DIR=$H/kernels
export GGML_AXERA_PROF=1
export VOXCPM2_PROF=1
export MALLOC_ARENA_MAX=2
export MALLOC_MMAP_THRESHOLD_=131072
export MALLOC_TRIM_THRESHOLD_=131072
REF=${REF:-$H/examples/reference.wav}
BASE=$H/gguf/VoxCPM2-BaseLM-F16.gguf
ACOUSTIC=$H/gguf/VoxCPM2-Acoustic-F16.gguf
SPID=
cleanup() {
if [ -n "${SPID:-}" ] && [ -d /proc/$SPID ]; then
kill -TERM "$SPID" 2>/dev/null || true
i=0
while [ -d /proc/$SPID ] && [ $i -lt 120 ]; do sleep 1; i=$((i+1)); done
fi
}
trap 'cleanup; exit 143' TERM INT
trap cleanup EXIT
cmm_cur_kb() {
awk '/NAME="anonymous"/{f=1;next} f&&/nbytes\(/&&match($0,/Cur=[0-9]+B/){x=substr($0,RSTART+4,RLENGTH-5); printf "%d", x/1024; exit}' /proc/ax_proc/mem_cmm_info
}
nthr() { awk '/Threads:/{print $2}' /proc/$SPID/status; }
audio_s() {
python3 - "$1" <<'PY'
import os, sys, wave
# A streamed WAV declares an open-ended data size, so take the duration from
# the file size for those; a regular WAV is read from its header.
p = sys.argv[1]
try:
with wave.open(p, 'rb') as w:
n, sr = w.getnframes(), w.getframerate()
if n / float(sr) > 600:
n = (os.path.getsize(p) - 44) // 2
print(f"{n / float(sr):.3f}")
except Exception:
n = (os.path.getsize(p) - 44) // 2
print(f"{n / 48000.0:.3f}")
PY
}
one() {
# one <tag> <text>; prints wall, time-to-first-byte, audio duration and RTF.
tag=$1; text=$2
wav=$OUT/$tag.wav
t=$(curl -sS -m 900 -o "$wav" -H "Content-Type: application/json" \
--data-binary "{\"model\":\"voxcpm2\",\"input\":\"$text\",\"response_format\":\"wav\",\"seed\":42}" \
-w '%{time_starttransfer} %{time_total}' "http://127.0.0.1:$PORT/v1/audio/speech")
ttfb=$(echo "$t" | cut -d' ' -f1)
wall=$(echo "$t" | cut -d' ' -f2)
s=$(audio_s "$wav")
awk -v t="$tag" -v f="$ttfb" -v w="$wall" -v s="$s" \
'BEGIN{printf "BENCH %s first_byte_s=%.3f wall_s=%.3f audio_s=%.3f rtf=%.3f\n",t,f,w,s,w/s}'
}
stream_one() {
# Streamed PCM has no header, so the first body byte is the first decoded
# audio. curl reports the HTTP header time here, which is ~0 because the
# chunked response sends headers before the first audio chunk exists; read
# the body directly so the number is the actual time to first audio.
tag=$1; text=$2
pcm=$OUT/$tag.pcm
t=$(python3 - "$PORT" "$text" "$pcm" <<'PY'
import http.client, json, sys, time
port, text, out = int(sys.argv[1]), sys.argv[2], sys.argv[3]
body = json.dumps({"model": "voxcpm2", "input": text, "response_format": "pcm",
"seed": 42, "stream": True}).encode()
c = http.client.HTTPConnection("127.0.0.1", port, timeout=900)
t0 = time.time()
c.request("POST", "/v1/audio/speech", body, {"Content-Type": "application/json"})
r = c.getresponse()
first = None
n = 0
with open(out, "wb") as f:
while True:
chunk = r.read1(65536) if hasattr(r, "read1") else r.read(65536)
if not chunk:
break
if first is None:
first = time.time() - t0
f.write(chunk)
n += len(chunk)
print(f"{first:.3f} {time.time() - t0:.3f} {n}")
PY
)
first=$(echo "$t" | cut -d' ' -f1)
wall=$(echo "$t" | cut -d' ' -f2)
bytes=$(wc -c <"$pcm")
s=$(awk -v b="$bytes" 'BEGIN{printf "%.3f", b/2/48000}')
awk -v t="$tag" -v f="$first" -v w="$wall" -v s="$s" \
'BEGIN{printf "BENCH %s stream_first_audio_s=%.3f wall_s=%.3f audio_s=%.3f rtf=%.3f\n",t,f,w,s,w/s}'
}
module_table() {
# One line per request from the runtime's stage profile. Call counts are
# the kernel calls the step loop makes; VAE decodes six latent frames per
# call, and one audio patch is four latent frames.
grep 'VOXPROF' "$OUT/server.log" | tail -1 | sed 's/^.*VOXPROF /BENCH stage /'
line=$(grep 'VOXPROF' "$OUT/server.log" | tail -1)
steps=$(echo "$line" | sed -n 's/.*steps=\([0-9]*\).*/\1/p')
vae_calls=$(awk -v s="$steps" 'BEGIN{n=s*4; c=int((n+5)/6); print (c>0?c:1)}')
pre_res=$(echo "$line" | sed -n "s/.*[ ]prefill_res_ms=\([0-9.]*\).*/\1/p")
for spec in \
"base_lm_decode:base_ms:1" "dit_loop(9_euler):front_dit_ms:1" \
"locenc+enc_to_lm:front_locenc_ms:1" "residual_lm+post:residual_ms:1"; do
name=${spec%%:*}; rest=${spec#*:}; key=${rest%%:*}; calls=${rest#*:}
ms=$(echo "$line" | sed -n "s/.*[ ]${key}=\([0-9.]*\).*/\1/p")
if [ "$key" = "residual_ms" ]; then
ms=$(awk -v a="$ms" -v b="${pre_res:-0}" 'BEGIN{printf "%.3f", a-b}')
fi
awk -v n="$name" -v s="$steps" -v ms="$ms" -v c="$calls" \
'BEGIN{if(s>0) printf "BENCH step_module %-26s calls_per_step=%s total_ms=%.2f ms_per_call=%.3f\n",n,c,ms,ms/(s*c)}'
done
ms=$(echo "$line" | sed -n "s/.*[ ]vae_ms=\([0-9.]*\).*/\1/p")
awk -v n="audiovae_decode(6-frame)" -v s="$steps" -v ms="$ms" -v c="$vae_calls" \
'BEGIN{if(s>0) printf "BENCH step_module %-26s calls_per_step=%.3f total_ms=%.2f ms_per_call=%.3f\n",n,c/s,ms,ms/c}'
echo "BENCH npu_calls_per_step=4 (base_lm_decode + dit_loop + locenc + residual_lm_post)"
awk -v s="$steps" -v v="$vae_calls" 'BEGIN{if(s>0) printf "BENCH npu_calls_per_step_with_vae=%.3f\n",4+v/s}'
}
{
trap cleanup EXIT
echo "VoxCPM2 AX8860 benchmark $(date -Iseconds)"
echo "BENCH cmm_before_kb=$(cmm_cur_kb)"
t0=$(date +%s%N)
"$H/bin/llama-server" -m "$BASE" --voxcpm2-base-lm "$BASE" --voxcpm2-acoustic "$ACOUSTIC" \
-ngl 99 -c 8192 -b 1024 -np 1 -t 8 --threads-http 1 --host 127.0.0.1 --port "$PORT" >"$OUT/server.log" 2>&1 &
SPID=$!
ready=0
i=0
while [ $i -lt 300 ]; do
if ! [ -d /proc/$SPID ]; then break; fi
if curl -sf "http://127.0.0.1:$PORT/health" >/dev/null 2>&1; then ready=1; break; fi
sleep 1; i=$((i+1))
done
t1=$(date +%s%N)
if [ $ready -ne 1 ]; then
echo "BENCH server FAILED to start"
tail -20 "$OUT/server.log"
else
awk -v a="$t0" -v b="$t1" 'BEGIN{printf "BENCH server_ready_s=%.3f\n",(b-a)/1e9}'
echo "BENCH cmm_after_load_kb=$(cmm_cur_kb)"
echo "BENCH rss_after_load_kb=$(awk '/VmRSS/{print $2}' /proc/$SPID/status)"
EN_S="The quick brown fox jumps over the lazy dog."
ZH_S="请打开窗户,让新鲜空气进来。"
EN_M="The morning train rolled slowly along the river, and the passengers watched the fog lift from the hills as the first light touched the water."
ZH_M="今天的天气很好,我们一起去公园散步,看看湖边的柳树和远处的山,顺便聊聊最近的天气变化。"
EN_L="When the old lighthouse keeper finally retired, the village held a small gathering by the harbour, and everyone told stories about the winter storms, the ships that had passed in the night, and the bright beam that had guided them home for forty years. The children ran along the seawall with paper boats, the fishermen mended their nets in the last light, and someone played an old song on a wooden flute while the gulls circled overhead."
ZH_L="秋天的傍晚,风从山谷里吹过来,带着桂花和稻谷的香味。我们沿着河边的小路慢慢走,看见孩子们在桥上放风筝,老人们坐在树下聊天,远处传来火车经过的声音。孩子们的笑声在巷子里回荡,远处的炊烟慢慢升起。天色一点点暗下来,路灯亮了,整座小城显得安静而温暖。"
# Long-sentence quality set: five Chinese (100-130 characters) and five
# English (40-60 words) passages. These are synthesised with the same
# seed as the accuracy report so the WAVs in bench/ can be transcribed.
ZH01="清晨六点四十分,第一班地铁准时驶出站台,车厢里的乘客一边看手机,一边留意广播里报出的站名。程序员小林打开电脑,检查昨晚提交的代码,发现三个测试需要重跑,于是他在笔记本上写下今天的计划:修复两个问题,完成一次发布,下午四点参加评审。"
ZH02="“你看见我的钥匙了吗?”妈妈在门口问。“是不是放在餐桌上?”爸爸回答。“桌上只有报纸和杯子。”“那你去沙发旁边找找,昨天你回来的时候,好像把外套放在那里了。”我听见他们你一言我一语,忍不住笑着提醒:“钥匙就在门边的小篮子里呀!”"
ZH03="这座古城建于明代,城墙沿着山势蜿蜒十余里,东门外的石桥已经有六百多年历史。商队曾经从这里经过,把茶叶、丝绸和瓷器运往北方。如今老街两旁仍保留着木结构的店铺,屋檐下挂着红灯笼,游客在青石板上慢慢行走,听讲解员讲述那些旧日的故事。"
ZH04="做一锅好吃的番茄牛腩,要先把牛腩切成小块,用冷水浸泡半小时,再放入锅中焯水。接着把洋葱、姜片和番茄炒出香味,加入牛腩和适量清水,小火炖上一个小时。最后放盐和黑胡椒,再撒一把香菜。汤汁酸甜浓郁,配米饭或者面条都很合适。"
ZH05="春天来的时候,山坡上的积雪慢慢融化,溪水从石缝间流下来,汇成一条清澈的小河。柳树抽出嫩芽,燕子从南方飞回旧巢,田野里传来拖拉机的声音。农民把种子撒进湿润的泥土,孩子们在田埂上追逐,空气中混着青草和泥土的气息,整个村庄都醒过来了。"
EN01="When the first train reached the small coastal town, the station master rang the brass bell three times, and everyone hurried down to the platform to see the passengers arrive. The fishermen forgot their nets for a moment, the children waved from the fence, and the baker carried a tray of warm bread through the crowd."
EN02="The research team spent three years developing a battery that can charge in twelve minutes and still keep most of its capacity after two thousand cycles. They tested it in cold weather, in heat, and during long journeys, then published the measurements together with the full manufacturing recipe so other laboratories could repeat the experiment."
EN03="On Saturday morning, my neighbour asked whether I could help him move an old wooden table from his garage to the garden. We lifted it carefully through the narrow doorway, stopped twice to catch our breath, and finally set it under the apple tree, where his family was already waiting with teapots, plates, and a very large cake."
EN04="The museum opened a new gallery devoted to maps, clocks, and instruments used by sailors before satellites existed. Visitors can turn a small brass wheel to see how a compass responds, compare handwritten charts from different centuries, and listen to recordings of captains describing storms, currents, and the long quiet nights at sea."
EN05="If you want to cook rice for a crowd, first rinse it until the water runs clear, then use one part rice to one and a half parts water. Bring it to a boil, lower the heat, cover the pot, and wait about fifteen minutes. Turn off the flame and let it rest before opening the lid."
one cold_en "$EN_S"
echo "BENCH cmm_after_cold_kb=$(cmm_cur_kb)"
one warmup_en "$EN_S"
one warm_en_short "$EN_S"
one warm_zh_short "$ZH_S"
one warm_en_8s "$EN_M"
one warm_zh_8s "$ZH_M"
one warm_en_20s "$EN_L"
one warm_zh_20s "$ZH_L"
for id in ZH01 ZH02 ZH03 ZH04 ZH05; do
eval "text=\$$id"
one "quality_$id" "$text"
done
for id in EN01 EN02 EN03 EN04 EN05; do
eval "text=\$$id"
one "quality_$id" "$text"
done
python3 - "$ZH01" "$EN01" <<'PYEOF2'
import sys
print("BENCH quality_long cases=10 zh_chars=%d en_words=%d" % (len(sys.argv[1]), len(sys.argv[2].split())))
PYEOF2
echo "BENCH cmm_end_kb=$(cmm_cur_kb)"
echo "BENCH rss_end_kb=$(awk '/VmRSS/{print $2}' /proc/$SPID/status)"
module_table
stream_one stream_en_short "$EN_S"
stream_one stream_zh_short "$ZH_S"
rss0=$(awk '/VmRSS/{print $2}' /proc/$SPID/status)
cmm0=$(cmm_cur_kb)
i=0
while [ $i -lt 20 ]; do
curl -sS -m 900 -o "$OUT/seq.wav" -H "Content-Type: application/json" \
--data-binary "{\"model\":\"voxcpm2\",\"input\":\"$EN_S\",\"response_format\":\"wav\",\"seed\":42}" \
"http://127.0.0.1:$PORT/v1/audio/speech" >/dev/null || echo "BENCH seq request $i failed"
i=$((i+1))
done
echo "BENCH seq20_rss_before_kb=$rss0 seq20_rss_after_kb=$(awk '/VmRSS/{print $2}' /proc/$SPID/status)"
echo "BENCH seq20_cmm_before_kb=$cmm0 seq20_cmm_after_kb=$(cmm_cur_kb)"
echo "BENCH seq20_threads=$(nthr)"
# Twenty mixed requests including two independent clones per cycle.
python3 - "$REF" "$OUT" <<'PY'
import base64, json, os, sys
ref, out = sys.argv[1], sys.argv[2]
b64 = base64.b64encode(open(ref, 'rb').read()).decode()
for tag, text, clone in [
('mix_en', 'The quick brown fox jumps over the lazy dog.', False),
('mix_zh', '今天天气很好,我们一起去公园散步吧。', False),
('mix_clone_en', 'This is a cloned voice speaking with VoxCPM2.', True),
('mix_clone_zh', '这是零样本音色克隆,用同一段参考音频合成中文。', True),
]:
body = {'model':'voxcpm2','input':text,'response_format':'wav','seed':42}
if clone:
body['ref_audio'] = b64
json.dump(body, open(os.path.join(out, tag + '.json'), 'w'))
PY
mix_cycle() {
for tag in mix_en mix_zh mix_clone_en mix_clone_zh; do
code=$(curl -sS -m 900 -o "$OUT/$tag.wav" -H "Content-Type: application/json" \
--data-binary "@$OUT/$tag.json" -w '%{http_code}' "http://127.0.0.1:$PORT/v1/audio/speech")
mixn=$((mixn+1))
[ "$code" = 200 ] || echo "BENCH mixed request $mixn failed http=$code"
done
}
mixn=0
mix_cycle
echo "BENCH mixed_warm_rss_kb=$(awk '/VmRSS/{print $2}' /proc/$SPID/status) mixed_warm_cmm_kb=$(cmm_cur_kb)"
rss1=$(awk '/VmRSS/{print $2}' /proc/$SPID/status)
cmm1=$(cmm_cur_kb)
for round in 1 2 3 4 5; do mix_cycle; done
echo "BENCH mixed20_rss_before_kb=$rss1 mixed20_rss_after_kb=$(awk '/VmRSS/{print $2}' /proc/$SPID/status)"
echo "BENCH mixed20_cmm_before_kb=$cmm1 mixed20_cmm_after_kb=$(cmm_cur_kb)"
echo "BENCH mixed20_threads=$(nthr)"
rss2=$(awk '/VmRSS/{print $2}' /proc/$SPID/status)
cmm2=$(cmm_cur_kb)
for round in 1 2 3 4 5; do mix_cycle; done
echo "BENCH mixed40_rss_before_kb=$rss2 mixed40_rss_after_kb=$(awk '/VmRSS/{print $2}' /proc/$SPID/status)"
echo "BENCH mixed40_cmm_before_kb=$cmm2 mixed40_cmm_after_kb=$(cmm_cur_kb)"
t2=$(date +%s%N)
kill -TERM "$SPID"
i=0
while [ -d /proc/$SPID ] && [ $i -lt 120 ]; do sleep 1; i=$((i+1)); done
t3=$(date +%s%N)
awk -v a="$t2" -v b="$t3" 'BEGIN{printf "BENCH term_exit_s=%.3f\n",(b-a)/1e9}'
grep -o 'init: banks[^0-9]*[0-9.]* ms' "$OUT/server.log" | tail -1 | sed 's/^/BENCH load /'
fi
} 2>&1 | tee "$OUT/bench.log"