Fix loading error when safetensors contains empty tensor (#1687)
This commit is contained in:
parent
65ea2ddf17
commit
2a2c135b41
@ -258,7 +258,12 @@ def convert_pyslice_to_tensor(x: Any) -> torch.Tensor:
|
|||||||
tensor first.
|
tensor first.
|
||||||
"""
|
"""
|
||||||
if not isinstance(x, torch.Tensor):
|
if not isinstance(x, torch.Tensor):
|
||||||
|
try:
|
||||||
x = x[:]
|
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
|
return x
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user