From d9f96e80ff0bbf8675f0866751193285bc4076b8 Mon Sep 17 00:00:00 2001 From: Olivia Liu Date: Tue, 16 Apr 2024 15:57:21 -0700 Subject: [PATCH] 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 --- sdk/inspector/_inspector_utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/inspector/_inspector_utils.py b/sdk/inspector/_inspector_utils.py index a71d34753b3..ecef1d13e73 100644 --- a/sdk/inspector/_inspector_utils.py +++ b/sdk/inspector/_inspector_utils.py @@ -103,6 +103,9 @@ def get_scalar_type_size(scalar_type: ScalarType) -> Tuple[torch.dtype, int]: return torch.zeros(tensor.sizes, dtype=torch_dtype) tensor_bytes_size = math.prod(tensor.sizes) * dtype_size + if tensor_bytes_size == 0: + # Empty tensor. Return empty tensor. + return torch.zeros(tensor.sizes, dtype=torch_dtype) if tensor.offset is None: raise ValueError("Tensor offset cannot be None")