Skip to content

Commit d9f96e8

Browse files
Olivia-liufacebook-github-bot
authored andcommitted
Handle empty (size=0) tensor in Inspector (#2998)
Summary: Empty tensors are not handled so they throw errors. {F1484412951} Reviewed By: tarun292 Differential Revision: D56027102
1 parent c73bfc0 commit d9f96e8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

sdk/inspector/_inspector_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ def get_scalar_type_size(scalar_type: ScalarType) -> Tuple[torch.dtype, int]:
103103
return torch.zeros(tensor.sizes, dtype=torch_dtype)
104104

105105
tensor_bytes_size = math.prod(tensor.sizes) * dtype_size
106+
if tensor_bytes_size == 0:
107+
# Empty tensor. Return empty tensor.
108+
return torch.zeros(tensor.sizes, dtype=torch_dtype)
106109

107110
if tensor.offset is None:
108111
raise ValueError("Tensor offset cannot be None")

0 commit comments

Comments
 (0)