Unverified Commit 2a2c135b authored by twaka's avatar twaka Committed by GitHub
Browse files

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

parent 65ea2ddf
......@@ -258,7 +258,12 @@ def convert_pyslice_to_tensor(x: Any) -> torch.Tensor:
tensor first.
"""
if not isinstance(x, torch.Tensor):
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment