Skip to content

vllm.config.utils

Utility functions for vLLM config dataclasses.

Classes:

  • Range –

    A range of numbers.

Functions:

Range

A range of numbers. Inclusive of start, inclusive of end.

_get_own_attr_docs(cls, out)

Get any docstrings placed after attribute assignments in a class body.

https://davidism.com/mit-license/

config(cls=None, *, config=None, **kwargs)

config(cls: type[ConfigT]) -> type[ConfigT]
config(
    *, config: ConfigDict | None = None, **kwargs: Any
) -> Callable[[type[ConfigT]], type[ConfigT]]

Decorator to create a pydantic dataclass with default config. The default config for the dataclass forbids extra fields.

All config classes in vLLM should use this decorator.

Parameters:

  • cls

    (type[ConfigT] | None, default: None ) –

    The class to decorate

  • config

    (ConfigDict | None, default: None ) –

    The pydantic ConfigDict to use. If provided, it will be merged with the default config.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments to pass to pydantic.dataclass.

get_attr_docs(cls)

Get any docstrings placed after attribute assignments in a class body or its bases.

get_compile_factors(config, ignored_factors)

Gets the factors used for hashing a config class. - Includes all dataclass fields not in ignored_factors. - Uses compile_factors() for nested configs that define it. - Errors on unknown ignored_factors and non-normalizable values.

get_field(cls, name)

Get the default factory field of a dataclass by name. Used for getting default factory fields in EngineArgs.

get_from_deprecated_env_if_set(env_name, removal_version, field_name=None)

Get value from deprecated environment variable with warning.

Parameters:

  • env_name

    (str) –

    Name of the deprecated environment variable

  • removal_version

    (str) –

    Version when it will be removed

  • field_name

    (str | None, default: None ) –

    Name of the field to suggest as alternative

Returns:

  • str | None –

    The environment variable value if set, None otherwise

getattr_iter(object, names, default=None, default_factory=None, warn=False)

A helper function that retrieves an attribute from an object which may have multiple possible names. This is useful when fetching attributes from arbitrary transformers.PreTrainedConfig instances.

In the case where the first name in names is the preferred name, and any other names are deprecated aliases, setting warn=True will log a warning when a deprecated name is used.

hash_config(config)

Hash the compile factors of a config.

hash_config_cached(config)

Cache hash_config(config) by object identity.

Config objects (ModelConfig, etc.) are long-lived singletons that never mutate after construction, but hashing them is expensive (JSON serialization + SHA-256). This utility avoids recomputing the hash on every forward pass while keeping a single consistent key type for all lookup paths.

hash_factors(items)

Return a SHA-256 hex digest of the canonical items structure.

normalize_value(x)

Return a stable, JSON-serializable canonical form for hashing. Order: primitives, special types (Enum, callable, torch.dtype, Path), then generic containers (Mapping/Set/Sequence) with recursion.

replace(dataclass_instance, /, **kwargs)

Like dataclasses.replace, but compatible with Pydantic dataclasses which use pydantic.fields.Field instead of dataclasses.field

set_from_deprecated_env_if_set(config, env_name, removal_version, field_name, to_bool=False, to_int=False)

Set object field from deprecated environment variable with warning.

Parameters:

  • config

    (ConfigT) –

    Config object to set the field on

  • env_name

    (str) –

    Name of the deprecated environment variable

  • removal_version

    (str) –

    Version when the env var will be removed

  • field_name

    (str) –

    Name of the field to set

  • to_bool

    (bool, default: False ) –

    Whether to convert the environment variable value to boolean

  • to_int

    (bool, default: False ) –

    Whether to convert the environment variable value to integer

Returns: None