Skip to content

Commit 281134d

Browse files
Handle empty (size=0) tensor in Inspector (#2998) (#3192)
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) Co-authored-by: Olivia Liu <[email protected]>
1 parent a94459a commit 281134d

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)