Skip to content

vllm.v1.kv_identity

An engine's KV compatibility identity.

Engines with equal identities compute the same KV bytes for the same token ids, up to floating-point rounding order, so they can exchange KV cache blocks. The identity covers the target model only: draft model KV is checked by the connectors that transfer it.

Classes:

Functions:

KVIdentityTracker

The identity across runtime weight changes.

  • Weights loaded from files are identified by the files' digest.
  • Setting a weight version identifies the weights by the last file digest and that version, which the caller vouches for.
  • Otherwise, after weights change, the identity is unknown: a unique value that matches no other engine, until a reload from files or a version identifies the weights again.

Methods:

  • reloaded –

    Identify weights reloaded from files, if rank 0 digested all of

Source code in vllm/v1/kv_identity.py
class KVIdentityTracker:
    """The identity across runtime weight changes.

    - Weights loaded from files are identified by the files' digest.
    - Setting a weight version identifies the weights by the last file digest
      and that version, which the caller vouches for.
    - Otherwise, after weights change, the identity is unknown: a unique value
      that matches no other engine, until a reload from files or a version
      identifies the weights again.
    """

    def __init__(
        self, vllm_config: VllmConfig, checkpoint_digests: list[dict[str, str] | None]
    ) -> None:
        self._vllm_config = vllm_config
        self.identity = compute_kv_identity(vllm_config, checkpoint_digests)
        self._file_weights = self.identity.components["weights"]

    def unknown(self) -> KVIdentity:
        weights = {"weights": "unknown", "weights_source": "unknown"}
        identity = _kv_identity(self._vllm_config, weights)
        self.identity = KVIdentity(
            digest=UNKNOWN_KV_IDENTITY_PREFIX + uuid.uuid4().hex,
            components=identity.components,
        )
        return self.identity

    def reloaded(self, checkpoint_digests: list[dict[str, str] | None]) -> KVIdentity:
        """Identify weights reloaded from files, if rank 0 digested all of
        them by content."""
        weights = next((d for d in checkpoint_digests if d is not None), None)
        if weights is None or weights["weights_source"] not in _CONTENT_WEIGHTS_SOURCES:
            return self.unknown()
        self._file_weights = weights["weights"]
        self.identity = _kv_identity(self._vllm_config, weights)
        return self.identity

    def versioned(self, weight_version: str) -> KVIdentity:
        weights = {
            "weights": hash_factors(
                {"files": self._file_weights, "weight_version": weight_version}
            ),
            "weights_source": "weight_version",
            "weight_version": weight_version,
        }
        self.identity = _kv_identity(self._vllm_config, weights)
        return self.identity

reloaded(checkpoint_digests)

Identify weights reloaded from files, if rank 0 digested all of them by content.

Source code in vllm/v1/kv_identity.py
def reloaded(self, checkpoint_digests: list[dict[str, str] | None]) -> KVIdentity:
    """Identify weights reloaded from files, if rank 0 digested all of
    them by content."""
    weights = next((d for d in checkpoint_digests if d is not None), None)
    if weights is None or weights["weights_source"] not in _CONTENT_WEIGHTS_SOURCES:
        return self.unknown()
    self._file_weights = weights["weights"]
    self.identity = _kv_identity(self._vllm_config, weights)
    return self.identity

compute_kv_identity(vllm_config, checkpoint_digests)

Compute the identity from the checkpoint digest workers report.

Rank 0 reports it; without a report, the weights are identified by the model path and revision.

Source code in vllm/v1/kv_identity.py
def compute_kv_identity(
    vllm_config: VllmConfig,
    checkpoint_digests: list[dict[str, str] | None],
) -> KVIdentity:
    """Compute the identity from the checkpoint digest workers report.

    Rank 0 reports it; without a report, the weights are identified by the
    model path and revision.
    """
    weights = next(
        (digest for digest in checkpoint_digests if digest is not None), None
    ) or path_checkpoint_digest(vllm_config.model_config, vllm_config.load_config)
    return _kv_identity(vllm_config, weights)