Skip to content

Commit 04013c8

Browse files
feat: add CPU benchmark tool with context length sweep
Update README.md
1 parent fe6c481 commit 04013c8

19 files changed

Lines changed: 684 additions & 76 deletions

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,12 @@ autotuner.log
4040
/models/
4141
# Keep source model adapters tracked
4242
!tools/mllm-llm-benchmark/models/
43+
44+
# ---- bench artifacts (generated / local) ----
45+
perf.data
46+
perf.data.old
47+
bench_context/
48+
snapshots/
49+
*.bak
50+
*.bak.*
51+
bench_mem_context.csv

bench_artifacts/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# [Bench] CPU Context Sweep Benchmark
2+
3+
CPU-only benchmark for measuring prefill/decode latency and memory
4+
across context lengths (256–4096) on x86_64.
5+
6+
`sweep_context_v2.sh` runs the benchmark at each context length in two
7+
modes (decode_heavy, prefill_ttft) and records: TTFT, prefill latency,
8+
decode per-token latency, peak RSS, KV cache estimate, and GEMM shapes
9+
(via `MLLM_MATMUL_SHAPE_LOG=1`).
10+
11+
- `data/` — raw CSVs
12+
- `plots/` — generated figures
13+
14+
## Quick Repro (x86_64 example)
15+
16+
```bash
17+
# 1. Build
18+
cmake -S . -B build -G Ninja \
19+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
20+
-DBUILD_TESTING=OFF \
21+
-DMLLM_ENABLE_TOOLS=ON \
22+
-DCMAKE_CXX_FLAGS="-march=native"
23+
24+
cmake --build build -j"$(nproc)"
25+
26+
# 2. Run Context Sweep & View Shape Log
27+
chmod +x sweep_context_v2.sh
28+
export BIN=./build/bin/mllm-llm-benchmark
29+
export MLLM_MATMUL_SHAPE_LOG=1
30+
31+
# Run a quick test
32+
./sweep_context_v2.sh
33+
```
34+
35+
Outputs:
36+
37+
* `bench_context/context_sweep_v2.csv`
38+
* <img width="2879" height="1366" alt="image" src="https://github.com/user-attachments/assets/46a4cb2b-6a22-4fba-81e2-dccf41bf4357" />
39+
* <img width="2837" height="1437" alt="image" src="https://github.com/user-attachments/assets/3468b710-c7c8-4bab-bfe6-afaf6826d5ed" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ts,git,arch,model,mode,cl,pp,tg,threads,ttft_ms,prefill_ms,decode_ms,decode_ms_per_tok,peak_rss_kb,kv_est_kb
2+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,prefill_ttft,256,254,2,8,8476.504,8476.504,169.632,84.816,4207436,5632
3+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,decode_heavy,512,256,256,8,7719.204,7719.2046,173.43939,0.6774976171875,4281236,11264
4+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,prefill_ttft,512,510,2,8,18217.402,18217.402,179.518,89.759,4364668,11264
5+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,decode_heavy,1024,768,256,8,28733.297,28733.295,172.73177,0.6747334765625,4756888,22528
6+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,prefill_ttft,1024,1022,2,8,50484.66,50484.66,199.94199,99.970995,4841960,22528
7+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,decode_heavy,2048,1792,256,8,135609.38,135609.38,187.38985,0.7319916015625,5932308,45056
8+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,prefill_ttft,2048,2046,2,8,149802.72,149802.72,259.102,129.551,6221464,45056
9+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,decode_heavy,4096,3840,256,8,462259.72,462259.75,224.40271,0.8765730859375,7343064,90112
10+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,prefill_ttft,4096,4094,2,8,523101.5,523101.56,1793.434,896.717,7363988,90112
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ts,git,arch,model,mode,cl,pp,tg,threads,ttft_ms,prefill_ms,decode_ms,decode_ms_per_tok,peak_rss_kb,kv_est_kb,peak_rss_gb,kv_est_mb
2+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,decode_heavy,512.0,256.0,256.0,8.0,7719.204,7719.2046,173.43939,0.6774976171875,4281236.0,11264.0,4.082904815673828,11.0
3+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,decode_heavy,1024.0,768.0,256.0,8.0,28733.297,28733.295,172.73177,0.6747334765625,4756888.0,22528.0,4.536521911621094,22.0
4+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,decode_heavy,2048.0,1792.0,256.0,8.0,135609.38,135609.38,187.38985,0.7319916015625,5932308.0,45056.0,5.657489776611328,44.0
5+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,decode_heavy,4096.0,3840.0,256.0,8.0,462259.72,462259.75,224.40271,0.8765730859375,7343064.0,90112.0,7.002891540527344,88.0
6+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,prefill_ttft,256.0,254.0,2.0,8.0,8476.504,8476.504,169.632,84.816,4207436.0,5632.0,4.012523651123047,5.5
7+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,prefill_ttft,512.0,510.0,2.0,8.0,18217.402,18217.402,179.518,89.759,4364668.0,11264.0,4.162471771240234,11.0
8+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,prefill_ttft,1024.0,1022.0,2.0,8.0,50484.66,50484.66,199.94199,99.970995,4841960.0,22528.0,4.617652893066406,22.0
9+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,prefill_ttft,2048.0,2046.0,2.0,8.0,149802.72,149802.72,259.102,129.551,6221464.0,45056.0,5.933250427246094,44.0
10+
2026-02-02T17:28:18+08:00,b17c8f55eea8,x86_64,tiny_llama,prefill_ttft,4096.0,4094.0,2.0,8.0,523101.5,523101.56,1793.434,896.717,7363988.0,90112.0,7.022846221923828,88.0
50.6 KB
Loading
63.9 KB
Loading
46.4 KB
Loading
50.8 KB
Loading
55.9 KB
Loading
52.7 KB
Loading

0 commit comments

Comments
 (0)