Fix rel_diff being nan for bitwise-identical tensors (#30655)

This commit is contained in:
fzyzcjy
2026-07-09 20:16:18 +08:00
committed by GitHub
parent 0d7e8cfb85
commit 287291c232
2 changed files with 17 additions and 1 deletions
@@ -458,6 +458,20 @@ class TestComputeDiffPredicate:
is False
)
def test_bitwise_predicate(self) -> None:
"""'rel <= 0' passes only for bitwise-identical tensors."""
ident = torch.randn(5, 5)
assert (
compute_diff(
x_baseline=ident, x_target=ident.clone(), predicate="rel <= 0"
).passed
is True
)
x, y = self._near_zero_pair()
assert (
compute_diff(x_baseline=x, x_target=y, predicate="rel <= 0").passed is False
)
def test_predicate_recorded_for_empty_tensor(self) -> None:
"""Empty tensors short-circuit to passed=True and still record the predicate."""
empty = torch.empty(0)