Skip to content

Commit d3fdeba

Browse files
[feat] Add patch support and required connector interfaces (#1016)
## Purpose Add patch support for vLLM 0.19.1 with connector interfaces ## Modifications - Update the supported vLLM version from 0.19.0 to 0.19.1. - Add missing connector methods for vllm-ascend: - get_finished - update_connector_output ## Test
1 parent 74e3c15 commit d3fdeba

11 files changed

Lines changed: 123 additions & 2 deletions

File tree

ucm/integration/vllm/patch/apply_patch.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def get_vllm_version() -> Optional[str]:
114114

115115
def get_supported_versions() -> list[str]:
116116
"""Get patch-required vLLM versions."""
117-
return ["0.11.0", "0.17.0", "0.18.0", "0.19.0"]
117+
return ["0.11.0", "0.17.0", "0.18.0", "0.19.1"]
118118

119119

120120
def apply_all_patches() -> None:
@@ -150,6 +150,9 @@ def apply_all_patches() -> None:
150150
case "0.18.0":
151151
logger.info("UCM patching vllm for pc...")
152152
import ucm.integration.vllm.patch.v0180.vllm.pc_patch
153+
case "0.19.1":
154+
logger.info("UCM patching vllm for pc...")
155+
import ucm.integration.vllm.patch.v0191.vllm.pc_patch
153156
case _:
154157
pass
155158

@@ -171,9 +174,12 @@ def apply_all_patches() -> None:
171174
case "0.18.0":
172175
logger.info("UCM patching vllm-ascend for pc...")
173176
import ucm.integration.vllm.patch.v0180.vllm_ascend.pc_ascend_patch
174-
case "0.17.0" | "0.19.0":
177+
case "0.17.0":
175178
logger.info(f"UCM patching vllm-ascend {ascend_version} for pc...")
176179
import ucm.integration.vllm.patch.v0180.vllm_ascend.ucm_connector_patch
180+
case "0.19.1":
181+
logger.info(f"UCM patching vllm-ascend {ascend_version} for pc...")
182+
import ucm.integration.vllm.patch.v0191.vllm_ascend.pc_ascend_patch
177183
case _:
178184
pass
179185

ucm/integration/vllm/patch/v0180/vllm_ascend/pc/distributed/kv_transfer/kv_pool/ucm_connector.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,21 @@ def request_finished_all_groups(
7474
return engine.request_finished(request, [])
7575

7676

77+
def get_finished(
78+
self: Any,
79+
finished_req_ids: set[str],
80+
) -> tuple[set[str] | None, set[str] | None]:
81+
return self._call_ucm_reserved_hook("get_finished", finished_req_ids)
82+
83+
7784
def build_connector_worker_meta(self: Any) -> Any:
7885
return self._call_ucm_reserved_hook("build_connector_worker_meta")
7986

8087

88+
def update_connector_output(self: Any, connector_output: Any) -> None:
89+
return self._call_ucm_reserved_hook("update_connector_output", connector_output)
90+
91+
8192
def take_events(self: Any) -> Iterable[Any]:
8293
events = self._call_ucm_reserved_hook("take_events")
8394
return () if events is None else events
@@ -142,11 +153,13 @@ def patch_ucm_connector_v1(mod: Any) -> None:
142153
"request_finished_all_groups",
143154
request_finished_all_groups,
144155
)
156+
patch_or_inject(target_cls, "get_finished", get_finished)
145157
patch_or_inject(
146158
target_cls,
147159
"build_connector_worker_meta",
148160
build_connector_worker_meta,
149161
)
162+
patch_or_inject(target_cls, "update_connector_output", update_connector_output)
150163
patch_or_inject(target_cls, "take_events", take_events)
151164
patch_or_inject(target_cls, "get_kv_connector_stats", get_kv_connector_stats)
152165
patch_or_inject(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from ucm.integration.vllm.patch.utils import patch_or_inject, when_imported
2+
from ucm.logger import init_logger
3+
4+
logger = init_logger(__name__)
5+
6+
7+
@when_imported("vllm.config.vllm")
8+
def patch_vllm_config(mod):
9+
logger.debug(f"Patched {mod} called")
10+
11+
from ucm.integration.vllm.patch.v0180.vllm.pc.config import vllm
12+
13+
vllm.patch_vllm_config_cls(mod.VllmConfig)
14+
15+
16+
@when_imported("vllm.model_executor.models.config")
17+
def patch_model_config(mod):
18+
logger.debug(f"Patched {mod} called")
19+
20+
from ucm.integration.vllm.patch.v0180.vllm.pc.model_executor.models import (
21+
config,
22+
)
23+
24+
config.patch_mamba_model_config_cls(mod.MambaModelConfig)
25+
26+
27+
@when_imported("vllm.v1.core.sched.scheduler")
28+
def patch_core_sched_scheduler(mod):
29+
logger.debug(f"Patched {mod} called")
30+
31+
from ucm.integration.vllm.patch.v0180.vllm.pc.v1.core.sched import scheduler
32+
33+
patch_or_inject(
34+
mod.Scheduler,
35+
"_mamba_block_aligned_split",
36+
scheduler.Scheduler._mamba_block_aligned_split,
37+
)
38+
39+
40+
@when_imported("vllm.v1.worker.gpu_model_runner")
41+
def patch_worker_gpu_model_runner(mod):
42+
logger.debug(f"Patched {mod} called")
43+
44+
from ucm.integration.vllm.patch.v0180.vllm.pc.v1.worker import gpu_model_runner
45+
46+
patch_or_inject(
47+
mod.GPUModelRunner,
48+
"may_reinitialize_input_batch",
49+
gpu_model_runner.GPUModelRunner.may_reinitialize_input_batch,
50+
)
51+
52+
53+
@when_imported("vllm.v1.worker.mamba_utils")
54+
def patch_worker_mamba_utils(mod):
55+
logger.debug(f"Patched {mod} called")
56+
57+
from ucm.integration.vllm.patch.v0180.vllm.pc.v1.worker import mamba_utils
58+
59+
mamba_utils.patch_preprocess_mamba(mod)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import vllm.model_executor.models.config
2+
3+
4+
def patch_hybrid_attention_mamba_model_config() -> None:
5+
original = (
6+
vllm.model_executor.models.config.HybridAttentionMambaModelConfig.verify_and_update_config
7+
)
8+
9+
@classmethod
10+
def verify_and_update_config(cls, vllm_config) -> None:
11+
original(vllm_config)
12+
13+
cache_config = vllm_config.cache_config
14+
if cache_config.mamba_cache_mode == "align":
15+
cache_config.mamba_block_size = cache_config.block_size
16+
17+
vllm.model_executor.models.config.HybridAttentionMambaModelConfig.verify_and_update_config = (
18+
verify_and_update_config
19+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ucm.integration.vllm.patch.v0191.vllm_ascend.ucm_connector_patch # noqa: F401
2+
from ucm.integration.vllm.patch.utils import when_imported
3+
from ucm.logger import init_logger
4+
5+
logger = init_logger(__name__)
6+
7+
8+
@when_imported("vllm_ascend.patch.platform.patch_mamba_config")
9+
def patch_platform_mamba_config(mod):
10+
logger.debug(f"Patched {mod} called")
11+
12+
from ucm.integration.vllm.patch.v0191.vllm_ascend.pc.platform import (
13+
patch_mamba_config,
14+
)
15+
16+
patch_mamba_config.patch_hybrid_attention_mamba_model_config()

0 commit comments

Comments
 (0)