Repository navigation
Conversation
Track row deficits in MixOperator with exact rational weights for finite weights and, under STOP_ON_SHORTEST, stop only when a completed input has zero rows or the next deficit-selected input is exhausted. Queue one available empty block before stopping on a zero-row input when the output buffer is empty so zero-row results retain their schema, and dequeue remaining buffered inputs from runtime metrics when finishing. Closes ray-project#68628 Signed-off-by: mora <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request enhances the MixOperator to correctly handle the STOP_ON_SHORTEST stopping condition, stopping execution when the next selected input is exhausted or when any input is known to be empty. It also introduces exact weight tracking using Fraction to prevent rounding errors and deficit ties, and ensures that discarded inputs are properly dequeued to release bundle references. A review comment suggests directly converting weights to strings instead of casting them to floats first when constructing Fraction objects to avoid potential precision loss.
| exact_weights = [ | ||
| Fraction(w) | ||
| if isinstance(w, (int, Fraction)) | ||
| else Fraction(str(float(w))) |
There was a problem hiding this comment.
Converting w to float before converting to str can cause precision loss for large integer types (such as numpy.int64 or other custom numeric types) that are not standard Python int or Fraction. Directly converting w to str is safer and preserves full precision.
| else Fraction(str(float(w))) | |
| else Fraction(str(w)) |
…egral weights Override clear_internal_input_queue and clear_internal_output_queue on MixOperator so early executor shutdown drops runtime-metric references alongside normal completion, and accept numbers.Integral weights without float rounding loss. Signed-off-by: mora <[email protected]>
Summary
Allow underrepresented inputs to catch up before
Dataset.mix(..., stopping_condition=MixStoppingCondition.STOP_ON_SHORTEST)stops, and release operator-held references to discarded buffered inputs when the operator finishes, closing #68628. Open PR #67506 rejects non-finiteDataset.mixweights at initialization rather than changing runtime stopping or input cleanup.Before
Calling
ds1.mix(ds2, ..., stopping_condition=MixStoppingCondition.STOP_ON_SHORTEST)stops pulling inputs as soon as any completed input's buffer becomes empty, even if slower or finer-grained inputs still owe rows toward their target share (for example, returning[20, 0]instead of[20, 20]atweights=[1, 1]). Before completion is reported, floating-point rounding on decimal weights can also break an exact tie and pull an extra block ([63, 28]instead of[63, 27]at[0.7, 0.3]), and discarded buffered inputs remain referenced by operator metrics during output draining and while the operator stays reachable.After
MixOperatornow computes row deficits with exact rational weights for finite weights and, underSTOP_ON_SHORTEST, stops when a completed input has zero rows or once the next deficit-selected input is exhausted. When a zero-row completed input stops the mix while the output buffer is empty, one available empty block is queued first so zero-row results keep their schema; finishing or early shutdown then dequeues remaining buffered inputs from both input queues and runtime metrics.STOP_ON_LONGEST_DROPstill skips exhausted inputs and consumes the remaining datasets, and available blocks from the selected input continue to emit before other upstream tasks finish.flowchart LR subgraph Before B1["Execution: MixOperator (stops when any completed input empties)"] -. skips owed pulls & keeps metric refs .-> B2["Dataset.mix truncates owed rows & retains discarded refs"] end subgraph After A1["Execution: MixOperator (stops on empty input or exhausted selected input)"] -. pulls owed blocks & dequeues metric refs .-> A2["Dataset.mix lets owed inputs catch up & releases refs"] end classDef bad fill:#ffcdd2,stroke:#c62828,color:#000 classDef changed fill:#fff9c4,stroke:#f9a825,color:#000 classDef good fill:#c8e6c9,stroke:#2e7d32,color:#000 class B1,B2 bad class A1 changed class A2 goodSubsystems
Execution.
Testing
Local validation passed on Python 3.11.15 / Ray 2.60.1 (
arm64macOS) and Python 3.12.16 / Ray 3.0.0.dev0 (e4462656e8,aarch64Linux, PyArrow 26.0.1) with the updatedray.datasources loaded on both driver and workers. Tests cover uneven block boundaries across 2- and 3-way mixes, task and gated arrival orders, exact decimal/integer/rational weight ties (including large integer weights), empty-input schema preservation across input positions, and reference/metrics release for discarded input blocks.Pre-commit hooks (including
pyrefly-data) and pytest lint checks also passed.AI assistance was used.