Skip to content

vllm.v1.worker.iteration_timing

Non-blocking GPU timing of engine iterations.

An iteration is timed between two CUDA events recorded on the output worker's stream: one before execute_model, one after sample_tokens returns. The interval covers the model forward pass, sampling and speculative drafting, including host submission gaps.

The end event is often still pending when the iteration's own output is built, so a finished timing leaves the worker as a record with the first reply built after its end event has completed: the iteration's own output, a later step's output or a dummy batch. No step waits for a timing, so the last iterations before the engine goes idle are reported once it steps again.

Classes:

  • IterationTimer –

    Times iterations on the calling thread's CUDA stream.

Functions:

IterationTimer

Times iterations on the calling thread's CUDA stream.

Only the worker's main thread uses it, and it never waits for the GPU.

Methods:

  • start –

    Begin an iteration, dropping any that never finished.

  • take_ready –

    Pop the oldest iterations whose GPU work has completed.

start(details, is_dummy=False)

Begin an iteration, dropping any that never finished.

Without a scheduling snapshot the iteration is not timed.

take_ready()

Pop the oldest iterations whose GPU work has completed.

_TimedIteration dataclass

Methods:

  • read –

    Read the elapsed time. Both events must have completed.

read()

Read the elapsed time. Both events must have completed.

_WithIterationRecords

Bases: AsyncModelRunnerOutput

A step's output that also carries completed iteration records.

_drop_on_cuda_error()

Timing must never fail a step: a CUDA error drops the affected record.

finish_iteration_timing(sample_tokens)

Decorates Worker.sample_tokens to record the iteration's end.

The returned output carries the iterations that have completed by then.

make_iteration_timer(vllm_config, rank)

Only the worker whose output the engine reads times iterations.

start_iteration_timing(execute_model)

Decorates Worker.execute_model to record the iteration's start.

time_dummy_batch(execute_dummy_batch)

Decorates Worker.execute_dummy_batch to time the dummy iteration.

Returns the iterations that have completed by then.