Skip to content

Conversation

@markmc
Copy link
Member

@markmc markmc commented Oct 31, 2025

Follow on from #25712

VllmConfig is explicitly designed as a dataclass containing user-provided configuration and model metadata. It is a global configuration object that lives throughout the entire engine lifetime and is meant to be immutable after __post_init__().

KVCacheConfig is worker-specific, runtime-computed state. It has limited lifetime, and its purpose is limited to initializing the KV Cache in the model runner.

Even if we add KV cache hints to model config.json in future, this would be parsed into ModelConfig, used as input to the get_kv_cache_configs() computation, and the resulting KVCacheConfig would still be runtime state.

We are currently creating per-worker copies of VllmConfig in order to attach the runtime KVCacheConfig state. But instead we should just explicitly pass KVCacheConfig to the connector.

Make sure to handle backwards compatibility for external connector implementations (loaded via module path) that have the old style constructor signature.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors KV connector instantiation to explicitly pass KVCacheConfig, which is a good improvement for separating runtime state from global configuration. The implementation of backward compatibility for external connectors is also well-handled in the factory. However, I've identified a critical issue in MultiConnector where it incorrectly instantiates its sub-connectors, which breaks backward compatibility and fails to pass the kv_cache_config. I've also found a minor issue in a test utility. Please see my comments for details and suggestions.

@markmc
Copy link
Member Author

markmc commented Oct 31, 2025

See also #25712 (comment)

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@markmc
Copy link
Member Author

markmc commented Oct 31, 2025

xref #27811

/cc @KuntaiDu @njhill @heheda12345

@markmc markmc requested a review from KuntaiDu October 31, 2025 15:40
@markmc markmc force-pushed the connector-kv-cache-config branch from 4513b7c to 15ec91b Compare October 31, 2025 15:41
Follow on from vllm-project#25712

`VllmConfig` is explicitly designed as a dataclass containing
user-provided configuration and model metadata. It is a global
configuration object that lives throughout the entire engine lifetime
and is meant to be immutable after `__post_init__()`.

`KVCacheConfig` is worker-specific, runtime-computed state. It has
limited lifetime, and its purpose is limited to initializing the KV
Cache in the model runner.

Even if we add KV cache hints to model config.json in future, this
would be parsed into `ModelConfig`, used as input to the
`get_kv_cache_configs()` computation, and the resulting
`KVCacheConfig` would still be runtime state.

We are currently creating per-worker copies of VllmConfig in order
to attach the runtime `KVCacheConfig` state. But instead we should
just explicitly pass `KVCacheConfig` to the connector.

Make sure to handle backwards compatibility for external connector
implementations (loaded via module path) that have the old style
constructor signature.

Signed-off-by: Mark McLoughlin <[email protected]>
@markmc markmc force-pushed the connector-kv-cache-config branch from 15ec91b to fdc30ae Compare October 31, 2025 17:24
@markmc markmc added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 31, 2025
Copy link
Collaborator

@KuntaiDu KuntaiDu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general LGTM. Some nits listed in comments.

f"Class {connector_name} not found in {connector_module_path}"
) from e
connector_cls = cast(type[KVConnectorBaseType], connector_cls)
if not supports_kw(connector_cls, "kv_cache_config"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm: this means that we allow connector to include kv_cache_config field as init args even when it does not support hybrid allocator (not a subclass of SupportsHMA)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Since we we are currently unconditionally attaching KVCacheConfig to VllmConfig, I didn't even consider making it conditional until now

If we think that KVCacheConfig will only be used as part of implementing request_finished_all_groups() we could add init_hma() or init_kv_cache_config() to SupportsHMA ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KVCacheConfig takes effect on almost all connector methods when HMA is enabled and it is not useful at all when HMA is disabled.

That said, the current implementation looks good to me as it is simple enough.

@@ -0,0 +1,275 @@
# SPDX-License-Identifier: Apache-2.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this file? Like test_connector_init_with_kv_cache_config or something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously I don't really mind renaming it, if it helps, but my thinking is that these tests are about testing support for connectors that have not yet been updated to the new signature so it's more like "without_kv_cache_config()"

Basically, because all connectors are expected to support the new signature, we'll soon see these tests as old cruft that we need to keep around for a while

(This is different from the SupportsHMA approach - in that case, maybe only a small subset of connectors would be updated to take KVCacheConfig)

@markmc
Copy link
Member Author

markmc commented Nov 3, 2025

Just capturing some of the points from the Slack discussion, since I think it was very useful 👍

@heheda12345

I think in the long term, kv cache config will be part of vllm config. But for now, as it is not created during vllm_config initialization, my concern is that there are multiple copies of vllm_config inside vllm, and it's difficult to keep them synchronized. So I suggest @KuntaiDu to add it only as a special attribute for connector

But I don't want something like init(vllm_config, kv_cache_config) as kv_cache_config may be part of vllm_config in the future.

Even if we add KV cache hints to model config.json in future, this would be parsed into ModelConfig, used as input to the get_kv_cache_configs() computation, and the resulting KVCacheConfig would still be runtime state.

if we can do get_kv_cache_configs(model_config), then kv_cache_config can be init during config resolution and is immutable

@markmc

In future, KVCacheConfig will only ever contain immutable config from user/model, and it will no longer ever contain runtime computed state?

IMHO we should not attach runtime computed state to VllmConfig - it makes sense to have KVConnector.init(VllmConfig, KVCacheConfig) now, and work towards making KVCacheConfig only immutable config and then deprecating the KVCacheConfig argument

@heheda12345

should we keep connector interface as stable as possible?

@markmc

yes, but IMO "stability" means "backwards compatible for a (potentially long) deprecation period"

Copy link
Collaborator

@NickLucche NickLucche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, let's keep compat code under control though

self,
vllm_config: "VllmConfig",
role: KVConnectorRole,
kv_cache_config: "KVCacheConfig",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KuntaiDu do you need to change LMCache connector? kv_cache_config is not available in vllm config now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to change LMCache PR correspondingly, but we can merge this PR first and I can change it in LMCache afterwards.

Copy link
Collaborator

@heheda12345 heheda12345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Leave this PR to @KuntaiDu for compatibility with LMCache + HMA

@KuntaiDu
Copy link
Collaborator

KuntaiDu commented Nov 4, 2025

LGTM! Leave this PR to @KuntaiDu for compatibility with LMCache + HMA

Thanks for reminder! I will fix LMCache compatibility after this PR is merged (still a lot of work on LMCache side before turning on HMA by default for LMCache).

@KuntaiDu KuntaiDu merged commit 58279c6 into vllm-project:main Nov 4, 2025
54 checks passed
omerpaz95 pushed a commit to omerpaz95/vllm that referenced this pull request Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kv-connector ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants