Repository navigation
[data][train][1/n] Push-based streaming_split - #65842
xinyuangui2 wants to merge 38 commits into
Conversation
…ks to consumer actors) Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
… order Multi-threaded actors dispatch tasks by argument readiness, so receive_block calls could reorder and an argless receive_eof could overtake blocks still fetching their args (dropping rows). Stamp each push with a per-split seq and reorder in the consumer's data thread before releasing to the local queue. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
…Config - Coordinator gains a generic consumer mode: pushes go through the actor's built-in __ray_call__ into a process-local receiver registry, with bundles carrying nested (unmaterialized) refs so the standard DataIterator prefetch/resolve/collate pipeline is reused unchanged. - PushBasedDataIterator self-registers the hosting train worker actor at iteration time (current_actor), so no Ray Train core changes are needed. - PushBasedDataConfig is a drop-in dataset_config replacement. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
Adds --ray_data_push_based_split (+ optional --ray_data_push_target_buffer_rows) to the train benchmark, returning PushBasedDataConfig from RayDataLoaderFactory, and manual-frequency full_training.parquet.push_based / skip_training.parquet.push_based variations of training_ingest_benchmark-task=image_classification. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
…add TODOs - Remove PushSplitConsumer and the 'methods' push mode: only the throwaway bench used it; PushBasedDataIterator (generic __ray_call__ path) is strictly more general. One push mechanism left. - Remove _push_lock: every per-split counter has a single writer (its own pusher thread); cross-thread readers only compute the heuristic external-consumer-bytes sum. Contract documented in __init__. - Document why create_push_split replicates the StreamingSplit wrapping (same construction Dataset.streaming_split does before the pull SplitCoordinator; it plans to OutputSplitter, which per-split queues route on). - TODO: park pusher threads on consumer death and resume when a replacement worker re-registers, instead of exiting. - TODO: verify set_external_consumer_bytes is still needed under push. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
…_based; disable external-consumer-bytes feed - Align with the pull impl: dataset.py now wraps the StreamingSplit op and calls PushBasedDataIterator.create (mirroring streaming_split / StreamSplitDataIterator.create); create_push_split is gone and PushBasedDataConfig.configure now mirrors DataConfig.configure exactly. - Comment out set_external_consumer_bytes registration + updates to check whether the feed is needed at all under push (credit + blocking get_next may suffice); re-enable together if slow-consumer runs regress. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
…et.py) Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
…/_QueueItem Replaces the anonymous (bundle, rows, bytes) tuple and Any annotations. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
…, not just refs The block ref rides twice: nested in the bundle (the pipeline needs refs) and as a resolved top-level arg, so Ray fetches the block to the consumer node before the delivery executes; resolve's ray.get becomes a local hit. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
Only metadata rides in the sequenced message (_BlockPush); the block ref is a resolved top-level arg, so the consumer receives the Block by value, never borrows the executor's refs, and re-owns the block via ray.put into a local single-block RefBundle for the standard pipeline. The executor can free each block as soon as its delivery completes; the cost is one local object-store copy per block. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
…-wrap Blocks already arrive materialized, so re-wrapping them into a RefBundle via ray.put was a pointless object-store copy. The receiver queue now holds raw Blocks and _MaterializedBatchIterator (a BatchIterator subclass) starts the pipeline at the batching stage — format/collate threadpool, order restore, and finalize (everything iter_torch_batches needs) are inherited unchanged; the ref-level prefetch/resolve stages are gone. Still zero borrowed refs. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
…ock floor Aligns flow control with the pull model instead of a fixed row constant: the consumer reports prefetch_batches * batch_size (from the actual iter_batches call) as its buffer target, and the pusher independently keeps MIN_PREFETCH_BLOCKS(=1) whole blocks in flight — the analog of the pull model's 1-deep pipelined get — so flow can't degenerate to stop-and-wait when a block exceeds the row window. Drops DEFAULT_GENERIC_TARGET_BUFFER_ROWS; explicit target_buffer_rows remains an override. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
The credit protocol only stops pushers from popping the executor's output queues; it does not stop read/map tasks from filling them. With the feed disabled, DownstreamCapacityBackpressurePolicy never engaged for the terminal op and the full_training release benchmark spilled 50GB (producer raced the whole epoch ahead of GPU-bound consumers). Restore the registration + poll-driven updates, mirroring SplitCoordinator's prefetched-bytes reporting. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
Instead of draining and discarding a dead consumer's split, the pusher now parks: the split's remaining data stays queued in the executor (paced by normal backpressure), and the split is marked awaiting-rejoin. A replacement worker that registers for the split (bumping the registration version) wakes the pusher — which rebinds to the new handle and restarts the split's seq/accounting — and joins the ACTIVE epoch via a start_epoch fast-path instead of blocking at the next-epoch barrier. Rows already delivered to the dead consumer were freed at delivery and are lost for that epoch (re-reading them is the data-checkpointing integration's job). Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
… a TODO Keep the data-preserving park (no drain, remaining data stays queued so replacement stays possible) but drop the live re-registration machinery (registration versions, pusher rebind/reset, barrier fast-path) to keep the prototype simple. The validated design is captured in the _pusher_loop TODO; recovery today is Train's group restart via the next-epoch barrier teardown. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
A poll can fail transiently (GetTimeoutError under load, ActorUnavailableError during a restart); treating the first failure as death parked a healthy split for the rest of the epoch. Now only a definitive ActorDiedError parks immediately; other failures retry with exponential backoff (1s, 2s) and park after 3 consecutive failures. Any successful poll resets the counter. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
The consumer now tells the coordinator what it needs instead of being polled: at iteration start it requests its prefetch window (prefetch_batches * batch_size rows), and after each block it pops from its local queue it requests the popped amount again. The coordinator accumulates per-split demand (request_rows, which doubles as the consumption report for producer pacing) and its pusher sends whole blocks while demand is positive — waking instantly on a request via a condition — then waits otherwise. This deletes the entire poll layer: _PollResponse, _receiver_poll, POLL_INTERVAL_S idle polling, the poll-failure backoff/death detection, and the explicit MIN_PREFETCH_BLOCKS floor (replenish-on-pop plus whole-block sends reproduce the pull model's window + 1-deep pipelining naturally). A dead consumer simply stops requesting, so its pusher parks implicitly with the split's data kept queued. The executor's external-consumer-bytes report is refreshed by the pusher after each push, not per request — a per-request set_external_consumer_bytes contended on the resource-manager lock and cost ~10% throughput. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
…mixin - request_blocks replaces the row-based request_rows: the consumer asks for target_buffer_blocks (default 2) at iteration start and one more block after each pop; the prefetch_batches * batch_size window derivation and all row accounting are gone. Demand is counted in the coordinator's own dispatch unit. - PushSplitReceiverMixin replaces the __ray_call__ transport: the hosting actor class exposes _push_split_deliver/_push_split_deliver_error as real methods (no per-call function pickling); RayTrainWorker mixes it in, and register() validates the handle exposes the methods. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
request_block asks for exactly one block — the analog of the pull model pulling one RefBundle per get: one at iteration start, one more after each popped block, so the next block is in flight while the previous one is consumed. The target_buffer_blocks knob is removed everywhere. Removing the demand slack exposed two latent flow-control races, both fixed: - Phantom demand at epoch transitions: a stale request could land between _reset_state and the epoch bump and survive into the new epoch, making the pusher push seq 0 before the consumer's begin_epoch (receiver drops it, wedging the reorder buffer). The bump now precedes the reset and the request's epoch check is atomic with its apply (inside the demand cond). - Zombie generators: an early-exited epoch's generator stays parked in queue.get on the SHARED receiver queue and steals the next epoch's deliveries (its replenish is then stale-dropped, starving the split). reset() now swaps in a fresh queue object per epoch, and the generator loop checks _active_epoch so zombies exit within one timeout. Verified with a 90-cycle early-exit stress loop (previously hung within a few cycles). Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: xgui <[email protected]>
PushSplitReceiverMixin's methods manipulated the receiver's fields from outside; the reorder/delivery logic now lives on _PushReceiver (deliver/deliver_error) and the mixin is a stateless lookup-and-delegate surface. They stay separate classes on purpose: one actor hosts one receiver per dataset shard, the iterator reaches the state via the process-local registry (it has no reference to the actor instance), and a stateless mixin needs no cooperative __init__ chaining on RayTrainWorker — documented in the mixin docstring. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
The module docstring is now a short bullet overview plus a compact diagram, and inline comments keep only the load-bearing invariants; investigation narrative moved out (it lives in the git history). Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
…pull model One outstanding block per split serialized transfers and made the external-consumer-bytes report ~1 block, so DownstreamCapacityBackpressure throttled the producer (push 19% slower than pull in skip_training). Mirror the pull model's local prefetch window instead: keep enough one-block requests outstanding to cover prefetch_batches * batch_size rows (+1 pipelined), sized adaptively from the rows-per-block seen so far. The receiver queue stores the prefetched blocks, several transfers stay in flight, and pushed-minus-consumed now reports window bytes for pacing. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
Ray Train workers are default single-threaded actors (the training loop runs on a ThreadRunner thread), so delivery tasks execute in submission order and the reorder buffer never fired. Drop seq numbers and the buffer; document that consumers must execute tasks in submission order, with a TODO to restore reordering (see this commit's parent) if max_concurrency>1 hosts ever need support. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
The 16-GPU skip_training A/B still showed push 13% slower: all of it consumer starvation (time_spent_blocked +15.2s) caused by DownstreamCapacity throttling Map 286x. Push reported ~1.5 blocks/split as external consumer bytes while pull reports ~3 (window + resolve stage + handed-over block), so the producer's output cap was ~3x tighter. Match pull: window target is now ceil(window_rows / avg_rows) + 2, and the consumption report lags one block so the block currently being batched still counts as consumer-held. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
Replace block-count demand with rows: request_rows(consumed_bytes, num_rows) keeps a prefetch_batches * batch_size row window covered, and the pusher sends whole blocks while row demand is positive. Variable block sizes are handled by the protocol itself, removing the rows-per-block estimation and its +2/bootstrap-3 constants. Observability: pushers track wait_demand (consumer-bound) vs wait_output (producer-bound) and log a rate-limited progress line; consumers log pops/queue depth and record queue-wait in the get_ref_bundles iter stat; new coordinator debug_state() snapshots per-split flow control. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
…ing-split (picks up autoscaler request_remaining fix ray-project#66370)
The release test confirmed parity (push 121.35s vs pull 121.01s epoch), so the rate-limited [push-split] progress logs have served their purpose. Keep the wait counters, the queue-wait iterator stat, and debug_state() for diagnosis; remove the log spam. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
Re-add sequence numbers and the receiver reorder buffer so delivery order no longer depends on the hosting actor being single-threaded (future max_concurrency > 1 train workers keep working). Drop the PROTOTYPE markers and tighten the module docstring per review. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
justinvyu
left a comment
There was a problem hiding this comment.
Looks good overall so far, had some initial thoughts but will continue doing a more thorough review. Any parts that you want reviewed in particular?
| total = sum( | ||
| max(0, self._bytes_pushed[i] - self._bytes_consumed_reported[i]) | ||
| for i in range(self._n) | ||
| ) | ||
| try: | ||
| executor.set_external_consumer_bytes(total) |
There was a problem hiding this comment.
Here's my understanding of how the accounting is being done now:
sum(bytes_pushed - bytes_consumed for worker in workers)- In the steady state, this is roughly equal to
prefetch_batches * batch_bytes, which has parity with the old pull system. The pull system instead tracked the prefetch window bytes on the consumer and reported it back to bytes_consumedgets incremented as soon as the block iterator hands it off to the next consumer pipeline stage (the "block -> batch" stage). We still don't account for remaining references to the object in the remainder of the pipeline (format -> collate), but this has parity with the original implementation.
- In the steady state, this is roughly equal to
It'd be good to double check this though in a unit test; is accounting the same before/after?
There was a problem hiding this comment.
Yes, they align: in the push model, rows_pushed − rows_consumed is the in-flight data not yet returned from _to_ref_bundle_iterator (on the wire or in the receiver queue), which is the same quantity the pull model tracks as blocks prefetched to local but not yet consumed.
…th pull The consumer no longer computes a request deficit — it declares its row window and reports consumption, and the coordinator derives what to send: to_send = target_rows - (rows_pushed - rows_consumed). Rows are reported at pop (they drive the window, like the pull window's slide-out); bytes lag one block (the being-batched block stays consumer-held for pacing, playing the role of the pull client's just-received block). Also document how pushed-minus-consumed corresponds to the pull coordinator's prefetched-bytes total. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
Covers _PushReceiver (reordering, sequenced EOF, stale/early drops, fail-fast errors, epoch reset) and end-to-end behavior with a Train-shaped consumer actor: equal splits across epochs, early exit recovery, error propagation, flow-control buffering bound, and the actor-host requirement. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
|
|
||
| def _to_ref_bundle_iterator( | ||
| self, | ||
| ) -> Tuple[Iterator[ResolvedBlock], Optional[DatasetStats], None]: |
There was a problem hiding this comment.
@justinvyu Could you check here if it is safe to return one Iterator[ResolvedBlock] from the _to_ref_bundle_iterator
| total = sum( | ||
| max(0, self._bytes_pushed[i] - self._bytes_consumed_reported[i]) | ||
| for i in range(self._n) | ||
| ) | ||
| try: | ||
| executor.set_external_consumer_bytes(total) |
There was a problem hiding this comment.
Yes, they align: in the push model, rows_pushed − rows_consumed is the in-flight data not yet returned from _to_ref_bundle_iterator (on the wire or in the receiver queue), which is the same quantity the pull model tracks as blocks prefetched to local but not yet consumed.
…comparisons Replace the manual-frequency *.push_based variations with *.pull_vs_push: a wrapper runs train_benchmark.py with the pull-based split, then with the push-based one, records both metrics plus the throughput ratio, and fails if push global throughput drops below 90% of pull's. The comparisons inherit the parent's nightly frequency, same as the pull variants. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv Signed-off-by: xgui <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a push-based streaming split iterator (PushBasedDataIterator and PushSplitCoordinator) for Ray Data, allowing a coordinator actor to push blocks directly to consumer actors (such as Ray Train workers) rather than having consumers pull them. The changes also include integration with Ray Train via PushBasedDataConfig, comprehensive unit and end-to-end tests, and benchmarks comparing pull vs. push performance. The review feedback highlights several critical issues: a race condition during epoch transitions where early block deliveries or errors can be silently dropped, a performance bottleneck in the barrier implementation due to busy-waiting, and a race condition when updating external consumer bytes without synchronization. Suggestions are provided to resolve these concurrency and performance issues, along with corresponding updates to the unit tests.
| with self.lock: | ||
| if epoch_id != self.cur_epoch: | ||
| return | ||
| if self.reorder_epoch != epoch_id: | ||
| self.reorder_epoch = epoch_id | ||
| self.reorder_next_seq = 0 | ||
| self.reorder_pending = {} | ||
| self.reorder_pending[seq] = queue_item |
There was a problem hiding this comment.
There is a critical race condition here. When a new epoch starts, the coordinator's pusher threads are spawned and can immediately push blocks to the consumer actor before the consumer's main thread has finished the start_epoch RPC and called receiver.begin_epoch(epoch). During this window, receiver.cur_epoch is still None (due to the preceding reset()), causing these early blocks to be silently dropped.
Additionally, if a sequence number is delivered multiple times (e.g., due to Ray task retries), it can cause duplicate data processing or memory leaks if the duplicate arrives after the sequence number has already been released.
We can fix both issues by:
- Accepting deliveries when
self.cur_epochisNoneand settingself.cur_epoch = epoch_id. - Ignoring duplicate deliveries where
seq < self.reorder_next_seqorseq in self.reorder_pending.
| with self.lock: | |
| if epoch_id != self.cur_epoch: | |
| return | |
| if self.reorder_epoch != epoch_id: | |
| self.reorder_epoch = epoch_id | |
| self.reorder_next_seq = 0 | |
| self.reorder_pending = {} | |
| self.reorder_pending[seq] = queue_item | |
| with self.lock: | |
| if self.cur_epoch is None: | |
| self.cur_epoch = epoch_id | |
| elif epoch_id != self.cur_epoch: | |
| return | |
| if self.reorder_epoch != epoch_id: | |
| self.reorder_epoch = epoch_id | |
| self.reorder_next_seq = 0 | |
| self.reorder_pending = {} | |
| if seq < self.reorder_next_seq or seq in self.reorder_pending: | |
| return | |
| self.reorder_pending[seq] = queue_item |
| with self.lock: | ||
| if epoch_id == self.cur_epoch: | ||
| self.queue.put(error) |
There was a problem hiding this comment.
To align with the early delivery fix in deliver, we should also allow deliver_error to accept errors when self.cur_epoch is None by setting self.cur_epoch = epoch_id first.
| with self.lock: | |
| if epoch_id == self.cur_epoch: | |
| self.queue.put(error) | |
| with self.lock: | |
| if self.cur_epoch is None: | |
| self.cur_epoch = epoch_id | |
| if epoch_id == self.cur_epoch: | |
| self.queue.put(error) |
| if is_last_arrival: | ||
| # The last arrival tears down the previous epoch before the | ||
| # barrier releases; done outside self._lock so exiting pushers | ||
| # can still take it. | ||
| self._teardown_epoch() | ||
| with self._lock: | ||
| self._teardown_complete_for = starting_epoch | ||
|
|
||
| start_time = time.time() | ||
| while self._cur_epoch == starting_epoch and ( | ||
| self._num_unarrived_splits_at_barrier != 0 | ||
| or self._teardown_complete_for != starting_epoch | ||
| ): | ||
| if time.time() - start_time > BLOCKED_CLIENT_WARN_TIMEOUT: | ||
| if log_once(f"push_split_blocked_{split_idx}_{starting_epoch}"): | ||
| logger.warning( | ||
| f"PushBasedDataIterator(epoch={starting_epoch}, " | ||
| f"split={split_idx}) blocked waiting on other clients " | ||
| f"for more than {BLOCKED_CLIENT_WARN_TIMEOUT}s. All " | ||
| "clients must iterate their splits at the same time." | ||
| ) | ||
| time.sleep(0.1) |
There was a problem hiding this comment.
The barrier implementation currently uses a busy-waiting loop with time.sleep(0.1), which introduces up to 100ms of latency per epoch transition. Since this is a high-performance push-based streaming split designed for speed, we can eliminate this latency by using a threading.Condition variable to block and notify the waiting threads immediately when the last split arrives and teardown is complete. Note that you will need to initialize self._barrier_cond = threading.Condition(self._lock) in __init__.
if is_last_arrival:
# The last arrival tears down the previous epoch before the
# barrier releases; done outside self._lock so exiting pushers
# can still take it.
self._teardown_epoch()
with self._lock:
self._teardown_complete_for = starting_epoch
self._barrier_cond.notify_all()
start_time = time.time()
with self._lock:
while self._cur_epoch == starting_epoch and (
self._num_unarrived_splits_at_barrier != 0
or self._teardown_complete_for != starting_epoch
):
remaining_timeout = BLOCKED_CLIENT_WARN_TIMEOUT - (time.time() - start_time)
if remaining_timeout <= 0:
if log_once(f"push_split_blocked_{split_idx}_{starting_epoch}"):
logger.warning(
f"PushBasedDataIterator(epoch={starting_epoch}, "
f"split={split_idx}) blocked waiting on other clients "
f"for more than {BLOCKED_CLIENT_WARN_TIMEOUT}s. All "
"clients must iterate their splits at the same time."
)
self._barrier_cond.wait(timeout=1.0)
else:
self._barrier_cond.wait(timeout=min(1.0, remaining_timeout))| total = sum( | ||
| max(0, self._bytes_pushed[i] - self._bytes_consumed_reported[i]) | ||
| for i in range(self._n) | ||
| ) | ||
| try: | ||
| executor.set_external_consumer_bytes(total) | ||
| except Exception: | ||
| # The executor may be mid-shutdown during an epoch transition. | ||
| pass |
There was a problem hiding this comment.
The calculation of total reads self._bytes_pushed and self._bytes_consumed_reported without synchronization. Since this method is called concurrently by multiple pusher threads and the actor thread, there is a race condition where concurrent unsynchronized updates can lead to stale or out-of-order backpressure updates being sent to the executor. We should wrap the calculation and the call to set_external_consumer_bytes in with self._lock: to ensure atomicity.
| total = sum( | |
| max(0, self._bytes_pushed[i] - self._bytes_consumed_reported[i]) | |
| for i in range(self._n) | |
| ) | |
| try: | |
| executor.set_external_consumer_bytes(total) | |
| except Exception: | |
| # The executor may be mid-shutdown during an epoch transition. | |
| pass | |
| with self._lock: | |
| total = sum( | |
| max(0, self._bytes_pushed[i] - self._bytes_consumed_reported[i]) | |
| for i in range(self._n) | |
| ) | |
| try: | |
| executor.set_external_consumer_bytes(total) | |
| except Exception: | |
| # The executor may be mid-shutdown during an epoch transition. | |
| pass |
| def test_receiver_drops_stale_or_early_deliveries(): | ||
| receiver = _PushReceiver() | ||
| # Before begin_epoch, every delivery is dropped. | ||
| receiver.deliver(0, 0, _BlockPush(size_bytes=1, num_rows=1), "early") | ||
| assert receiver.queue.qsize() == 0 | ||
|
|
||
| receiver.begin_epoch(1) | ||
| # Stale epoch dropped, current epoch delivered. | ||
| receiver.deliver(0, 0, _BlockPush(size_bytes=1, num_rows=1), "stale") | ||
| receiver.deliver(1, 0, _BlockPush(size_bytes=1, num_rows=1), "current") | ||
| items = _drain(receiver.queue) | ||
| assert [item.block for item in items] == ["current"] |
There was a problem hiding this comment.
Since we updated _PushReceiver.deliver to accept early deliveries when self.cur_epoch is None (to prevent a critical race condition during epoch transitions), we should update this unit test to verify that early deliveries are correctly accepted and set the epoch, rather than asserting they are dropped.
| def test_receiver_drops_stale_or_early_deliveries(): | |
| receiver = _PushReceiver() | |
| # Before begin_epoch, every delivery is dropped. | |
| receiver.deliver(0, 0, _BlockPush(size_bytes=1, num_rows=1), "early") | |
| assert receiver.queue.qsize() == 0 | |
| receiver.begin_epoch(1) | |
| # Stale epoch dropped, current epoch delivered. | |
| receiver.deliver(0, 0, _BlockPush(size_bytes=1, num_rows=1), "stale") | |
| receiver.deliver(1, 0, _BlockPush(size_bytes=1, num_rows=1), "current") | |
| items = _drain(receiver.queue) | |
| assert [item.block for item in items] == ["current"] | |
| def test_receiver_accepts_early_deliveries_before_begin_epoch(): | |
| receiver = _PushReceiver() | |
| # Before begin_epoch, an early delivery is accepted and sets the epoch. | |
| receiver.deliver(1, 0, _BlockPush(size_bytes=1, num_rows=1), "early") | |
| assert receiver.queue.qsize() == 1 | |
| assert receiver.queue.get_nowait().block == "early" | |
| # Stale epoch dropped, current epoch delivered. | |
| receiver.deliver(0, 0, _BlockPush(size_bytes=1, num_rows=1), "stale") | |
| receiver.deliver(1, 1, _BlockPush(size_bytes=1, num_rows=1), "current") | |
| items = _drain(receiver.queue) | |
| assert [item.block for item in items] == ["current"] |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
Reviewed by Cursor Bugbot for commit 8943fd6. Configure here.
| with self._iter_stats.iter_get_ref_bundles_s.timer(): | ||
| item = epoch_queue.get(timeout=1.0) | ||
| except queue.Empty: | ||
| continue |
There was a problem hiding this comment.
Actor-thread iteration deadlocks deliveries
High Severity
Iterating a PushBasedDataIterator from an actor method on the default single-threaded actor hangs forever. Deliveries arrive as _push_split_deliver actor tasks, but that same actor thread is blocked waiting for the next batch, so the receiver queue never fills.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit 8943fd6. Configure here.
| seq += 1 | ||
| with cond: | ||
| self._rows_pushed[split_idx] += num_rows | ||
| self._bytes_pushed[split_idx] += size_bytes |
There was a problem hiding this comment.
Unknown row counts disable flow control
Medium Severity
The pusher treats metadata.num_rows of None as 0 when updating _rows_pushed. Demand is computed from row counts, so unknown-size blocks never consume the prefetch window and the coordinator keeps pushing.
Reviewed by Cursor Bugbot for commit 8943fd6. Configure here.
Refactor the splitcoordinator to push based. Passing the ref as a task arg forces Ray to dereference and materialize a secondary copy on the worker node. So by the time the worker touches the data, it's already materialized in the worker’s local object store and is not affected by a remote death. ## Why are these changes needed? First PR of the push-based `streaming_split` for Ray Train ingestion. It adds the coordinator actor only; the pushers and the consumer-side iterator follow in #66466. - **Epoch lifecycle:** runs one streaming executor per epoch behind a barrier that all `n` splits must reach. Waiters sleep on a `Condition` rather than polling. - **Row window:** `_SplitFlow` tracks each split's `target_rows`, `rows_pushed`, and `rows_consumed`. A sender may send while `target_rows - (rows_pushed - rows_consumed) > 0`. Flow state is recreated every epoch, so a stale report can't affect the new one. - **Pacing:** bytes sent but not yet consumed feed the executor's external-consumer backpressure. - **Scope:** internal only. There's no public API change and the pull path is untouched. `Dataset.streaming_split` will switch over in a later PR. Split out of #65842 (supersedes it), so this doesn't duplicate other work. Written with AI assistance (Claude Code) and reviewed by a human. Tests: `pytest python/ray/data/tests/test_push_split_coordinator.py` (10 passed). ## TODO: After mid-epoch resumption PRs are merged, this coordinator needs minor changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv --------- Signed-off-by: xgui <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>


Why are these changes needed?
Adds a push-based alternative to
streaming_splitfor Ray Train ingestion. Train workers no longer callcoordinator.get()for each block. Instead, the coordinator pushes blocks to each worker's local queue.prefetch_batches * batch_sizerow window and reports consumption. The coordinator pushes whole blocks whiletarget_rows - (rows_pushed - rows_consumed) > 0. Pushed-minus-consumed bytes feed the executor's external-consumer backpressure.PushBasedDataConfig/Dataset.streaming_split_push_based. The pull path is unchanged and stays the default.skip_trainingrelease benchmark (epoch 121.35s vs 121.01s; global throughput 8100 vs 8120 rows/s). New nightly*.pull_vs_pushrelease tests fail if push drops below 90% of pull's global throughput.Next PRs
enable_shard_localityholds end to end.DataManageronly tracksStreamSplitDataIteratorcoordinators for shutdown, so it also needs to track the push coordinator.DataConfigand make push the default once checkpointing lands.🤖 Generated with Claude Code
https://claude.ai/code/session_01QfaKctvP9gCsC2EBTpdqnv