Skip to content

Commit 936c95e

Browse files
committed
remove asdict() which involves object deep copy.
Signed-off-by: Staszek Pasko <[email protected]>
1 parent c61c87a commit 936c95e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

vllm/v1/serial_utils.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ def enc_hook(self, obj: Any) -> Any:
9191
ret = []
9292
for elem in obj.values():
9393
# Encode as plain dictionary + special handling for .field
94-
ret.append(
95-
asdict(elem) | {"field": self._encode_field(elem.field)})
94+
ret.append({
95+
"modality": elem.modality,
96+
"key": elem.key,
97+
"data": self._encode_nested_tensors(elem.data),
98+
"field": self._encode_field(elem.field),
99+
})
96100
return ret
97101

98102
if isinstance(obj, FunctionType):
@@ -126,6 +130,11 @@ def _encode_ndarray(
126130
# backing buffers that we've stashed in `aux_buffers`.
127131
return obj.dtype.str, obj.shape, data
128132

133+
def _encode_nested_tensors(self, obj: Any) -> NestedTensors:
134+
if isinstance(obj, torch.Tensor):
135+
return self._encode_ndarray(obj.numpy())
136+
return [self._encode_nested_tensors(x) for x in obj]
137+
129138
def _encode_field(self, field: BaseMultiModalField):
130139
# Encode the field as a dictionary + special handling for .field
131140
d = asdict(field)

0 commit comments

Comments
 (0)