Skip to content

Commit b90d8cd

Browse files
authored
[Distributed] Make it clear that % should not be in tensor dict keys. (#5927)
Signed-off-by: Xiaowei Jiang <[email protected]>
1 parent 3b752a6 commit b90d8cd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

tests/distributed/test_parallel_state.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any, Dict
22

3+
import pytest
34
import torch
45

56
from vllm.distributed.parallel_state import (_split_tensor_dict,
@@ -24,14 +25,21 @@ def test_split_tensor_dict():
2425
assert torch.allclose(tensor_list[2], test_dict["key_c"]["key_2"])
2526

2627

28+
def test_split_tensor_dict_invalid_key():
29+
test_dict = {
30+
"a%b": "a",
31+
}
32+
with pytest.raises(AssertionError):
33+
_split_tensor_dict(test_dict)
34+
35+
2736
def test_update_nested_dict():
2837
flattened_keys_values = [("key1%key2%key3", "value1"),
2938
("key1%key2%key4", "value2"),
3039
("key1%key5", "value3"), ("key6%key7", "value4"),
3140
("key8", "value5")]
3241
res: Dict[str, Any] = {}
3342

34-
# Update the nested dictionary with each flattened key-value pair
3543
for flat_key, value in flattened_keys_values:
3644
_update_nested_dict(res, flat_key, value)
3745
assert res == {

vllm/distributed/parallel_state.py

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def _split_tensor_dict(
5858
metadata_list: List[Tuple[str, Any]] = []
5959
tensor_list = []
6060
for key, value in tensor_dict.items():
61+
assert "%" not in key, (
62+
"Avoid having '%' in key "
63+
"as it is used as a separator for nested entries.")
6164
if isinstance(value, torch.Tensor):
6265
# Note: we cannot use `value.device` here,
6366
# because it contains not only the device type but also the device

0 commit comments

Comments
 (0)