Repository navigation
Conversation
Add per-block producer tracking on RefBundle and per-producer byte tracking in bundle queues to correctly attribute memory through ineligible operators (Union, Limit, etc.) back to their upstream eligible operators. - Add producer_op_ids tuple on RefBundle, propagated through slice/merge - Stamp producer_op_id on DataOpTask output bundles - Add estimate_size_bytes_for_producer to BundleQueue hierarchy - Add per-producer filtering to OpBufferQueue and resource manager - Collapse _internal_inqueues to single _internal_inqueue - Remove input_index from on_input_queued/on_input_dequeued - Mark Union as throttling_disabled (ineligible) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Revert the input_index -> producer_op_id migration on internal inqueues to reduce scope. Keep only the changes needed for ineligible op attribution: - producer_op_ids on RefBundle and propagation in merge/slice/split - Per-producer byte tracking in BundleQueue (combined estimate_size_bytes API) - OpBufferQueue.memory_usage_for_producer for external output queues - Resource manager ineligible op attribution via producer filtering - Union throttling_disabled - Add TODOs for future input_index -> producer_op_id migration Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add a per-block `producer_op_ids` tuple to RefBundle that tracks which eligible operator produced each block. This is plumbing for future per-producer memory attribution in ineligible operators (Union, etc.). - Add `producer_op_ids: Optional[Tuple[Optional[str], ...]]` to RefBundle - Initialize to `(None,) * len(blocks)` by default in __post_init__ - Add `size_bytes_per_producer()` method for per-producer byte accounting - Stamp producer_op_ids in DataOpTask.on_data_ready via new operator_id param - Propagate through all RefBundle construction sites: - RefBundle.slice() and RefBundle.merge_ref_bundles() - _merge_ref_bundles in map_operator - _split in output_splitter - LimitOperator._add_input_inner - dedupe_schemas_with_validation - stream_split_iterator block extraction - randomize_blocks shuffle Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces producer_op_ids to RefBundle and DataOpTask to enable per-producer memory attribution in Ray Data. The changes ensure that the UUID of the operator producing a block is tracked and propagated through various execution stages, including mapping, shuffling, limiting, and splitting operations. This metadata is utilized by a new method, size_bytes_per_producer, to calculate memory usage for downstream queue management. Feedback was provided regarding the duplication of block size estimation logic in RefBundle, suggesting that this logic be refactored into a shared helper method to improve maintainability and consistency.
Signed-off-by: Justin Yu <[email protected]>
Signed-off-by: Justin Yu <[email protected]>
|
Some quick thoughts: Should simplify the change overall |
| ] = lambda metadata_ref: None, | ||
| task_resource_bundle: Optional[ExecutionResources] = None, | ||
| operator_name: str = "Unknown", | ||
| operator_id: Optional[str] = None, |
There was a problem hiding this comment.
nit: can we use an alias here for operator_id type?
There was a problem hiding this comment.
I think it's fine to keep as string since the variable name is already clear.
| else: | ||
| if not isinstance(self.producer_op_ids, tuple): | ||
| object.__setattr__(self, "producer_op_ids", tuple(self.producer_op_ids)) | ||
| assert len(self.producer_op_ids) == len( |
There was a problem hiding this comment.
Won't this be false for 1 producer to many blocks cases?
There was a problem hiding this comment.
There's still one producer id per block. Ex: A single producer with 3 blocks would be ("uuid", "uuid", "uuid") — length 3 matches 3 blocks.
A single producer is the typical case, but I need to also account for merged bundles which could contain blocks from multiple producers.
There was a problem hiding this comment.
Btw, the reason for storing the tuple is:
- In the typical case, we output a bundle with a single block from a single producer: ex: ("uuid",)
- However, operators like MapOperator and StreamingRepartition can merge multiple input bundles into a single task input via BlockRefBundler. When this happens downstream of a Union, the merged bundle may contain blocks from different producers, e.g., ("uuid_a", "uuid_b").
- Per-block tracking ensures memory is correctly attributed to each producer even after merging.
|
@goutamvenkat-anyscale I think the However, this change would be a huge refactor since we use the blocks as |
These bulk operators create new output blocks without going through DataOpTask.on_data_ready(), so they need to stamp producer_op_ids directly. This ensures correct attribution when their output flows into downstream ineligible operators like Union. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- DataOpTask.on_data_ready stamps producer_op_ids with operator_id - AllToAllOperator.all_inputs_done stamps output bundles - RefBundle.slice() preserves producer_op_ids - RefBundle.merge_ref_bundles() concatenates producer_op_ids - LimitOperator preserves producer_op_ids - OutputSplitter._split() preserves producer_op_ids - Default, explicit, and length mismatch cases Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Remove the standalone _merge_ref_bundles function in map_operator.py and use the RefBundle.merge_ref_bundles classmethod instead. This avoids duplicating the merge logic including producer_op_ids concatenation. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
OutputSplitter is a terminal consumer (streaming_split), so producer_op_ids propagation there doesn't affect Union attribution behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Justin Yu <[email protected]>
AllToAll is the producer of its output bundles, so unconditionally stamping with self.id is correct. Remove the unnecessary per-block propagation in randomize_blocks since AllToAll overwrites it anyway. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Justin Yu <[email protected]>
bveeramani
left a comment
There was a problem hiding this comment.
Nice.
I don't think it's obvious from the PR description why we went with storing this on the RefBundle rather than on BlockMetadata. Could you include that context so it's accessible to future readers?
| # Per-block producer operator IDs, parallel to `blocks`. | ||
| # Each entry is the UUID of the eligible operator that produced that block. | ||
| # Used for per-producer memory attribution in downstream operators' queues. |
There was a problem hiding this comment.
Can you clarify what the expected meaning is if a block's producer_op_id is None? Does it mean that the producer is unknown, or that the block was created outside of the scope of this execution?
There was a problem hiding this comment.
- InputDataBuffer — Root-of-DAG bundles with no upstream operator.
- Shuffle intermediate outputs (pull/push-based shuffle, split repartition) — Intermediate bundles inside _bulk_fn before AllToAllOperator stamps them.
- Metrics-only bundles in HashShuffleOperator — Not real data flow.
- equalize.py — Post-execution repackaging in Dataset.split().
| # Per-block producer operator IDs, parallel to `blocks`. | ||
| # Each entry is the UUID of the eligible operator that produced that block. | ||
| # Used for per-producer memory attribution in downstream operators' queues. | ||
| producer_op_ids: Optional[Tuple[Optional[str], ...]] = None |
There was a problem hiding this comment.
If a developer forgets to specify this field, this will silently default to None and possibly introduce subtle accounting bugs. There are only a few call sites where this is None -- should we just make this field required and explicitly pass in None there? Would be a tradeoff against boilerplate.
Think it'd also clarify the type. The double optional is a bit complicated: Optional[Tuple[Optional[str], ...]]
| operator_name: The name of the physical operator that created this task. | ||
| Used for logging the operator name in warnings/errors. | ||
| operator_id: The UUID of the operator that created this task. | ||
| Stamped on output RefBundles for per-producer memory attribution. |
There was a problem hiding this comment.
Felt confused by "for per-producer memory attribution." at a first glance. Think this will be confusing to other readers with less context
| ] = lambda metadata_ref: None, | ||
| task_resource_bundle: Optional[ExecutionResources] = None, | ||
| operator_name: str = "Unknown", | ||
| operator_id: Optional[str] = None, |
There was a problem hiding this comment.
When can this be None? DataOpTask are always constructed by operators I thought?
- Move dataclasses import to top of test_limit_operator.py - Remove _limit_reached() usage in test - Use cleaner assertion pattern - Improve docstrings on RefBundle.producer_op_id and DataOpTask.operator_id Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 17a67ca. Configure here.
|
This pull request has been automatically marked as stale because it has not had 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. |
|
This pull request has been automatically closed because there has been no more activity in the 14 days Please feel free to reopen or open a new pull request if you'd still like this to be addressed. Again, you can always ask for help on our discussion forum or Ray's public slack channel. Thanks again for your contribution! |

