Skip to content

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 curl command for readiness and generation requests.
  • Synchronized clocks for cross-host timestamp comparisons.
  • If you need per-span JIT counters, keep TOKENSPEED_JIT_COMPILE_CHECK enabled. The default is warn; error also 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.

  1. 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.

  2. Start the server with startup timing enabled. The SECONDS variable starts the enclosing measurement immediately before process launch:

    bash
    SECONDS=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.

  3. Poll the readiness endpoint, stopping early if the server process exits:

    bash
    until 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, inspect startup.log for the startup error.

  4. 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:

    bash
    request_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"
    fi

    A successful response contains a choices array. The example leaves the server running for steady-state checks; stop it with your usual launch procedure after you finish measuring.

  5. Confirm that the runtime logger emitted paired start and end records:

    bash
    grep 'startup_timing ' startup.log

    Each span emits one start and one end record; a phase name can appear in multiple spans. If the command returns no records, confirm that TOKENSPEED_STARTUP_TIMING=1 is present in each worker's environment and that you are reading the worker's log.

  6. 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.

  7. 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.

FieldRecordsMeaning
phaseStart and endInstrumented phase name.
eventStart and endSpan boundary: start or end.
pidStart and endProcess ID.
rankStart and endCaller-supplied rank, inherited by nested spans.
roleStart and endCaller-supplied role, inherited by nested spans.
span_idStart and endSpan ID, local to the process.
parent_idStart and endEnclosing span ID, or null for an outer span.
wall_time_nsStart and endWall-clock timestamp in nanoseconds.
duration_sEndInclusive host wall time in seconds.
statusEndResult: ok or error.
error_typeEndException class name, or null on success.
jit_compilesEndChange in the process-wide startup compilation count, or null.
jit_compile_sEndChange in the process-wide startup compilation seconds, or null.

Apply these rules when comparing records:

  • Group records by host and pid, and then match start and end records by span_id. Use parent_id to reconstruct nesting.
  • Compare wall_time_ns values across hosts only when the hosts' clocks are synchronized.
  • Do not sum nested duration_s values: 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, from graph.capture, the final capture, before optimizing either phase.
  • Inspect status and error_type on 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.

PhaseBoundary
scheduler.initEnclosing scheduler initialization, from CUPTI preparation through event-loop construction
model.configModel configuration resolution for the target or draft model
distributed.initDevice and distributed initialization
weights.target, weights.draftTarget or draft model-runner construction, including loading
weights.allocateDefault loader model construction
weights.read_copyDefault loader iterator consumption and weight assignment
weights.postprocessDefault loader quantization and other post-load transforms
weights.post_quant_warmupDefault loader post-quantization warmup
multimodal.initApplicable multimodal runtime preparation
communication.prepareTarget and draft persistent communication preparation
model.post_initRegistered post-model-init hooks
kv.buildAttention backend and key-value (KV) pool construction, including rebinds
executor.initExecutor construction
kernels.autotuneStartup kernel compilation warmup and optional tactic selection
graph.probe_rebindOptional partial capture probe, release, and KV rebind
kernels.rewarmAMD kernel warmup on the final pools after the graph probe and rebind
graph.captureFinal serving graph capture and post-capture cleanup
drafter.profileOptional 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.

TokenSpeed documentation