Fix loading error when safetensors contains empty tensor (#1687)

This commit is contained in:
twaka
2023-11-17 03:38:10 +09:00
committed by GitHub
parent 65ea2ddf17
commit 2a2c135b41

View File

@@ -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