fix: reenable flaky tests on test_torch_kmeans.py#7849
Conversation
📝 WalkthroughWalkthroughThe Torch KMeans tests are re-enabled. One test uses explicit duplicate centroids with CPU execution, while the device-acceptance test passes an explicit CPU device. ChangesTorch KMeans test execution
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Note
Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.
🟡 Other comments (1)
python/python/tests/torch_tests/test_torch_kmeans.py-19-23 (1)
19-23: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winSeed the empty-cluster repair path.
KMeans._updated_centroidsstill calls unseededtorch.rand_likewhen a cluster is empty, so this test can still vary run to run. Seed the CPU RNG locally or make the assertion independent of that perturbation.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@python/python/tests/torch_tests/test_torch_kmeans.py` around lines 19 - 23, Make the test around KMeans._updated_centroids deterministic by locally seeding the CPU Torch RNG before kmeans.fit(arr), or revise its assertions so they do not depend on the random empty-cluster repair perturbation. Keep the duplicate-centroid setup and validate the intended empty-cluster recovery behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Other comments:
In `@python/python/tests/torch_tests/test_torch_kmeans.py`:
- Around line 19-23: Make the test around KMeans._updated_centroids
deterministic by locally seeding the CPU Torch RNG before kmeans.fit(arr), or
revise its assertions so they do not depend on the random empty-cluster repair
perturbation. Keep the duplicate-centroid setup and validate the intended
empty-cluster recovery behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: QUIET
Plan: Pro Plus
Run ID: e3bd19cf-0237-417e-a256-0e84eccf8d93
📒 Files selected for processing (1)
python/python/tests/torch_tests/test_torch_kmeans.py
Seems like the tests are not flaky anymore and we could re-enable them. Fixes #1683 .