Description
Adds a per-block tuple to
RefBundlethat tracks which operator produced each block. This is plumbing for per-producer memory attribution whenUnionbecomes an ineligible (pass-through) operator in a follow-up PR.Production Sites
Where
producer_op_idsis stampedDataOpTask.on_data_ready()— Streaming map/filter operators stamp each output block via the newoperator_idparam.AllToAllOperator.all_inputs_done()— Bulk operators (shuffle, sort, repartition,randomize_blocks) stamp output bundles withself.idafter_bulk_fnreturns.ZipOperator— Stamps output bundles at construction.HashShuffleOperator/GpuHashShuffleOperator— Passoperator_idtoDataOpTask.Propagation Sites
Where
producer_op_idsis preservedRefBundle.slice()— Tracksproducer_op_idsparallel to blocks in consumed/remaining halves.RefBundle.merge_ref_bundles()— Concatenates tuples from all input bundles.LimitOperator._add_input_inner()— Preserves per-blockproducer_op_idsthrough limiting.OutputSplitter._split()— Preserves per-blockproducer_op_idsthrough splitting.dedupe_schemas_with_validation()— Preserves when reconstructing a bundle with a unified schema.stream_split_iterator.py— Preserves when extracting/forwarding blocks to consumers.plan.py— Preserves when merging output bundles.Where
producer_op_idsEntries AreNoneWhy add to RefBundle rather than BlockMetadata?
We chose RefBundle over BlockMetadata because:
DataOpTask.on_data_ready(). There are 30+ construction sites across datasources, planners, exchange schedulers, block accessors, etc. — all would need updating for the same result.