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:
-
finish_iteration_timing–Decorates
Worker.sample_tokensto record the iteration's end. -
make_iteration_timer–Only the worker whose output the engine reads times iterations.
-
start_iteration_timing–Decorates
Worker.execute_modelto record the iteration's start. -
time_dummy_batch–Decorates
Worker.execute_dummy_batchto time the dummy iteration.
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.
Source code in vllm/v1/worker/iteration_timing.py
start(details, is_dummy=False)
¶
Begin an iteration, dropping any that never finished.
Without a scheduling snapshot the iteration is not timed.
Source code in vllm/v1/worker/iteration_timing.py
take_ready()
¶
Pop the oldest iterations whose GPU work has completed.
Source code in vllm/v1/worker/iteration_timing.py
_TimedIteration
dataclass
¶
Methods:
-
read–Read the elapsed time. Both events must have completed.
Source code in vllm/v1/worker/iteration_timing.py
read()
¶
Read the elapsed time. Both events must have completed.
Source code in vllm/v1/worker/iteration_timing.py
_WithIterationRecords
¶
Bases: AsyncModelRunnerOutput
A step's output that also carries completed iteration records.
Source code in vllm/v1/worker/iteration_timing.py
_drop_on_cuda_error()
¶
Timing must never fail a step: a CUDA error drops the affected record.
Source code in vllm/v1/worker/iteration_timing.py
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.
Source code in vllm/v1/worker/iteration_timing.py
make_iteration_timer(vllm_config, rank)
¶
Only the worker whose output the engine reads times iterations.
Source code in vllm/v1/worker/iteration_timing.py
start_iteration_timing(execute_model)
¶
Decorates Worker.execute_model to record the iteration's start.
Source code in vllm/v1/worker/iteration_timing.py
time_dummy_batch(execute_dummy_batch)
¶
Decorates Worker.execute_dummy_batch to time the dummy iteration.
Returns the iterations that have completed by then.