Skip to content

Commit

Permalink
Handle empty (size=0) tensor in Inspector (#2998)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Olivia-liu authored and facebook-github-bot committed Apr 17, 2024
1 parent 5d7949d commit f14dc83
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sdk/inspector/_inspector_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit f14dc83

Please sign in to comment.