intel / torch-xpu-ops

Apache License 2.0
30 stars 21 forks source link

[2025 bundle] test_non_standard_bool_values failed with view created from torch.randint() #1048

Closed daisyden closed 1 day ago

daisyden commented 2 weeks ago

🐛 Describe the bug

With 2025 bundle, we got failed on this case "PYTORCH_TEST_WITH_SLOW=1 pytest -vs test_ops_xpu.py -k test_non_standard_bool_values_index_put_xpu_bool". The test will transform the input sample with convert_boolean_tensors() and compare the output with transformed input and original input. However, with torch.randint() to evaluate true_vals it failed, while with torch.ones() to evalute true_vals it passed. Is it a problem related to c10 load? @xytintel

       def convert_boolean_tensors(x):
            if not isinstance(x, torch.Tensor) or x.dtype != torch.bool:
                return x

            # Map False -> 0 and True -> Random value in [2, 255]
            true_vals = torch.randint(
                2, 255, x.shape, dtype=torch.uint8, device=x.device
            )

            #true_vals = torch.ones(x.shape, dtype=torch.uint8, device=x.device)
            false_vals = torch.zeros((), dtype=torch.uint8, device=x.device)

            x_int = torch.where(x, true_vals, false_vals)

            ret = x_int.view(torch.bool)
            self.assertEqual(ret, x)

            return ret

Versions

torch-xpu-ops 9fc5d81c27f04ec767dd57af1e3ada05c5dda10c