8000 [MPS] Fix error check for torch.var on scalar by malfet · Pull Request #160889 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension 8000

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aten/src/ATen/native/mps/operations/ReduceOps.mm
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ static Tensor std_var_common_impl_mps(const Tensor& input_t,
errMessage += ": reduction dim must be in the range of input shape";
for (const auto dim : dim_value) {
auto wrap_dim = maybe_wrap_dim(dim, num_input_dims);
TORCH_CHECK(wrap_dim < static_cast<decltype(wrap_dim)>(input_shape.size()), errMessage.c_str())
TORCH_CHECK(wrap_dim < (num_input_dims ? num_input_dims : 1), errMessage.c_str())
}
}

Expand Down
3 changes: 3 additions & 0 deletions test/test_mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5321,6 +5321,9 @@ def helper():

helper()

# Regression test for https://github.com/pytorch/pytorch/issues/160738
self.assertTrue(torch.var(torch.tensor(3.13, device='mps'), dim=0).isnan().item())

# Test forward amax
def test_amax(self):
def helper(shape, dim, keepdim):
Expand Down
Loading
0