Skip to content

Commit 0b217da

Browse files
authored
Update deprecated type hinting in vllm/adapter_commons (#18073)
Signed-off-by: Harry Mellor <[email protected]>
1 parent 19324d6 commit 0b217da

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ exclude = [
7272
"vllm/version.py" = ["F401"]
7373
"vllm/_version.py" = ["ALL"]
7474
# Python 3.8 typing. TODO: Remove these excludes after v1.0.0
75-
"vllm/adapter_commons/**/*.py" = ["UP006", "UP035"]
7675
"vllm/attention/**/*.py" = ["UP006", "UP035"]
7776
"vllm/core/**/*.py" = ["UP006", "UP035"]
7877
"vllm/device_allocator/**/*.py" = ["UP006", "UP035"]

vllm/adapter_commons/layers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
from dataclasses import dataclass
4-
from typing import Tuple
54

65

76
@dataclass
87
class AdapterMapping:
98
# Per every token in input_ids:
10-
index_mapping: Tuple[int, ...]
9+
index_mapping: tuple[int, ...]
1110
# Per sampled token:
12-
prompt_mapping: Tuple[int, ...]
11+
prompt_mapping: tuple[int, ...]
1312

1413
def __post_init__(self):
1514
self.index_mapping = tuple(self.index_mapping)

vllm/adapter_commons/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
from abc import ABC, abstractmethod
4-
from typing import Any, Callable, Dict, Optional, TypeVar
4+
from typing import Any, Callable, Optional, TypeVar
55

66
from torch import nn
77

@@ -49,9 +49,9 @@ def __init__(
4949
model: the model to be adapted.
5050
"""
5151
self.model: nn.Module = model
52-
self._registered_adapters: Dict[int, Any] = {}
52+
self._registered_adapters: dict[int, Any] = {}
5353
# Dict instead of a Set for compatibility with LRUCache.
54-
self._active_adapters: Dict[int, None] = {}
54+
self._active_adapters: dict[int, None] = {}
5555
self.adapter_type = 'Adapter'
5656
self._last_mapping = None
5757

@@ -97,7 +97,7 @@ def get_adapter(self, adapter_id: int) -> Optional[Any]:
9797
raise NotImplementedError
9898

9999
@abstractmethod
100-
def list_adapters(self) -> Dict[int, Any]:
100+
def list_adapters(self) -> dict[int, Any]:
101101
raise NotImplementedError
102102

103103
@abstractmethod

vllm/adapter_commons/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
from typing import Any, Callable, Dict, Optional, Set
3+
from typing import Any, Callable, Optional
44

55

66
## model functions
7-
def deactivate_adapter(adapter_id: int, active_adapters: Dict[int, None],
7+
def deactivate_adapter(adapter_id: int, active_adapters: dict[int, None],
88
deactivate_func: Callable) -> bool:
99
if adapter_id in active_adapters:
1010
deactivate_func(adapter_id)
@@ -13,7 +13,7 @@ def deactivate_adapter(adapter_id: int, active_adapters: Dict[int, None],
1313
return False
1414

1515

16-
def add_adapter(adapter: Any, registered_adapters: Dict[int, Any],
16+
def add_adapter(adapter: Any, registered_adapters: dict[int, Any],
1717
capacity: int, add_func: Callable) -> bool:
1818
if adapter.id not in registered_adapters:
1919
if len(registered_adapters) >= capacity:
@@ -32,23 +32,23 @@ def set_adapter_mapping(mapping: Any, last_mapping: Any,
3232
return last_mapping
3333

3434

35-
def remove_adapter(adapter_id: int, registered_adapters: Dict[int, Any],
35+
def remove_adapter(adapter_id: int, registered_adapters: dict[int, Any],
3636
deactivate_func: Callable) -> bool:
3737
deactivate_func(adapter_id)
3838
return bool(registered_adapters.pop(adapter_id, None))
3939

4040

41-
def list_adapters(registered_adapters: Dict[int, Any]) -> Dict[int, Any]:
41+
def list_adapters(registered_adapters: dict[int, Any]) -> dict[int, Any]:
4242
return dict(registered_adapters)
4343

4444

4545
def get_adapter(adapter_id: int,
46-
registered_adapters: Dict[int, Any]) -> Optional[Any]:
46+
registered_adapters: dict[int, Any]) -> Optional[Any]:
4747
return registered_adapters.get(adapter_id)
4848

4949

5050
## worker functions
51-
def set_active_adapters_worker(requests: Set[Any], mapping: Optional[Any],
51+
def set_active_adapters_worker(requests: set[Any], mapping: Optional[Any],
5252
apply_adapters_func,
5353
set_adapter_mapping_func) -> None:
5454
apply_adapters_func(requests)
@@ -66,7 +66,7 @@ def add_adapter_worker(adapter_request: Any, list_adapters_func,
6666
return loaded
6767

6868

69-
def apply_adapters_worker(adapter_requests: Set[Any], list_adapters_func,
69+
def apply_adapters_worker(adapter_requests: set[Any], list_adapters_func,
7070
adapter_slots: int, remove_adapter_func,
7171
add_adapter_func) -> None:
7272
models_that_exist = list_adapters_func()
@@ -88,5 +88,5 @@ def apply_adapters_worker(adapter_requests: Set[Any], list_adapters_func,
8888
add_adapter_func(models_map[adapter_id])
8989

9090

91-
def list_adapters_worker(adapter_manager_list_adapters_func) -> Set[int]:
91+
def list_adapters_worker(adapter_manager_list_adapters_func) -> set[int]:
9292
return set(adapter_manager_list_adapters_func())

vllm/adapter_commons/worker_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
from abc import ABC, abstractmethod
4-
from typing import Any, Optional, Set
4+
from typing import Any, Optional
55

66
import torch
77

@@ -17,7 +17,7 @@ def is_enabled(self) -> bool:
1717
raise NotImplementedError
1818

1919
@abstractmethod
20-
def set_active_adapters(self, requests: Set[Any],
20+
def set_active_adapters(self, requests: set[Any],
2121
mapping: Optional[Any]) -> None:
2222
raise NotImplementedError
2323

@@ -34,5 +34,5 @@ def remove_all_adapters(self) -> None:
3434
raise NotImplementedError
3535

3636
@abstractmethod
37-
def list_adapters(self) -> Set[int]:
37+
def list_adapters(self) -> set[int]:
3838
raise NotImplementedError

0 commit comments

Comments
 (0)