π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
test(geometry): handle CUDA meshgrid trace one-ULP divergence (#4824)
Puttala Jeevan Kumarad1b408c4da4
diff --git a/tests/geometry/test_grid.py b/tests/geometry/test_grid.pyindex c67ffb520..5850117f6 100644--- a/tests/geometry/test_grid.py+++ b/tests/geometry/test_grid.py@@ -146,12 +146,12 @@ def test_normalized_meshgrid_trace_matches_eager_at_unrepresentable_sizes(is_3d,``bfloat16`` holds 299 only as 300, so casting ``size - 1`` into the coordinate dtype beforedividing shifts every normalized coordinate -- up to 0.0078 in bfloat16, 0.00098 in float16.Eager divides by a Python ``int``, so the traced graph has to divide against the unrounded- size too and round only the quotient. Every size the singleton-boundary tests above use is+ size too and narrow only after normalization. Every size the singleton-boundary tests above use isrepresentable in all four dtypes, so none of them can catch this.The sizes here are the ones whose predecessor is *not* exactly representable in bfloat16- (all five) or float16 (2050 and 3000); at float32 and float64 they all are, which pins the- two paths as agreeing there rather than merely not being compared.+ (all five) or float16 (2050 and 3000). CPU eager supplies the correctly rounded reference;+ exact comparison at every dtype preserves the half-precision regression check."""class MeshGrid(torch.nn.Module):@@ -172,7 +172,9 @@ def test_normalized_meshgrid_trace_matches_eager_at_unrepresentable_sizes(is_3d,shape = (1, 1, 2, size, 4) if is_3d else (1, 1, size, 4)image = torch.zeros(*shape, device=device, dtype=dtype)traced = torch.jit.trace(MeshGrid(), image)- assert_close(traced(image), MeshGrid()(image), atol=0.0, rtol=0.0)+ # CUDA eager's Python-scalar division multiplies by a host-computed reciprocal, which can+ # round differently from the traced tensor division (#4195).+ assert_close(traced(image).cpu(), MeshGrid()(image.cpu()), atol=0.0, rtol=0.0)@pytest.mark.parametrize("normalized_coordinates", [False, True], ids=["pixel", "normalized"])