Skip to content

Commit 42b7355

Browse files
Olivia-liupytorchbot
authored andcommitted
Handle empty (size=0) tensor in Inspector (#2998)
Summary: Pull Request resolved: #2998 Empty tensors are not handled so they throw errors. {F1484412951} Reviewed By: tarun292 Differential Revision: D56027102 fbshipit-source-id: a8dab52d9ba7eb0784a72493e9888cf63aefbb76 (cherry picked from commit f14dc83)
1 parent 7b29ad2 commit 42b7355

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

sdk/inspector/_inspector_utils.py

+3
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)