Skip to content

Commit 16c29fe

Browse files
Managed user kimboclaude
andcommitted
feat(speedbench): add MiMo-V2.6-Flash SGLang MTP AL collector / feat(speedbench):新增 MiMo-V2.6-Flash SGLang MTP AL 采集脚本
Measures SPEED-Bench coding acceptance length for MiMo-V2.6-Flash's bundled MTP layers (SGLang multi-layer EAGLE, topk 1, depths 1-3) on B300, thinking on, for the golden AL curve mimov2.6flash_mtp.yaml. 在 B300 上测量 MiMo-V2.6-Flash 自带 MTP 层(SGLang 多层 EAGLE, topk 1,深度 1-3)在 SPEED-Bench coding 类别上的接受长度(开启思考), 用于生成 golden AL 曲线 mimov2.6flash_mtp.yaml。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0e5b07c commit 16c29fe

1 file changed

Lines changed: 223 additions & 0 deletions

File tree

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
#!/usr/bin/env bash
2+
3+
# MiMo-V2.6-Flash B300 SGLang SPEED-Bench AL matrix collector for the checkpoint's native MTP.
4+
#
5+
# For each MTP depth, measure the REAL acceptance length (AL) on one SPEED-Bench category and
6+
# emit a YAML matrix in the golden_al_distribution shape. The server matches the AgentX
7+
# serving setup (TP4, fa4, text-only, mimo parsers).
8+
#
9+
# SGLang serves MiMoV2 MTP as multi-layer EAGLE: one bundled MTP layer per draft step, linear
10+
# chain (topk 1), so MTP_LIST level N runs N steps with N + 1 draft tokens and stops at the
11+
# checkpoint's num_nextn_predict_layers.
12+
# SGLang's speed-bench loader applies the chat template client-side without kwargs, so every
13+
# cell runs the template default (thinking on), which is the mode AgentX selects.
14+
#
15+
# AL is SGLang's accept_length (accepted tokens per verify step, bonus token included,
16+
# cumulative since server start), the same quantity as vLLM's 1 + accepted/drafts. Each cell
17+
# restarts the server, so it covers one cell only.
18+
#
19+
# Dispatch this collector through speedbench-al.yml with framework=sglang.
20+
21+
set -o pipefail
22+
repo_root="$(cd "$(dirname "$0")/../../.." && pwd)"
23+
source "$repo_root/benchmarks/check_env.sh"
24+
check_env_vars \
25+
CATEGORY MODEL MODEL_PATH MTP_LIST OUT_YAML PORT SPEEDBENCH_OUTPUT_LEN THINKING_MODES
26+
27+
if [[ "$THINKING_MODES" != "on" ]]; then
28+
echo "CRITICAL: the SGLang speed-bench client cannot disable MiMo thinking; dispatch with thinking-modes=on (got '$THINKING_MODES')"
29+
exit 1
30+
fi
31+
32+
SERVE_MODEL="${MODEL_PATH}"
33+
MODEL_KEY="$(basename "$SERVE_MODEL" | tr '[:upper:]' '[:lower:]')"
34+
# AL is a per-draft accept/reject property independent of batch size, so batch the
35+
# SPEED-Bench pass to cut wall-clock.
36+
CONCURRENCY="32"
37+
TEMPERATURE="1.0"
38+
TOP_P="0.95"
39+
40+
SPEEDBENCH_DIR="/workspace/speed_bench_data"
41+
RESULTS_DIR="/workspace/speedbench_results"
42+
43+
mkdir -p "$RESULTS_DIR"
44+
nvidia-smi
45+
GPU_NAME="$(nvidia-smi --query-gpu=name --format=csv,noheader | head -1)"
46+
47+
if [[ ! -d "$MODEL_PATH" || -z "$(ls -A "$MODEL_PATH" 2>/dev/null)" ]]; then
48+
if [[ ! -w "$(dirname "$MODEL_PATH")" ]]; then
49+
echo "CRITICAL: $MODEL_PATH is empty and $(dirname "$MODEL_PATH") is not writable."
50+
echo "The cluster's models.entries names this checkpoint but the weights were never staged."
51+
exit 1
52+
fi
53+
echo "=== $MODEL_PATH is empty; downloading $MODEL (first run only) ==="
54+
hf download "$MODEL" --local-dir "$MODEL_PATH"
55+
fi
56+
57+
MTP_LAYERS=$(python3 -c '
58+
import json, sys
59+
print(json.load(open(sys.argv[1]))["num_nextn_predict_layers"])
60+
' "$MODEL_PATH/config.json")
61+
for mtp in $MTP_LIST; do
62+
if [[ "$mtp" -lt 1 || "$mtp" -gt "$MTP_LAYERS" ]]; then
63+
echo "CRITICAL: MTP level $mtp is outside 1..$MTP_LAYERS (num_nextn_predict_layers)"
64+
exit 1
65+
fi
66+
done
67+
68+
echo "=== Downloading SPEED-Bench dataset ==="
69+
pip install -q datasets tiktoken
70+
curl -LsSf https://raw.githubusercontent.com/NVIDIA-NeMo/Skills/refs/heads/main/nemo_skills/dataset/speed-bench/prepare.py \
71+
| python3 - --config qualitative --output_dir "$SPEEDBENCH_DIR"
72+
73+
if [[ ! -f "$SPEEDBENCH_DIR/qualitative.jsonl" ]]; then
74+
echo "CRITICAL: SPEED-Bench download failed — $SPEEDBENCH_DIR/qualitative.jsonl not found"
75+
exit 1
76+
fi
77+
78+
# SGLang's speed-bench loader only accepts the throughput-split categories on the CLI and
79+
# reads prompts from "turns", while prepare.py writes "messages". Filter the qualitative
80+
# split to $CATEGORY and restore "turns" from the user messages.
81+
CATEGORY_JSONL="$SPEEDBENCH_DIR/qualitative_${CATEGORY}.jsonl"
82+
python3 - "$SPEEDBENCH_DIR/qualitative.jsonl" "$CATEGORY_JSONL" "$CATEGORY" <<'EOF'
83+
import json, sys
84+
src, dst, category = sys.argv[1:]
85+
with open(src) as f, open(dst, "w") as out:
86+
for line in f:
87+
row = json.loads(line)
88+
if row.get("category") == category:
89+
row["turns"] = [m["content"] for m in row["messages"] if m["role"] == "user"]
90+
out.write(json.dumps(row) + "\n")
91+
EOF
92+
NUM_PROMPTS=$(wc -l < "$CATEGORY_JSONL")
93+
if [[ "$NUM_PROMPTS" -eq 0 ]]; then
94+
echo "CRITICAL: no SPEED-Bench qualitative rows for category '$CATEGORY'"
95+
exit 1
96+
fi
97+
98+
SERVER_PID=""
99+
_descendants() {
100+
local pid="$1" child
101+
for child in $(pgrep -P "$pid" 2>/dev/null || true); do
102+
echo "$child"
103+
_descendants "$child"
104+
done
105+
}
106+
cleanup_server() {
107+
if [[ -n "$SERVER_PID" ]]; then
108+
local descendants
109+
descendants=$(_descendants "$SERVER_PID")
110+
kill "$SERVER_PID" 2>/dev/null || true
111+
wait "$SERVER_PID" 2>/dev/null || true
112+
local pid
113+
for pid in $descendants; do
114+
kill -9 "$pid" 2>/dev/null || true
115+
done
116+
local waited=0
117+
while [[ $waited -lt 120 ]]; do
118+
local used
119+
used=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits 2>/dev/null | sort -rn | head -1)
120+
if [[ -z "$used" || "$used" -lt 2000 ]]; then break; fi
121+
sleep 3; waited=$((waited + 3))
122+
done
123+
SERVER_PID=""
124+
fi
125+
}
126+
trap 'cleanup_server' EXIT
127+
128+
declare -A AL_RESULT
129+
130+
run_cell() {
131+
local mode="$1" mtp="$2"
132+
133+
echo ""
134+
echo "=========================================="
135+
echo " Cell: thinking=$mode MTP=$mtp category=$CATEGORY"
136+
echo "=========================================="
137+
138+
local serve_args=(
139+
--model-path "$SERVE_MODEL"
140+
--host 0.0.0.0 --port "$PORT"
141+
--tp-size 4
142+
--trust-remote-code
143+
# The default trtllm_mha rejects MiMoV2's asymmetric K/V head dims.
144+
--attention-backend fa4
145+
--language-model-only
146+
--mem-fraction-static 0.8
147+
--reasoning-parser mimo
148+
--tool-call-parser mimo
149+
# MiMoV2 is not in SGLang's bundled-draft list, so name the target checkpoint.
150+
--speculative-algorithm EAGLE
151+
--speculative-draft-model-path "$SERVE_MODEL"
152+
--enable-multi-layer-eagle
153+
--speculative-num-steps "$mtp"
154+
--speculative-eagle-topk 1
155+
--speculative-num-draft-tokens "$((mtp + 1))"
156+
)
157+
158+
local server_log="$RESULTS_DIR/server_${mode}_mtp${mtp}.log"
159+
python3 -m sglang.launch_server "${serve_args[@]}" > "$server_log" 2>&1 &
160+
SERVER_PID=$!
161+
162+
if ! PYTHONSAFEPATH=1 PYTHONPATH="$repo_root${PYTHONPATH:+:$PYTHONPATH}" python3 -m infx.bench wait \
163+
--url "http://0.0.0.0:${PORT}/health" --pid "$SERVER_PID" --log "$server_log"; then
164+
echo " -> server failed to start (thinking=$mode mtp=$mtp), recording N/A"
165+
AL_RESULT["${mode}_${mtp}"]="N/A"
166+
cleanup_server
167+
return
168+
fi
169+
170+
local result_file="$RESULTS_DIR/speedbench_${mode}_mtp${mtp}.jsonl"
171+
python3 -m sglang.bench_serving \
172+
--backend sglang \
173+
--port "$PORT" \
174+
--model "$SERVE_MODEL" \
175+
--dataset-name speed-bench \
176+
--dataset-path "$CATEGORY_JSONL" \
177+
--speed-bench-output-len "$SPEEDBENCH_OUTPUT_LEN" \
178+
--num-prompts "$NUM_PROMPTS" \
179+
--max-concurrency "$CONCURRENCY" \
180+
--temperature "$TEMPERATURE" \
181+
--top-p "$TOP_P" \
182+
--disable-ignore-eos \
183+
--output-file "$result_file" \
184+
--output-details
185+
186+
local al
187+
al=$(python3 -c '
188+
import json, sys
189+
with open(sys.argv[1]) as f:
190+
al = json.loads(f.readlines()[-1]).get("accept_length")
191+
print(f"{al:.2f}" if al else "N/A")
192+
' "$result_file" 2>/dev/null || echo "N/A")
193+
echo " -> thinking=$mode MTP=$mtp AL=$al"
194+
AL_RESULT["${mode}_${mtp}"]="$al"
195+
196+
cleanup_server
197+
}
198+
199+
for mtp in $MTP_LIST; do
200+
run_cell on "$mtp"
201+
done
202+
203+
{
204+
echo "# Acceptance Length (AL) reference values measured with SPEED-Bench."
205+
echo "# dataset: $CATEGORY | temperature: $TEMPERATURE | top_p: $TOP_P | output_len: $SPEEDBENCH_OUTPUT_LEN"
206+
echo "# thinking_on: chat template default"
207+
echo "# draft: bundled MTP layers (multi-layer EAGLE, topk 1)"
208+
echo "# Measured on $MODEL_KEY ($GPU_NAME, SGLang MTP), per num_speculative_tokens."
209+
echo "# Auto-generated by benchmarks/single_node/speedbench/mimov2.6flash_fp4_b300_sglang.sh (speedbench-al.yml)."
210+
echo "#"
211+
echo "# key = num_speculative_tokens (MTP steps); value = golden AL"
212+
echo "${MODEL_KEY}:"
213+
echo " thinking_on:"
214+
for mtp in $MTP_LIST; do
215+
echo " $mtp: ${AL_RESULT[on_${mtp}]}"
216+
done
217+
} > "$OUT_YAML"
218+
219+
echo ""
220+
echo "=========================================="
221+
echo " SPEED-Bench AL matrix written to: $OUT_YAML"
222+
echo "=========================================="
223+
cat "$OUT_YAML"

0 commit comments

Comments
 (0)