collect-workloads-bench
Skill288 starsChanged 7 months agoApache-2.0View on GitHub
Collect real workloads using examples/sglang_bench/bench_serving.py as the server launcher. This is an improved alternative to collect_workloads.py sglang that: Use when: - The model is listed in examples/sglang_bench/model_configs.json (or can be added) - You need a paged prefill collection (add --disable-radix-cache flag; it's already present for qwen3-235b-a22b) - You need TP/EP parallelism without hand-coding server flags Edit examples/sglang_bench/model_configs.json to add/confirm entry: For paged prefill: always include --disable-radix-cache and --enable-deterministic-inference. Run one batch size at a time to avoid node overload. After…
- Deletes or force-pushes
- Commits and pushes
In this repository10 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- add-reference-testsSkill
- clone-reposSkill
- collect-workloadsSkill
- discover-modelsSkill
- extract-kernel-definitionsSkill
- onboard-modelSkill
- submit-onboarding-prsSkill
- track-modelsSkill
- validate-datasetSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 39
Run one batch size at a time to avoid node overload.
- Very specific: line 42
Multi-node auto-detection: when model config TP > local GPU count (e.g.
- Very specific: line 142
Only launch multi-node if needed_nodes > 1 — peer nodes are looked up from SLURM/--peer-node-addr only when needed
- Very specific: line 167
Use --replace only on the first run if you want to start fresh.
- Distinctive: line 210
Delete the old (wrong) definition JSON
- Very specific: line 211
Update any sibling definitions for the same model (e.g.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
collect-workloads-bench
Collect real workloads using examples/sglang_bench/bench_serving.py as the server
launcher. This is an improved alternative to collect_workloads.py sglang that:
- Pulls model-specific server flags (TP, EP, attention-backend, etc.) from
examples/sglang_bench/model_configs.json - Drives the server with random or ShareGPT prompts (default
--dataset random, controlled via--isl/--osl) for diverse(batch_size, kv_len)coverage - Handles server lifecycle cleanly via
popen_launch_server/kill_process_tree - Still uses the same FlashInfer Level-10 tensor dump +
sanitize_dumps.pypipeline
When to use
Use when:
- The model is listed in
examples/sglang_bench/model_configs.json(or can be added) - You need a paged prefill collection (add
--disable-radix-cacheflag; it's already present for qwen3-235b-a22b) - You need TP/EP parallelism without hand-coding server flags
Workflow
1. Ensure model is in model_configs.json
Edit examples/sglang_bench/model_configs.json to add/confirm entry:
"<model-key>": {
"server_flags": [
"--trust-remote-code",
"--attention-backend", "flashinfer",
"--tp-size", "<N>",
"--disable-radix-cache", // add for paged-prefill definitions
"--disable-cuda-graph"
]
}For paged prefill: always include --disable-radix-cache and --enable-deterministic-inference.
2. Set FlashInfer Level-10 dump env vars and run bench_serving.py (incremental)
Run one batch size at a time to avoid node overload. After each run, sanitize to collect 2–3 workloads, then delete the dump dir before the next run.
Multi-node auto-detection: when model config TP > local GPU count (e.g. TP=8 config but
only 4 GPUs visible via nvidia-smi), bench_serving.py automatically triggers multi-node
mode. Peer nodes are discovered from SLURM_JOB_ID; workers are launched via SSH.
FLASHINFER dump env vars are forwarded only to the head node (rank 0) — workers don't dump.
Passwordless SSH between allocated nodes is required (standard in SLURM environments).
DUMP_DIR=/tmp/flashinfer_dumps_<name>
TRACE_DIR=<trace_dir>
LOG=/tmp/bench_serving_<name>.log
cd /home/averyh/flashinfer-bench
for BS in 1 64 128 256; do
echo "=== Collecting batch_size=$BS ===" | tee -a $LOG
rm -rf $DUMP_DIR && mkdir -p $DUMP_DIR
tools/gpu-lock --gpus <N> --exec-timeout 1800 -- \
conda run -n flashinfer_bench env \
FLASHINFER_LOGLEVEL=10 \
FLASHINFER_DUMP_DIR=$DUMP_DIR \
FLASHINFER_DUMP_SAFETENSORS=1 \
FLASHINFER_DUMP_INCLUDE="<fi_include_pattern>,<fi_plan_pattern>" \
FLASHINFER_DUMP_EXCLUDE="*.__init__" \
FLASHINFER_DUMP_MAX_COUNT=100 \
FLASHINFER_DUMP_MAX_SIZE_GB=2 \
FLASHINFER_USE_CUDA_NORM=1 \
FLASHINFER_DISABLE_VERSION_CHECK=1 \
SGLANG_SKIP_SGL_KERNEL_VERSION_CHECK=1 \
SGLANG_ENABLE_TP_MEMORY_INBALANCE_CHECK=0 \
python examples/sglang_bench/bench_serving.py \
--model <model-key> \
--model-path <model-path> \
--batch-sizes $BS \
--num-batches 4 \
--disable-cuda-graph \
2>&1 | tee -a $LOG
# Kill any lingering processes (including remote workers if multi-node)
pkill -f bench_serving.py || true
pkill -f sglang.launch_server || true
# Sanitize (no --replace so workloads from previous batch sizes are kept)
conda run -n flashinfer_bench python scripts/sanitize_dumps.py \
--dump-dir $DUMP_DIR \
--definitions <def_name> \
--flashinfer-trace-dir $TRACE_DIR
# Delete dumps before next run to free disk space
rm -rf $DUMP_DIR
doneMulti-node flags (bench_serving.py)
| Flag | Default | Purpose |
--peer-node-addr HOST [HOST ...] | auto (SLURM) | Override peer node hostname(s)/IP(s) |
--dist-init-port PORT | 20010 | PyTorch dist rendezvous port (must differ from --port) |
--no-multinode | off | Disable auto multi-node even when config TP > local GPUs |
--conda-env ENV | $CONDA_DEFAULT_ENV | Fallback: conda env for peer SSH (only used when sys.executable is a relative path, i.e. non-NFS clusters) |
Peer worker SSH environment: on NFS-shared clusters (e.g. SLURM where /home is shared),
bench_serving.py passes sys.executable (absolute path) as the Python binary on the remote
node — no conda activation needed. It also passes:
CUDA_HOME=<conda_prefix>:deep_gemmchecks this first; conda prefix contains nvcc/include/libPATH=<conda_bin>:/usr/...: JIT build tools likeninja(needed by SGLang's JIT kernels) are foundCPATH=<nvidia_include_dirs>: pip-installed nvidia packages (nvidia-cuda-nvrtc-cu13etc.) putnvrtc.hand other CUDA headers undersite-packages/nvidia/cuXX/include. These are not on the system compiler's default include path, but FlashInfer's TRT-LLM FMHA JIT kernel (fmha_gen)#includes <nvrtc.h>. Without CPATH, the peer node's JIT compilation fails withnvrtc.h: No such file or directory. The head node's SGLang server also gets CPATH set via theenvdict passed topopen_launch_server.FLASHINFER_WORKSPACE_BASE=/tmp/flashinfer_jit_peer: redirects the peer node's FlashInfer JIT cache to local/tmp. Without this, both head and peer nodes try to acquire the same NFS-pathFileLock(at~/.cache/flashinfer/.../cached_ops/tmp/fmha_gen.lock), causingOSError: [Errno 116] Stale file handleon the peer.
SSH sessions don't inherit the conda env's CUDA_HOME, PATH, or CPATH, and csh/tcsh don't
support inline KEY=value cmd syntax, so env (an external binary) is used for portability.
The --conda-env flag is only a fallback for non-NFS setups where sys.executable resolves to
a relative path.
Pre-compile TRT-LLM FMHA on head node before first run (optional but speeds up server startup):
# Warm the NFS JIT cache so head-node TP ranks don't all compile simultaneously
CPATH="$(python -c "import sys,pathlib; print(':'.join(str(p) for p in pathlib.Path(sys.prefix).glob('lib/python*/site-packages/nvidia/cu*/include')))")" \
python -c "from flashinfer.prefill import get_trtllm_gen_fmha_module; get_trtllm_gen_fmha_module()"Two independent decisions:
- What TP to use — always from model config:
- Config has
--tp-size N→ use N as-is - Config has no
--tp-size→ fall back to local GPU count - Config TP is never overridden
- Config has
- How many nodes to use — derived from TP and local GPU count:
needed_nodes = ceil(config_tp / local_gpus)- Only launch multi-node if
needed_nodes > 1— peer nodes are looked up from SLURM/--peer-node-addronly when needed
Examples (4 GPUs per node, 2-node SLURM allocation):
| Config TP | needed_nodes | Launch mode |
--tp-size 4 | 1 | Single-node, TP=4 (fits on one node) |
--tp-size 8 | 2 | Multi-node, TP=8 (4 GPUs × 2 nodes) |
| (no flag) | 1 | Single-node, TP=4 (local GPU count fallback) |
Manual peer override (when not in SLURM or peer auto-detection fails):
SLURM_JOB_NODELIST=head-node,peer-node \
python examples/sglang_bench/bench_serving.py \
--model deepseek-v3 --model-path /nfs/path/to/model \
--peer-node-addr peer-node \
--dist-init-port 20010 \
...Model path must be NFS-accessible on all nodes: --model-path is passed directly to the
SGLang server on each node. Local paths (e.g. /data/...) that exist only on one node will
cause HFValidationError or FileNotFoundError on the peer. Use NFS-shared paths (e.g.
/home/user/models/...) or a shared file system mount that exists on all allocated nodes.
Note: Omit --replace during the loop so each batch size's workloads are appended.
Use --replace only on the first run if you want to start fresh.
FLASHINFER_DUMP_INCLUDE pattern — always include both plan* and run*:
- For paged prefill:
"BatchPrefillWithPagedKVCacheWrapper.plan*,BatchPrefillWithPagedKVCacheWrapper.run*" - For paged decode:
"BatchDecodeWithPagedKVCacheWrapper.plan*,BatchDecodeWithPagedKVCacheWrapper.run*"
Including plan* alongside run* is required so sanitize_dumps.py can pair each run() dump with
its plan() dump — this enables automatic skipping of const-axis checks on tensors not captured
in the run() dump (k_cache, v_cache). If you only captured run* dumps, add
--skip-const-axis-check to sanitize_dumps.py.
3. Post-process dumps with sanitize_dumps.py
conda run -n flashinfer_bench python scripts/sanitize_dumps.py \
--dump-dir $DUMP_DIR \
--definitions <def_name> \
--flashinfer-trace-dir <trace_dir> \
--replaceIf sanitize reports 0 workloads with const axis warnings, a definition constant is wrong. Diagnose and fix with:
# Inspect actual tensor shapes from a dump
from pathlib import Path
import safetensors.torch, json
dump_dir = Path(DUMP_DIR)
first = sorted(dump_dir.iterdir())[0]
inputs = safetensors.torch.load_file(first / "inputs.safetensors")
for k, v in inputs.items():
print(f" {k}: {v.shape} {v.dtype}")
meta = json.loads((first / "metadata.jsonl").read_text().splitlines()[0])
print("tensor_details:", json.dumps(meta.get("tensor_details", {}), indent=2))Then update the definition JSON to match the actual shapes:
- Fix the const axis value (e.g.
head_dim: 64 → 128) - Rename the definition file/name to reflect the corrected value (e.g.
_d64_→_d128_) - Fix the
assertin thereferenceimplementation - Rename the workload
.jsonland blob dir to match the new definition name - Delete the old (wrong) definition JSON
- Update any sibling definitions for the same model (e.g.
_ps1/_ps64variants share the samehead_dim) - Re-run
sanitize_dumps.pywith the corrected definition name
4. Verify NOT synthetic
python3 -c "
import json
lines = open('<trace_dir>/workloads/gqa_paged/<def_name>.jsonl').readlines()
entries = [json.loads(l) for l in lines]
axes = list(entries[0]['workload']['axes'].keys())
print('axes:', axes, '| total:', len(entries))
# Check for diversity - look at first axis that varies
first_key = axes[0]
vals = sorted(set(e['workload']['axes'][first_key] for e in entries))
print(f'{first_key} unique:', len(vals), '| sample:', vals[:10])
if len(vals) < 5: print('WARNING: low diversity'); exit(1)
print('REAL workloads OK')
"5. Run baseline eval + commit
cd /home/averyh/flashinfer-bench
conda run -n flashinfer_bench python -m flashinfer_bench run \
--local <trace_dir> --definitions <def_name> --save-results \
--warmup-runs 0 --iterations 1 --num-trials 1Then commit and force-push to HF PR2:
cd <trace_dir>
git add workloads/ blob/ traces/ solutions/
git commit -m "workloads: SGLang-collected <def_name> via bench_serving.py"
git push origin HEAD:refs/pr/<pr2_num> --forcePost the bench_serving.py log to the HF PR2 discussion under ## SGLang Collection Log.
Notes
- For
--enable-deterministic-inference(paged prefill): add it to the model'sserver_flagsinmodel_configs.json, or pass it via bench_serving.py'sserver_argslist - The existing
collect_workloads.pydump-processing pipeline (sanitize_dumps.py) is unchanged bench_serving.pypasses**os.environto the server process, so allFLASHINFER_*vars set in the outer shell are inherited by the SGLang server automatically
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

