Skip to content

vllm.model_executor.model_loader.weight_cache.protocol

WeightCacheKey fingerprinting and socket protocol for the weight cache daemon.

The protocol uses pickle over a Unix domain socket and is only intended for communication between trusted local processes owned by the same user. The sockets live in a per-user private directory (mode 0700) and the daemon restricts the socket file permissions to the owner (0600). Both the daemon and the engine verify that the directory and socket are owned by the current user and are not group/world accessible before trusting them, so a different local user cannot pre-plant a malicious socket at a predictable path.

Classes:

Functions:

CacheConfigMismatchError

Bases: Exception

Raised when the daemon's cached weights don't match the engine.

UnsupportedPlatformForIPCError

Bases: Exception

Raised when the current platform cannot share CUDA IPC handles.

UnsupportedQuantForIPCError

Bases: Exception

Raised when a quantization method is not verified for IPC weight sharing.

WeightCacheKey dataclass

Fingerprint of the cached weights.

Any mismatch between the daemon's and the engine's fingerprint means the cached weights cannot be reused and the engine must load from disk.

Methods:

Attributes:

  • is_draft (bool) –

    Daemon group the weights come from; False is the target model.

  • mm_disabled_modalities (tuple[str, ...]) –

    With the two flags above, decides which components (e.g. the vision

  • moe_backend (str) –

    Kernel backends pick the processed weight layout (e.g. shuffled or

is_draft = False class-attribute instance-attribute

Daemon group the weights come from; False is the target model.

mm_disabled_modalities = () class-attribute instance-attribute

With the two flags above, decides which components (e.g. the vision tower) are built; skipped ones are absent from the daemon's export.

moe_backend = 'auto' class-attribute instance-attribute

Kernel backends pick the processed weight layout (e.g. shuffled or repacked), so weights processed for one backend are wrong for another.

from_model_config(model_config, tp_size, tp_rank, *, cache_config, pp_size=1, pp_rank=0, is_draft=False, dp_size=1, dp_rank=0, enable_expert_parallel=False, expert_placement_strategy='linear', kernel_config=None, engram_cpu_offload=False, engram_dp_shared_memory=False, engram_embedding_across_dp=False, indexer_kv_dtype='auto') classmethod

Build the fingerprint for a model configuration.

Must be called before weight loading: process_weights_after_loading may mutate hf_config.quantization_config, which would change the hash between the daemon and the engine.

The checkpoint is identified by a hash of its safetensors metadata when the weights are available locally, so a daemon and engine referencing identical weights in different directories still match; otherwise it falls back to the model path.

WeightCacheState

Bases: NamedTuple

Consumer-side DTO decoded from a daemon's get_state response.

Attributes:

  • aliases (dict[str, str]) –

    Duplicate (tied) weight names aliased to their canonical tensor.

  • attrs (dict[str, bool]) –

    Python-side flags set by load_weights, e.g. EAGLE ownership flags.

  • manifest (dict) –

    Logical tensor views over the imported storages.

  • storages (list[StorageRecord]) –

    Storage records rebuilt on the consumer's device.

aliases instance-attribute

Duplicate (tied) weight names aliased to their canonical tensor.

attrs instance-attribute

Python-side flags set by load_weights, e.g. EAGLE ownership flags.

manifest instance-attribute

Logical tensor views over the imported storages.

storages instance-attribute

Storage records rebuilt on the consumer's device.

WeightCacheUnavailableError

Bases: Exception

Raised when no weight cache daemon is reachable or usable.

_safetensors_header(path)

Return the raw safetensors header (length prefix + JSON) of a file.

The header carries tensor names, dtypes, shapes and byte offsets, so it is a content fingerprint of the shard without reading any weight bytes.

check_ipc_platform_support()

Hard-error unless the current platform can share CUDA IPC handles.

Only CUDA/ROCm storages get a real IPC handle from TensorEntry; other platforms (e.g. XPU) would silently ship every storage by value instead.

Raises:

check_ipc_quant_support(model)

Hard-error unless every quant method supports pre-processed weights.

Parameters:

  • model

    (Module) –

    The model to inspect (weights need not be loaded).

Raises:

check_weight_cache_loader_support(vllm_config, model_config, *, is_draft)

Reject deployments a weight cache loader cannot serve (platform, EPLB, role).

ensure_private_socket_dir(directory, strict_perms=True)

Create the socket directory (if needed) locked down to the owner.

Called by the daemon before binding. Existing directories are re-checked and, for the auto-derived path, tightened so a pre-existing world-writable directory is rejected.

get_current_device_uuid()

UUID of the physical GPU backing the current accelerator device.

get_socket_dir(socket_dir=None)

Return the directory that holds the daemon sockets.

When no explicit directory is given, use a per-user private directory under the system temp dir so its path is unpredictable to other users and can be locked down to mode 0700.

get_socket_path(gpu_uuid, socket_dir=None, *, is_draft=False)

Socket path of a daemon group; is_draft=False is the target.

The GPU uuid is hashed to keep the name well under the AF_UNIX path limit (~108 bytes) even with the draft role suffix.

hash_checkpoint(model)

Fingerprint checkpoint content from local safetensors metadata.

Hashes each shard's safetensors header so a daemon and an engine pointing at identical weights in different directories produce the same key. Returns None when local safetensors files can't be located (e.g. an undownloaded Hugging Face repo id), leaving the caller to fall back to the model path.

hash_rope_parameters(model_config)

Fingerprint the text RoPE parameters used to construct cached buffers.

parse_seed_address(address)

Split a seed address into a Unix socket path or a (host, port).

recv_json(sock, max_size=MAX_JSON_MSG_SIZE, deadline=None)

Receive one JSON message.

Parameters:

  • sock

    (socket) –

    Connected socket.

  • max_size

    (int, default: MAX_JSON_MSG_SIZE ) –

    Largest payload accepted.

  • deadline

    (float | None, default: None ) –

    time.monotonic() by which the whole message must have arrived; a per-read timeout alone lets a peer trickle bytes forever.

verify_peer_is_owner(conn)

Best-effort check that the connecting peer runs as the current user.

Uses SO_PEERCRED where available (Linux). Silently returns on platforms that do not expose peer credentials.

verify_private_dir(directory, strict_perms=True)

Verify a directory is a real dir owned by us and not world/group readable.

When strict_perms is False the group/world permission bits are not checked; this is used for directories the operator explicitly configured (they own the trust decision), while the auto-derived per-user directory is always checked strictly.

verify_socket_owner(socket_path, strict_perms=True)

Verify the socket lives in a private dir and is owned by the current user.

Called by the engine before connecting so it never talks to a socket a different user could have planted.