Skip to content

[Data] Reject non-finite weights in Dataset.mix - #67506

Open
hello-peter-tang wants to merge 3 commits into
ray-project:masterfrom
hello-peter-tang:feat/67387-mix-nonfinite-weights
Open

hello-peter-tang wants to merge 3 commits into
ray-project:masterfrom
hello-peter-tang:feat/67387-mix-nonfinite-weights

Conversation

@hello-peter-tang

@hello-peter-tang hello-peter-tang commented Oct 28, 2026 •

Copy link
Copy Markdown

Why are these changes needed?

Dataset.mix only rejected weights with weight <= 0. That lets NaN and +inf through, and they are then divided by the total weight, producing non-finite normalized weights that corrupt the deficit-based block selection. -inf was rejected, but with the misleading "Weights must be positive" message.

What is the change?

  • Added validate_mix_weights(), shared by the logical Mix operator and the physical MixOperator.
  • Non-finite weights now raise ValueError: Weights must be finite. Got weights: [...]; zero and negative weights keep the existing positive-weights error.
  • Documented the validation on Dataset.mix.

Related issue number

Fixes #67387

Tests

  • Added parameterized tests for nan, inf, -inf, 0.0, and -1.0 at both the Dataset.mix level and the MixOperator level.
  • python/ray/data/tests/test_mix.py: 30 passed (20 existing + 10 new).
  • black and ruff clean on the touched files.

AI assistance: developed with an AI coding agent; the human submitter reviewed the diff and ran the tests above.

@hello-peter-tang
hello-peter-tang requested a review from a team as a code owner October 28, 2026 09:32

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread python/ray/data/tests/test_mix.py Resolved
@ray-gardener ray-gardener Bot added docs An issue or change related to documentation data Ray Data-related issues community-contribution Contributed by the community labels Oct 28, 2026

@Jadiouo Jadiouo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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?

@hello-peter-tang

Copy link
Copy Markdown
Author

@richardliaw — there's now an independent reproduction on the linked issue: @Jadiouo verified against base 8bfa990 vs this PR's head (702036c) that on base weights=[nan, 1] and [inf, 1] are accepted by mix() and execution hangs, while this PR raises ValueError immediately. That's the "someone actually ran into it" signal you asked for on #67387. Given the failure mode is a hang rather than a clear error, would you be open to lifting the hold-off and having this land as a cheap guard? Happy to close it if you'd still rather wait.

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 <[email protected]>
@hello-peter-tang
hello-peter-tang force-pushed the feat/67387-mix-nonfinite-weights branch from 702036c to e5a24a9 Compare November 4, 2026 04:18
@hello-peter-tang

Copy link
Copy Markdown
Author

I merged master into this branch to clear the 85-commit gap. buildkite/microcheck came back red on the new head (f7b1c83) while everything else is green.

I could not read the failure — the Buildkite build page requires a login and the API returns 401 unauthenticated. What I could check: of the 8 most recently updated open PRs, 4 fail microcheck and 4 pass, mixing branches 345 commits behind master with branches at 0. That points at a repo-wide flaky job rather than this diff (validate_mix_weights plus its unit tests).

Could a maintainer re-run microcheck? If the log points into python/ray/data/_internal/execution/operators/mix_operator.py or python/ray/data/dataset.py I will fix it right away.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Nov 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues docs An issue or change related to documentation stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Data] Dataset.mix does not consistently reject non-finite weights

2 participants