Skip to content

vllm.model_executor.model_loader.weight_cache.utils

Helpers shared by the weight cache daemon, the IPC loader and the engine.

These live outside protocol so callers that only need to know whether a draft is cached, or how a daemon group is named, do not have to import the wire format.

Classes:

Functions:

Attributes:

  • DaemonRole –

    Which daemon group serves a model: the target or the speculative draft.

DaemonRole = Literal['target', 'draft'] module-attribute

Which daemon group serves a model: the target or the speculative draft.

ExternalWeightCharges dataclass

Track a worker's external weight charges and those freed by disk fallback.

Attributes:

  • current_bytes (int) –

    External bytes held right now: charges minus fallback removals.

current_bytes property

External bytes held right now: charges minus fallback removals.

build_warmup_runner(vllm_config, local_rank, *, is_draft, model_config)

Create a model runner for the daemon's warmup dummy runs.

build_weight_cache_key(vllm_config, model_config, *, is_draft=False)

Fingerprint this rank's shard exactly as WeightCacheDaemon does.

Shared with the daemon so the peer loader requests the shard its own daemon fingerprinted: TP/PP ranks come from the rank the daemon (or engine worker) stamped on parallel_config.rank, and the DP placement follows the engine's per-worker view. Draft models always use a single pipeline stage.

collect_tensors(model)

Collect a model's tensors, preserving tied-parameter aliases.

named_parameters/named_buffers are iterated with remove_duplicate=False so tied weights (e.g. lm_head.weight sharing storage with embed_tokens.weight) are not silently dropped. Each unique tensor is kept once; every additional name that refers to the same tensor object is recorded in the returned alias map so the client can re-establish the shared identity instead of allocating uninitialized memory for it.

Returns:

  • dict[str, Tensor] –

    A (tensors, kinds, aliases) triple: tensors maps a canonical

  • dict[str, TensorKind] –

    name to its tensor, kinds maps it to "param" or "buffer", and

  • dict[str, str] –

    aliases maps each duplicate name to its canonical name.

exported_weight_bytes(storages)

Allocation bytes of unique non-CPU storages mapped from cached state.

This is the memory the engine would otherwise allocate for the weights itself. memory_allocated() also counts daemon-only state the engine never maps (communication buffers, warmup workspaces, tensors outside parameters/buffers that the engine rebuilds itself), so reporting it would shrink the engine's KV cache below that of a disk load.

format_daemon_role(is_draft)

Name of a daemon group: the target model or the draft.

format_socket_role_suffix(is_draft)

Socket-name suffix keeping the draft group distinct from the target.

get_engine_dp_placement(vllm_config, dp_rank)

(dp_size, dp_rank) as the engine fingerprints this DP rank.

The engine runs the DP ranks of a non-MoE target as independent DP=1 replicas, so their workers all report (1, 0).

is_draft_model_cacheable(speculative_config)

Whether the daemon serves the speculative draft as a separate role: EAGLE-style drafts only. Other drafts keep loading from disk in the engine.