Skip to content

Round gaussian_blur outputs before OpenCV reference compare. - #9579

Open
dnikolaev-amd wants to merge 1 commit into
pytorch:mainfrom
dnikolaev-amd:fix/gaussian-blur-round-before-compare
Open

Round gaussian_blur outputs before OpenCV reference compare.#9579
dnikolaev-amd wants to merge 1 commit into
pytorch:mainfrom
dnikolaev-amd:fix/gaussian-blur-round-before-compare

Conversation

@dnikolaev-amd

@dnikolaev-amd dnikolaev-amd commented Aug 3, 2026

Copy link
Copy Markdown

OpenCV ground truth in gaussian_blur_opencv_results.pt is uint8 (discrete levels). torchvision returns float blur values, so compare rounded outputs to match integer reference semantics at atol=1.0

Fixes AssertionError at torch.testing.assert_close(out, true_out, rtol=0.0, atol=1.0, msg=f"{ksize}, {sigma}") if a small numerical noise (1ULP) occurs.

Example:

  • OpenCV uint8 -> fp32 reference value: 62.0
  • OpenCV float / torchvision fp32 / real value: ~61.05 (already within atol=1 vs 62)
  • torchvision fp16 on ROCm raw: ~60.94 -> |62 - 60.94| = 1.0625 fails atol=1.0
  • torchvision fp16 on ROCm after round: ~60.94 -> 61 -> |62 - 61| = 1.0 passes

Use round, not a bare .to(torch.uint8) on float outputs: PyTorch truncates float-to-uint8 (60.9375 -> 60), which gives |62 - 60| = 2.0 and fails. round(out) keeps assert_close aligned with true_out dtype (.to(tensor) leaves float refs as float).

All test_gaussian_blur cases that hit the reference pass with round + atol=1.0

Fixes AssertionError on ROCm:

  1. test_transforms_tensor.py::test_gaussian_blur[3-meth_kwargs4-cuda]
  2. test_functional_tensor.py::test_gaussian_blur[gaussian_blur-sigma3-ksize2-dt3-large-cuda]

As a replacement for #9509

cc @jeffdaily @jithunnair-amd

@pytorch-bot

pytorch-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9579

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@dnikolaev-amd

Copy link
Copy Markdown
Author

Hi @NicolasHug,
could you review it?

OpenCV ground truth in gaussian_blur_opencv_results.pt is uint8 (discrete
gray levels). torchvision returns float blur values, so compare rounded
outputs to match integer reference semantics at atol=1.0.

Example (small image, kernel [3, 5], sigma 0.8, channel 0 at (9, 0)):
- OpenCV uint8 reference: 62
- OpenCV float / torchvision fp32: ~61.05 (already within atol=1 vs 62)
- torchvision fp16 on ROCm raw: ~60.94 -> |62 - 60.94| = 1.0625 fails atol=1.0
- after round: 61 -> |62 - 61| = 1.0 passes

Use round, not a bare .to(torch.uint8) on float outputs: PyTorch truncates
float-to-uint8 (60.9375 -> 60), which gives |62 - 60| = 2.0 and fails.
round(out) is enough here and keeps assert_close aligned with true_out
dtype (.to(tensor) leaves float refs as float).

All test_gaussian_blur cases that hit the reference pass with round + atol=1.0.
@dnikolaev-amd
dnikolaev-amd force-pushed the fix/gaussian-blur-round-before-compare branch from a1b559b to adb2add Compare August 11, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant