Measure startup timing
Use TOKENSPEED_STARTUP_TIMING=1 to measure scheduler initialization phases with startup_timing JSON records. Keep these phase measurements separate from HTTP readiness and first-request latency. Startup timing is off by default and adds no device synchronization or distributed collectives.
Prerequisites
- A working TokenSpeed launch command and access to the model checkpoint. For command syntax, see Launching a server.
- Runtime logs from every rank and host that you want to compare.
- The
curlcommand for readiness and generation requests. - Synchronized clocks for cross-host timestamp comparisons.
- If you need per-span JIT counters, keep
TOKENSPEED_JIT_COMPILE_CHECKenabled. The default iswarn;erroralso enables the monitor.
Measure startup and first-request latency
The following procedure uses Bash and writes startup.log in the current directory. Replace MODEL with your checkpoint path or model ID, SERVED_MODEL_NAME with the API model name, and 8000 with your server's port. Add your existing serving arguments to the launch command, and keep those arguments unchanged between compared runs. The example measures wall time at one-second resolution.
Hold the source, model revision, image, hardware, parallelism, and serving parameters fixed. Record checkpoint cache and host page-cache state separately from compile-cache state. Exclude image pulls, package installation, and downloads from the server startup measurement. Do not clear a shared host's page cache.
Start the server with startup timing enabled. The
SECONDSvariable starts the enclosing measurement immediately before process launch:bashSECONDS=0 TOKENSPEED_STARTUP_TIMING=1 tokenspeed serve MODEL \ --served-model-name SERVED_MODEL_NAME \ --host 127.0.0.1 \ --port 8000 \ >startup.log 2>&1 & server_pid=$!For multi-process launches, save each worker's records with the worker's host identity.
Poll the readiness endpoint, stopping early if the server process exits:
bashuntil curl --fail --silent \ http://127.0.0.1:8000/readiness >/dev/null; do if ! kill -0 "$server_pid" 2>/dev/null; then wait "$server_pid" exit 1 fi sleep 1 done printf 'Launch to readiness: %d s\n' "$SECONDS"When the server is ready, the endpoint returns HTTP
200 OK, and the final command prints the launch-to-readiness interval. If the process exits, inspectstartup.logfor the startup error.Immediately send one generation request without resetting
SECONDS. The response and the two printed intervals distinguish first-request latency from the total launch-to-first-generation measurement:bashrequest_start_s=$SECONDS if curl --fail --silent --show-error \ http://127.0.0.1:8000/v1/chat/completions \ -H 'Content-Type: application/json' \ -d '{ "model": "SERVED_MODEL_NAME", "messages": [ {"role": "user", "content": "Reply with OK."} ], "max_tokens": 1 }'; then printf 'First generation request: %d s\n' \ "$((SECONDS - request_start_s))" printf 'Launch to first successful generation: %d s\n' "$SECONDS" fiA successful response contains a
choicesarray. The example leaves the server running for steady-state checks; stop it with your usual launch procedure after you finish measuring.Confirm that the runtime logger emitted paired
startandendrecords:bashgrep 'startup_timing ' startup.logEach span emits one
startand oneendrecord; a phase name can appear in multiple spans. If the command returns no records, confirm thatTOKENSPEED_STARTUP_TIMING=1is present in each worker's environment and that you are reading the worker's log.Exercise representative steady-state requests and inspect the serving logs for JIT compilations. Keep the serving JIT checks enabled. Readiness alone does not validate the optimization: moving compilation into serving is not an equivalent startup improvement.
To isolate cache effects, repeat the procedure with compile-cache-cold and compile-cache-warm runs. Preserve each backend's cache directory across containers, and use that backend's diagnostics to establish cache hits.
Interpret startup timing records
Use the following fields to match records and inspect phase durations.
| Field | Records | Meaning |
|---|---|---|
phase | Start and end | Instrumented phase name. |
event | Start and end | Span boundary: start or end. |
pid | Start and end | Process ID. |
rank | Start and end | Caller-supplied rank, inherited by nested spans. |
role | Start and end | Caller-supplied role, inherited by nested spans. |
span_id | Start and end | Span ID, local to the process. |
parent_id | Start and end | Enclosing span ID, or null for an outer span. |
wall_time_ns | Start and end | Wall-clock timestamp in nanoseconds. |
duration_s | End | Inclusive host wall time in seconds. |
status | End | Result: ok or error. |
error_type | End | Exception class name, or null on success. |
jit_compiles | End | Change in the process-wide startup compilation count, or null. |
jit_compile_s | End | Change in the process-wide startup compilation seconds, or null. |
Apply these rules when comparing records:
- Group records by host and
pid, and then matchstartandendrecords byspan_id. Useparent_idto reconstruct nesting. - Compare
wall_time_nsvalues across hosts only when the hosts' clocks are synchronized. - Do not sum nested
duration_svalues: child spans overlap their inclusive parent spans. Use the slowest rank and the enclosing wall-clock measurements to identify the critical path. - Treat the values as host timings, not GPU kernel durations. The instrumentation adds no device synchronization or distributed collectives. Host timing includes existing waits but does not wait for newly enqueued GPU work.
- Distinguish
graph.probe_rebind, the partial graph-memory probe, fromgraph.capture, the final capture, before optimizing either phase. - Inspect
statusanderror_typeon failed runs. Startup errors propagate unchanged.
Interpret JIT compilation counters
With the JIT compile monitor enabled, end records contain jit_compiles and jit_compile_s: changes in the monitor's startup counters for Triton and CuTe DSL compilations over the span. A disabled monitor produces null, not zero. These are process-wide, inclusive observations, not a cache-hit ratio or total backend compilation time. In particular, zero compilations does not establish a FlashInfer or DeepGEMM cache hit.
When startup reuses cached FlashInfer tactics, FlashInfer still validates the lookup's required runner coverage and profile geometry.
Look up startup phases
The scheduler can record the following phases. Your configuration determines which spans appear.
| Phase | Boundary |
|---|---|
scheduler.init | Enclosing scheduler initialization, from CUPTI preparation through event-loop construction |
model.config | Model configuration resolution for the target or draft model |
distributed.init | Device and distributed initialization |
weights.target, weights.draft | Target or draft model-runner construction, including loading |
weights.allocate | Default loader model construction |
weights.read_copy | Default loader iterator consumption and weight assignment |
weights.postprocess | Default loader quantization and other post-load transforms |
weights.post_quant_warmup | Default loader post-quantization warmup |
multimodal.init | Applicable multimodal runtime preparation |
communication.prepare | Target and draft persistent communication preparation |
model.post_init | Registered post-model-init hooks |
kv.build | Attention backend and key-value (KV) pool construction, including rebinds |
executor.init | Executor construction |
kernels.autotune | Startup kernel compilation warmup and optional tactic selection |
graph.probe_rebind | Optional partial capture probe, release, and KV rebind |
kernels.rewarm | AMD kernel warmup on the final pools after the graph probe and rebind |
graph.capture | Final serving graph capture and post-capture cleanup |
drafter.profile | Optional drafter startup profiling after graph capture, nested in graph.capture |
Detailed weight phases cover the default loader. Other loaders still have the enclosing weights.target or weights.draft span. weights.read_copy includes any lazy checkpoint resolution and model-specific transforms that load_weights performs. It does not isolate disk I/O from host-to-device copies. Optional phases can be near-zero no-ops.
Account for measurement boundaries
The startup spans do not cover the following work:
- Launcher imports.
- Process spawning.
- Frontend tokenizer initialization.
- The encode-only loop.
- The final data-parallel barrier.
- HTTP readiness.
Use the externally measured launch-to-readiness and launch-to-first-successful-generation intervals for those boundaries. scheduler.init is not an end-to-end server startup metric.