The shortest path from a clean checkout to a per-launch report, a Perfetto timeline, and an A/B diff on vLLM.
Run inside the Python environment where vllm and CUDA-enabled torch are installed (with nvcc
on PATH or CUDA_HOME set):
pip install -e .If you also plan to use the access-trace tools (dataflow, dead-across, traffic,
perturb-plan, perturb-report), install the optional numpy extra:
pip install -e '.[dataflow]'ledger buildThis compiles capture/libledger.so against your CUDA toolkit and caches it under
~/.cache/ledger/build/ (printing the full path). Pass --access (and optionally --arch <sm>)
only if you also need the Compute Sanitizer access tracer.
CUPTI is looked up in the toolkit and, failing that, in pip-installed NVIDIA wheels
(site-packages/nvidia/*/{include,lib}), which is where the official vLLM images keep it. In a
container, build where the driver is visible (--gpus ...): the library links against libcuda.so.1.
Make sure no other process is using the GPU — ledger ceilings checks nvidia-smi and refuses
to measure if another CUDA context is active, so noisy numbers do not get cached.
ledger ceilingsThis runs bench/bwtest.cu and bench/flops.py, prints the measured DRAM read bandwidth and GEMM
peaks, and caches them in ~/.cache/ledger/ceilings-<device>.json. Subsequent ledger analyze,
ledger steps, ledger diff, ledger report, and ledger perfetto calls load this cache
automatically. Use ledger ceilings --refresh to re-measure.
To analyze a capture from a GPU that is not at hand, or from one the benchmarks above cannot run on
(Ascend), take the ceilings from that GPU's VirtualGPU
profile. Download the JSON file from its
profiles/ directory and run:
ledger ceilings --from-profile gb10.jsonThis needs no GPU. It caches the profile's DRAM read bandwidth and its bf16 MMA rate on all SMs
under the profile's SKU; pass --device <name> if your captures record another name (the device
in their run.json). Two things differ from measured ceilings:
- The rates come from microbenchmarks, not from real GEMMs, so they are higher (on GB10: 263.6 GB/s and 124.7 TFLOP/s bf16, against about 239 GB/s and 103 TFLOP/s measured here), and every launch reads as further from its ceiling.
- Profiles list no FP8, NVFP4 or INT8 rates. Unless you pass
--peak-tflops, launches in those precisions get no compute floor: decode-size ones are judged against the bandwidth ceiling only, and ones that multiply more than 64 rows are left out of the findings.
Reports that use such a cache name the profile on stderr.
ledger profile --steps 20 --out run1 -- --model <model> [vLLM args...]--out must be a new or empty directory. Optional flags before --: --steps (default 40),
--batch (default 1), --prompt-tokens (default 0), and --prefill (default 0). Everything after
-- is passed straight to vLLM.
When the run finishes, run1/ contains the raw CUPTI capture, run1/vllm.log, the combined
analyze + steps report in run1/report.md, and the Perfetto timeline in run1/trace.json
(printing the URL to open it).
Open run1/report.md and start with ## Findings at the top: it ranks up to the five largest
costs in ms per step, each as an upper bound on what fixing it could save. Follow the section name
in parentheses for the full table and evidence. See Reading Ledger Reports
for how to interpret every section and confirm a finding.
ledger profile already wrote run1/trace.json. Open ui.perfetto.dev
and load run1/trace.json to inspect the Steps, per-CUDA Stream, and Memcpy tracks.
To export a timeline from an existing capture later (for example, one captured with vllm serve or
another engine):
ledger perfetto run1 --out run1.jsonledger perfetto fills in --ceiling-gbps from the GPU cache automatically when available (pass
--ceiling-gbps <measured> explicitly on a machine without a cache to include per-launch gbps,
pct_ceiling, and partial-read filtering).
After changing a kernel, backend, or flag, capture a second run and diff the two:
ledger profile --steps 20 --out run2 -- --model <model> [updated vLLM args...]
ledger diff run1 run2ledger diff uses the cached ceilings, estimates run-to-run clock/power-cap drift from shared
launch groups, and lists only the groups that moved beyond that drift.
After upgrading or modifying Ledger, you do not need to re-run the GPU to refresh the report:
ledger report run1 [--out path/to/report.md]ledger report re-runs analyze and steps over the saved capture using the cached ceilings
(or explicit --ceiling-gbps / --peak-tflops) and writes <capture>/report.md by default.
pip install -e . registers ledger.vllm_plugin:register under the vllm.general_plugins entry
point. When LEDGER_OUT is unset it does nothing. To capture a window from a live vllm serve
instance:
LEDGER_OUT=out LEDGER_GRAPH_WINDOW=<skip>:<take> LD_PRELOAD=$(ledger build) \
vllm serve <model> [vLLM args...]Send requests while the graph-launch window (<skip> skipped, <take> captured) is open, and keep
the server running until the window closes. Kernels still running when it closes come back without
timestamps; the analysis drops them and says how many. Each GPU worker exports
regions-<pid>.json, attention-<pid>.json, and run.json after warm-up and emits a step marker
at every execute_model call.
Then write the report with ledger report out (or ledger analyze out): it counts steps from the
markers automatically. On a GB10 with vLLM main, Qwen3.8-27B NVFP4 with MTP,
LEDGER_GRAPH_WINDOW=300:200 and vllm bench serve sending 32 requests at concurrency 4 gave a
window of 49 steps.
Because serving batch size varies from step to step, run.json has no fixed batch or steps, so
the Compute section (which needs M) applies only when steps have a known shape.
With --tensor-parallel-size or --pipeline-parallel-size above 1, add
VLLM_WORKER_MULTIPROC_METHOD=spawn. vLLM forks its GPU workers by default, and CUPTI records
nothing in a process forked from the one where the capture library started; the plugin says so on
stderr when it happens.
Every worker writes its own files into out, and LEDGER_GRAPH_WINDOW counts graph launches in
each worker separately. ledger report out then writes one report per worker,
out/pid-<pid>/report.md; analyze, steps, perfetto, transfers and diff take those
pid-<pid> directories. With pipeline parallelism a worker is stepped for every batch in flight, so
most of its step markers carry no forward pass: the analysis folds those into the step before them,
and a step is one forward pass on that worker.
Install Ledger in the same environment as SGLang. The plugin uses the SGLang Runtime
general plugin entry point (sglang.srt.plugins, verified with SGLang 0.5.23) and only
activates when LEDGER_OUT is set. For a single-GPU server with CUDA graphs enabled:
ledger build
capture_lib=$(ledger build)
LEDGER_OUT=sglang-out LEDGER_GRAPH_WINDOW=16:32 LD_PRELOAD="$capture_lib" \
sglang serve --model-path <model>Use a fresh output directory. Send requests with enough generated tokens to reach the end of the graph-launch window while the server is still running. Adjust the skip and length for your workload. Each CUDA worker writes a parameter and KV pool map after initialization. Token-major KV views also include per-layer addresses and bytes per token. The target model emits one step marker per forward, including when it replays a CUDA graph.
Run ledger report sglang-out and ledger perfetto sglang-out --out sglang-out/trace.json to
inspect the capture. The report uses the measured bandwidth cache or --ceiling-gbps.
Any CUDA program works with the capture library directly:
- Preload
libledger.so(LD_PRELOAD=$(ledger build) LEDGER_OUT=out). - Bracket the window with
cudaProfilerStart/cudaProfilerStop, or setLEDGER_GRAPH_WINDOW=<skip>:<take>if the program never calls the profiler API. For programs thatfork()one process per GPU, setLEDGER_INIT_IN_CHILD=1so each child starts CUPTI itself (CUPTI worker threads do not survivefork()). - Export the memory map as
out/regions-<pid>.json(a list of{kind, name, addr, size, shape, dtype}; seeledger/vllm_regions.py).
For a Sibyl replay, which preserves recorded addresses:
ledger sibyl-regions <recording>/ranges-rank0-<pid>.json out
LD_PRELOAD=$(ledger build) LEDGER_OUT=out LEDGER_GRAPH_WINDOW=8:44 <replay program> ...To analyze an Ascend NPU run exported with msprof --export=on, import its op_summary_*.csv
(and optional task_time_*.csv), aclmdlRIDebugPrint graph dumps (--graph), and weight / KV
descriptor maps (--weights, --draft-weights, --owners, or --regions):
ledger ascend-import <msprof PROF_* dir> out \
--graph capture.json --graph draft-graph.json \
--weights target_weights.json --draft-weights draft_weights.json --owners owners.json \
--device "Ascend 910B1" --sms 24 --steps 1 --batch 8 --draft-tokens 7
ledger analyze out --ceiling-gbps 1350 --peak-tflops bf16=320,int8=640 --out out/report.md
# with a VirtualGPU profile of the same NPU model, the ceilings can come from it instead:
# ledger ceilings --from-profile ascend910b3.json --device "<the --device given above>"
ledger transfers out --steps 1 --out out/transfers.md
ledger perfetto out --ceiling-gbps 1350 --out out/trace.jsonmsprof does not record the size or direction of MEMCPY_ASYNC tasks: ledger transfers reports
their times, but the copies are imported with 0 bytes and labelled DtoD.