Skip to content

[Dy2St] Make RandomRotation static comparison deterministic#78562

Merged
SigureMo merged 1 commit intoPaddlePaddle:developfrom
ShigureNyako:fix/macos-randomrotation-static-flake
Apr 2, 2026
Merged

[Dy2St] Make RandomRotation static comparison deterministic#78562
SigureMo merged 1 commit intoPaddlePaddle:developfrom
ShigureNyako:fix/macos-randomrotation-static-flake

Conversation

@ShigureNyako
Copy link
Copy Markdown
Contributor

PR Category

Environment Adaptation

PR Types

Not User Facing

Description

This PR fixes a recurring Mac-CPU CI flake in test_transforms_static, observed while validating #78558.

The failing case is TestRandomRotation_expand_True, which compares dynamic and static outputs with np.testing.assert_almost_equal. The current test tries to make RandomRotation effectively deterministic by passing a very narrow degree range, but it still samples the angle from two different RNG paths:

  • dynamic mode: random.uniform(...)
  • static mode: paddle.uniform(...)

That means the test is not actually comparing the same rotation angle in the two modes. On macOS this sometimes shows up as a few mismatched edge pixels after expand=True, causing the test to fail on one run and pass on rerun.

To fix that, this PR keeps the change scoped to the test file:

  • add a local deterministic FixedAngleRandomRotation helper in test/legacy_test/test_transforms_static.py
  • use the exact same fixed angle for both TestRandomRotation and TestRandomRotation_expand_True

This does not hide a real kernel bug. It makes the test validate the intended contract more accurately: dynamic and static RandomRotation should match when given the same input and the same angle.

是否引起精度变化

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 2, 2026

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Apr 2, 2026
@ShigureNyako
Copy link
Copy Markdown
Contributor Author

@SigureMo

我先自 review 过这一版了,改动只落在 test/legacy_test/test_transforms_static.py

结论:这次修的是 RandomRotation 静态/动态图对比单测本身的随机性来源不一致问题,不是去放宽断言阈值。

关键信息:

  • python/paddle/vision/transforms/transforms.py:1824-1830 里,RandomRotation._get_param() 在动态图走 random.uniform(...),在静态图走 paddle.uniform(...)
  • 原测试虽然把角度范围收得很窄,但两边实际上还是会采样到不同角度;在 macOS 上 expand=True 时就会偶发成边缘像素不一致
  • 这版在测试文件里加了一个本地 FixedAngleRandomRotation helper,只把采样角度固定住,仍然走 RandomRotation 的旋转逻辑和 expand=True 路径

所以它不会掩盖真实算子 bug;如果同一个输入、同一个角度下静态/动态图旋转结果真的不一致,这个测试还是会继续失败。

@SigureMo SigureMo changed the title [Test] Make RandomRotation static comparison deterministic [Dy2St] Make RandomRotation static comparison deterministic Apr 2, 2026
@SigureMo SigureMo changed the title [Dy2St] Make RandomRotation static comparison deterministic [Dy2St] Make RandomRotation static comparison deterministic Apr 2, 2026
@ShigureNyako
Copy link
Copy Markdown
Contributor Author

/re-run all-failed

Copy link
Copy Markdown
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

@SigureMo SigureMo merged commit 53326c8 into PaddlePaddle:develop Apr 2, 2026
106 of 109 checks passed
@SigureMo SigureMo deleted the fix/macos-randomrotation-static-flake branch April 2, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants