-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VLM][Bugfix] Make sure that
multi_modal_kwargs
is broadcasted prop…
…erly (#5880) Signed-off-by: Xiaowei Jiang <xwjiang2010@gmail.com>
- Loading branch information
1 parent
6eabc6c
commit d12af20
Showing
3 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from typing import Any, Dict | ||
|
||
import torch | ||
|
||
from vllm.distributed.parallel_state import (_split_tensor_dict, | ||
_update_nested_dict) | ||
|
||
|
||
def test_split_tensor_dict(): | ||
test_dict = { | ||
"key_a": "a", | ||
"key_b": torch.arange(8, dtype=torch.float32), | ||
"key_c": { | ||
"key_1": torch.arange(5, dtype=torch.float32), | ||
"key_2": torch.tensor([], dtype=torch.float32), | ||
"key_3": 123, | ||
}, | ||
"key_d": {}, | ||
} | ||
metadata_list, tensor_list = _split_tensor_dict(test_dict) | ||
assert len(metadata_list) == 6 | ||
assert torch.allclose(tensor_list[0], test_dict["key_b"]) | ||
assert torch.allclose(tensor_list[1], test_dict["key_c"]["key_1"]) | ||
assert torch.allclose(tensor_list[2], test_dict["key_c"]["key_2"]) | ||
|
||
|
||
def test_update_nested_dict(): | ||
flattened_keys_values = [("key1%key2%key3", "value1"), | ||
("key1%key2%key4", "value2"), | ||
("key1%key5", "value3"), ("key6%key7", "value4"), | ||
("key8", "value5")] | ||
res: Dict[str, Any] = {} | ||
|
||
# Update the nested dictionary with each flattened key-value pair | ||
for flat_key, value in flattened_keys_values: | ||
_update_nested_dict(res, flat_key, value) | ||
assert res == { | ||
"key1": { | ||
"key2": { | ||
"key3": "value1", | ||
"key4": "value2" | ||
}, | ||
"key5": "value3" | ||
}, | ||
"key6": { | ||
"key7": "value4" | ||
}, | ||
"key8": "value5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters