Repository navigation
[Data] Reject non-finite weights in Dataset.mix - #67506
hello-peter-tang wants to merge 1 commit into
Conversation
Dataset.mix only checked `weight <= 0`, which lets NaN and +inf through; they then flow into the normalized weights and corrupt the deficit-based selection. Validate that weights are finite in both the logical and physical Mix operators, and document it on the public API. Signed-off-by: hello-peter-tang <132056702+hello-peter-tang@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a centralized validate_mix_weights function to ensure that mix weights are positive and finite, preventing issues with NaN or infinite values. It updates the dataset documentation and adds unit tests to verify this validation. A review comment identifies a missing import of MixOperator in the new test cases, which would lead to a NameError during execution.
| from unittest.mock import MagicMock | ||
|
|
||
| from ray.data._internal.execution.interfaces import PhysicalOperator | ||
|
|
There was a problem hiding this comment.
The test uses MixOperator on line 56, but it is not imported within this test function. If MixOperator is not imported at the top of test_mix.py, this will raise a NameError during test execution. To ensure the test is self-contained and robust, please import MixOperator locally.
| from unittest.mock import MagicMock | |
| from ray.data._internal.execution.interfaces import PhysicalOperator | |
| from unittest.mock import MagicMock | |
| from ray.data._internal.execution.interfaces import PhysicalOperator | |
| from ray.data._internal.execution.operators.mix_operator import MixOperator |
Jadiouo
left a comment
There was a problem hiding this comment.
Verified against base 8bfa990 and head 702036c (Python 3.13, CPU only, Ray nightly with ray/data swapped).
Through the public API (ds1.mix(ds2, weights=...), then take_all()): on base, weights=[nan, 1] and [inf, 1] are accepted by mix() and execution then hangs (I stopped it after 30s). With the PR, NaN, +inf and -inf raise ValueError: Weights must be finite. Got weights: [...] at the mix() call. Zero, negative and all-zero weights still raise the "positive" error, and finite weights produce the same block order as base. test_mix.py: 30 passed; the nan/inf/-inf cases fail on base.
Two small things: the gemini comment about a missing MixOperator import doesn't apply, since it's imported at the top of the file. The two parametrize lists are identical and could share one constant.
One question: richardliaw suggested on #67387 holding off until more people report this. Has that been cleared?
|
@richardliaw — there's now an independent reproduction on the linked issue: @Jadiouo verified against base |
Why are these changes needed?
Dataset.mixonly rejected weights withweight <= 0. That letsNaNand+infthrough, and they are then divided by the total weight, producing non-finite normalized weights that corrupt the deficit-based block selection.-infwas rejected, but with the misleading "Weights must be positive" message.What is the change?
validate_mix_weights(), shared by the logicalMixoperator and the physicalMixOperator.ValueError: Weights must be finite. Got weights: [...]; zero and negative weights keep the existing positive-weights error.Dataset.mix.Related issue number
Fixes #67387
Tests
nan,inf,-inf,0.0, and-1.0at both theDataset.mixlevel and theMixOperatorlevel.python/ray/data/tests/test_mix.py: 30 passed (20 existing + 10 new).blackandruffclean on the touched files.