|
3 | 3 | import filecmp |
4 | 4 | import shutil |
5 | 5 | import tempfile |
6 | | -from collections import defaultdict |
7 | 6 | from pathlib import Path |
8 | 7 |
|
9 | 8 | from vllm import LLM, SamplingParams |
10 | | -from vllm.config import KVTransferConfig, VllmConfig |
11 | | -from vllm.distributed.kv_transfer.kv_connector.factory import ( |
12 | | - KVConnectorFactory) |
13 | | -from vllm.distributed.kv_transfer.kv_connector.v1.shared_storage_connector import ( # noqa |
14 | | - SharedStorageConnector) |
15 | | -from vllm.v1.core.kv_cache_manager import KVCacheBlocks |
| 9 | +from vllm.config import KVTransferConfig |
16 | 10 |
|
17 | 11 | MODEL_NAME = "meta-llama/Llama-3.2-1B-Instruct" |
18 | 12 |
|
|
25 | 19 | SAMPLING_PARAMS = SamplingParams(temperature=0, max_tokens=20) |
26 | 20 |
|
27 | 21 |
|
28 | | -class TestSharedStorageConnector(SharedStorageConnector): |
29 | | - |
30 | | - def __init__(self, config: VllmConfig, role): |
31 | | - self.name = config.kv_transfer_config.kv_connector_extra_config["name"] |
32 | | - self._connector = SharedStorageConnector(config, role) |
33 | | - self.call_record: dict[str, int] = defaultdict(int) |
34 | | - # Use a unique temp file per connector |
35 | | - self._event_file = tempfile.gettempdir( |
36 | | - ) + f"/connector_{self.name}-{self.role.name}_events.log" |
37 | | - # Start with an empty file |
38 | | - with open(self._event_file, "w") as _: |
39 | | - pass |
40 | | - |
41 | | - def __getattribute__(self, name): |
42 | | - if name in ("_connector", "call_record", "name", "_event_file", |
43 | | - "__class__", "__dict__", "__getattribute__", |
44 | | - "__init__"): # avoid recursion |
45 | | - return object.__getattribute__(self, name) |
46 | | - if not hasattr(self._connector, name): |
47 | | - return object.__getattribute__(self, name) |
48 | | - attr = getattr(self._connector, name) |
49 | | - |
50 | | - # Intercept calls to the connector interface and write an event |
51 | | - # for each one to a file, which can be read back in the main test proc. |
52 | | - if callable(attr): |
53 | | - |
54 | | - def wrapper(*args, **kwargs): |
55 | | - self.call_record[name] += 1 |
56 | | - |
57 | | - # Include args that we're interested in |
58 | | - to_log = [name] |
59 | | - for arg in args: |
60 | | - if isinstance(arg, int): |
61 | | - to_log.append(str(arg)) |
62 | | - elif isinstance(arg, KVCacheBlocks): |
63 | | - to_log.append( |
64 | | - f"num_blocks={[len(b) for b in arg.blocks]}") |
65 | | - |
66 | | - # Log the event as a line to the file |
67 | | - try: |
68 | | - with open(self._event_file, "a") as f: |
69 | | - f.write(' '.join(to_log) + "\n") |
70 | | - except Exception as e: |
71 | | - print(f"[ERROR] Could not log event {name} " |
72 | | - f"for {self.name}: {e}") |
73 | | - return attr(*args, **kwargs) |
74 | | - |
75 | | - return wrapper |
76 | | - return attr |
77 | | - |
78 | | - |
79 | | -# This relies on "fork" multiprocessing method being used. |
80 | | -# It's the default but vLLM may fall back to spawn if for example CUDA |
81 | | -# is already initialized. |
82 | | -KVConnectorFactory.register_connector("TestSharedStorageConnector", |
83 | | - TestSharedStorageConnector.__module__, |
84 | | - TestSharedStorageConnector.__name__) |
85 | | - |
86 | | - |
87 | 22 | # Helper function to compare directories recursively |
88 | 23 | def _compare_directories(dir1: Path, dir2: Path) -> bool: |
89 | 24 | """Compares two directories recursively for identical content.""" |
@@ -118,19 +53,27 @@ def test_multi_shared_storage_connector_consistency(): |
118 | 53 | kv_role="kv_both", |
119 | 54 | kv_connector_extra_config={ |
120 | 55 | "connectors": [{ |
121 | | - "kv_connector": "TestSharedStorageConnector", |
122 | | - "kv_role": "kv_both", |
| 56 | + "kv_connector": |
| 57 | + "TestSharedStorageConnector", |
| 58 | + "kv_role": |
| 59 | + "kv_both", |
123 | 60 | "kv_connector_extra_config": { |
124 | 61 | "shared_storage_path": str(storage_1_path), |
125 | 62 | "name": "storage1", |
126 | | - } |
| 63 | + }, |
| 64 | + "kv_connector_module_path": |
| 65 | + "tests.v1.kv_connector.unit.utils", |
127 | 66 | }, { |
128 | | - "kv_connector": "TestSharedStorageConnector", |
129 | | - "kv_role": "kv_both", |
| 67 | + "kv_connector": |
| 68 | + "TestSharedStorageConnector", |
| 69 | + "kv_role": |
| 70 | + "kv_both", |
130 | 71 | "kv_connector_extra_config": { |
131 | 72 | "shared_storage_path": str(storage_2_path), |
132 | 73 | "name": "storage2", |
133 | | - } |
| 74 | + }, |
| 75 | + "kv_connector_module_path": |
| 76 | + "tests.v1.kv_connector.unit.utils", |
134 | 77 | }] |
135 | 78 | }, |
136 | 79 | ) |
|
0 commit comments