Skip to content

Commit 2a2c135

Browse files
authored
Fix loading error when safetensors contains empty tensor (#1687)
1 parent 65ea2dd commit 2a2c135

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

vllm/model_executor/weight_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,12 @@ def convert_pyslice_to_tensor(x: Any) -> torch.Tensor:
258258
tensor first.
259259
"""
260260
if not isinstance(x, torch.Tensor):
261-
x = x[:]
261+
try:
262+
x = x[:]
263+
except IndexError:
264+
# IndexError happens when the tensor is empty.
265+
# transformer.h.0.attn.masked_bias is empty in some gpt2 models.
266+
return torch.Tensor()
262267
return x
263268

264269

0 commit comments

Comments
 (0)