From 3b3161d3509ff38c3e51fb7cb5d87d6d5270136d Mon Sep 17 00:00:00 2001 From: twaka Date: Fri, 17 Nov 2023 03:38:10 +0900 Subject: [PATCH] Fix loading error when safetensors contains empty tensor (#1687) --- vllm/model_executor/weight_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vllm/model_executor/weight_utils.py b/vllm/model_executor/weight_utils.py index 0a05fe7e340b4..a91eaab5e7cfa 100644 --- a/vllm/model_executor/weight_utils.py +++ b/vllm/model_executor/weight_utils.py @@ -258,7 +258,12 @@ def convert_pyslice_to_tensor(x: Any) -> torch.Tensor: tensor first. """ if not isinstance(x, torch.Tensor): - x = x[:] + try: + x = x[:] + except IndexError: + # IndexError happens when the tensor is empty. + # transformer.h.0.attn.masked_bias is empty in some gpt2 models. + return torch.Tensor() return x