Skip to content

vllm.v1.metrics.buckets

Default bucket boundaries for the Prometheus histograms emitted by vLLM.

Every core engine histogram created by the Prometheus stat logger draws its bucket boundaries from exactly one of the families defined here, so each default list has a single source of truth. Histograms owned by other subsystems, such as the KV connector and offloading metrics, keep their own boundaries.

Functions:

Attributes:

BUCKET_FAMILY_KEYS = frozenset(get_args(BucketFamilyKey)) module-attribute

All bucket family keys, for membership checks.

BucketFamilyKey = Literal['request_latency', 'time_to_first_token', 'inter_token_latency', 'iteration_tokens', 'request_params_n', 'request_num_preemptions', 'request_tokens', 'kv_cache_residency'] module-attribute

Canonical keys for the histogram bucket families.

INTER_TOKEN_LATENCY_BUCKETS = (0.01, 0.025, 0.05, 0.075, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0, 20.0, 40.0, 80.0) module-attribute

Per-decode-step latencies: 10 ms fast decode up to multi-second stalls.

ITERATION_TOKENS_BUCKETS = (1, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384) module-attribute

Tokens processed per engine step: powers of two up to a typical max-num-batched-tokens budget.

KV_CACHE_RESIDENCY_BUCKETS = (0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 30, 60, 120, 300, 600, 1200, 1800) module-attribute

KV cache block residency times: millisecond-scale reuse gaps up to 30-minute block lifetimes.

REQUEST_LATENCY_BUCKETS = (0.3, 0.5, 0.8, 1.0, 1.5, 2.0, 2.5, 5.0, 10.0, 15.0, 20.0, 30.0, 40.0, 50.0, 60.0, 120.0, 240.0, 480.0, 960.0, 1920.0, 7680.0) module-attribute

Sub-second scheduling delays through multi-hour batch requests; shared by the accumulated request phase-timing histograms (e2e, queue, inference, prefill, decode).

REQUEST_NUM_PREEMPTIONS_BUCKETS = (1, 2, 3, 4, 5, 10, 20) module-attribute

Per-request preemption counts, recorded for every finished request: the first bucket therefore holds never-preempted requests together with singly-preempted ones, 2 through 5 are separated individually, and the tail coarsens to 20. Distinct from REQUEST_PARAMS_N_BUCKETS because these are the boundaries the metric shipped with, not a harmonized choice.

REQUEST_PARAMS_N_BUCKETS = (1, 2, 5, 10, 20) module-attribute

Small integer counts for the n sampling parameter.

TIME_TO_FIRST_TOKEN_BUCKETS = (0.001, 0.005, 0.01, 0.02, 0.04, 0.06, 0.08, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0, 20.0, 40.0, 80.0, 160.0, 640.0, 2560.0) module-attribute

Millisecond-scale prefill for tiny prompts up to ~40-minute worst cases, with the densest resolution around interactive (sub-second) latencies.

build_1_2_5_buckets(max_value)

Build a 1-2-5 series of buckets capped at max_value.

Example

build_1_2_5_buckets(100) [1, 2, 5, 10, 20, 50, 100]

Source code in vllm/v1/metrics/buckets.py
def build_1_2_5_buckets(max_value: int) -> list[float]:
    """Build a 1-2-5 series of buckets capped at `max_value`.

    Example:
        >>> build_1_2_5_buckets(100)
        [1, 2, 5, 10, 20, 50, 100]
    """
    return build_buckets([1, 2, 5], max_value)

build_buckets(mantissa_lst, max_value)

Build buckets from mantissas scaled by increasing powers of 10.

Parameters:

  • mantissa_lst

    (list[int]) –

    Mantissa values multiplied by each power of 10.

  • max_value

    (int) –

    Largest bucket value to include.

Returns:

  • list[float]

    Bucket values in increasing order, capped at max_value.

Source code in vllm/v1/metrics/buckets.py
def build_buckets(mantissa_lst: list[int], max_value: int) -> list[float]:
    """Build buckets from mantissas scaled by increasing powers of 10.

    Args:
        mantissa_lst: Mantissa values multiplied by each power of 10.
        max_value: Largest bucket value to include.

    Returns:
        Bucket values in increasing order, capped at `max_value`.
    """
    exponent = 0
    buckets: list[float] = []
    while True:
        for m in mantissa_lst:
            value = m * 10**exponent
            if value <= max_value:
                buckets.append(value)
            else:
                return buckets
        exponent += 1

histogram_buckets(family, max_model_len=None)

Return the default bucket boundaries for a histogram family.

Parameters:

  • family

    (BucketFamilyKey) –

    Canonical bucket family key.

  • max_model_len

    (int | None, default: None ) –

    Cap for the token-count series of the request_tokens family; required for that family and ignored otherwise.

Returns:

  • list[float]

    A fresh list of bucket upper bounds; callers may mutate it freely.

Raises:

  • ValueError

    If family is request_tokens and max_model_len is None.

Source code in vllm/v1/metrics/buckets.py
def histogram_buckets(
    family: BucketFamilyKey,
    max_model_len: int | None = None,
) -> list[float]:
    """Return the default bucket boundaries for a histogram family.

    Args:
        family: Canonical bucket family key.
        max_model_len: Cap for the token-count series of the
            `request_tokens` family; required for that family and ignored
            otherwise.

    Returns:
        A fresh list of bucket upper bounds; callers may mutate it freely.

    Raises:
        ValueError: If `family` is `request_tokens` and `max_model_len`
            is None.
    """
    if family == "request_tokens":
        if max_model_len is None:
            raise ValueError(
                "max_model_len is required for the 'request_tokens' bucket family"
            )
        return build_1_2_5_buckets(max_model_len)
    return list(_STATIC_FAMILY_DEFAULTS[family])