|
1 | 1 | # SPDX-License-Identifier: Apache-2.0 |
2 | 2 |
|
3 | 3 | import importlib |
4 | | -from typing import TYPE_CHECKING, Callable, Dict, Optional, Type, Union |
| 4 | +from typing import TYPE_CHECKING, Callable, Dict, Type, Union |
5 | 5 |
|
6 | 6 | import vllm.envs as envs |
7 | 7 | from vllm.distributed.kv_transfer.kv_connector.v1 import (KVConnectorBase_V1, |
@@ -47,36 +47,32 @@ def create_connector_v1( |
47 | 47 | connector_cls = cls._registry[connector_name]() |
48 | 48 | assert issubclass(connector_cls, KVConnectorBase_V1) |
49 | 49 | logger.info("Creating v1 connector with name: %s", connector_name) |
| 50 | + # NOTE(Kuntai): v1 connector is explicitly separated into two roles. |
| 51 | + # Scheduler connector: |
| 52 | + # - Co-colate with scheduler process |
| 53 | + # - Should only be used inside the Scheduler class |
| 54 | + # Worker connector: |
| 55 | + # - Co-locate with worker process |
| 56 | + # - Should only be used inside the forward context & attention layer |
| 57 | + # We build separately to enforce strict separation |
50 | 58 | return connector_cls(config, role) |
51 | 59 |
|
52 | 60 | @classmethod |
53 | | - def create_connector_v0(cls, rank: Optional[int], |
54 | | - local_rank: Optional[int], config: "VllmConfig", |
55 | | - role: KVConnectorRole) -> KVConnectorBase: |
| 61 | + def create_connector_v0(cls, rank: int, local_rank: int, |
| 62 | + config: "VllmConfig") -> KVConnectorBase: |
| 63 | + if envs.VLLM_USE_V1: |
| 64 | + raise ValueError("Attempting to initialize a V0 Connector, " |
| 65 | + f"but found {envs.VLLM_USE_V1=}") |
| 66 | + |
56 | 67 | connector_name = config.kv_transfer_config.kv_connector |
57 | 68 | if connector_name not in cls._registry: |
58 | 69 | raise ValueError(f"Unsupported connector type: {connector_name}") |
59 | 70 |
|
60 | | - if envs.VLLM_USE_V1: |
61 | | - # NOTE(Kuntai): v1 connector is explicitly separated into two roles. |
62 | | - # Scheduler connector: |
63 | | - # - Co-colate with scheduler process |
64 | | - # - Should only be used inside the Scheduler class |
65 | | - # Worker connector: |
66 | | - # - Co-locate with worker process |
67 | | - # - Should only be used inside the forward context & attention layer |
68 | | - # We build these two connectors separately to enforce strict |
69 | | - # separation |
70 | | - connector_cls_v1 = cls._registry[connector_name]() |
71 | | - assert issubclass(connector_cls_v1, KVConnectorBase_V1) |
72 | | - logger.info("Creating v1 connector with name: %s", connector_name) |
73 | | - return connector_cls_v1(rank, local_rank, config, role) |
74 | | - else: |
75 | | - assert rank is not None |
76 | | - assert local_rank is not None |
77 | | - connector_cls = cls._registry[connector_name]() |
78 | | - assert issubclass(connector_cls, KVConnectorBase) |
79 | | - return connector_cls(rank, local_rank, config) |
| 71 | + assert rank is not None |
| 72 | + assert local_rank is not None |
| 73 | + connector_cls = cls._registry[connector_name]() |
| 74 | + assert issubclass(connector_cls, KVConnectorBase) |
| 75 | + return connector_cls(rank, local_rank, config) |
80 | 76 |
|
81 | 77 |
|
82 | 78 | # Register various connectors here. |
|
0 commit comments