Skip to content

Commit

Permalink
fix: aminmax throws error if input is empty tensor
Browse files Browse the repository at this point in the history
  • Loading branch information
kiya00 committed Nov 19, 2024
1 parent 4554dcf commit d457c19
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions thunder/dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def _get_example_input_tensor_metadata(t: torch.Tensor) -> ExampleInputMetaData:
_get_storage_shape(t),
_concrete_value(t.stride()),
)
if not isinstance(t, FakeTensor):
if not isinstance(t, FakeTensor) and t.numel() != 0:
minmax: tuple[torch.Tensor, torch.Tensor] = torch.aminmax(t)
meta_ev.min_val = minmax[0].cpu().item()
meta_ev.max_val = minmax[1].cpu().item()
Expand Down Expand Up @@ -620,10 +620,13 @@ def remove_empty_autocast(graph_module: torch.fx.GraphModule) -> torch.fx.GraphM

def arg_like_tensor(arg: torch.Tensor | ExampleInputMetaData):
"""Creates a new argument like the given tensor or tensor metadata"""
min_val = None
max_val = None
if isinstance(arg, torch.Tensor):
min_val, max_val = torch.aminmax(arg)
min_val = min_val.cpu().item()
max_val = max_val.cpu().item()
if arg.numel() != 0:
min_val, max_val = torch.aminmax(arg)
min_val = min_val.cpu().item()
max_val = max_val.cpu().item()
else:
min_val, max_val = arg.min_val, arg.max_val
storage_shape = _get_storage_shape(arg) if isinstance(arg, torch.Tensor) else arg.storage_shape
Expand Down

0 comments on commit d457c19

Please sign in to comment.