Repository navigation
Conversation
Signed-off-by: Sirui Huang <[email protected]>
|
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. |
matthewdeng
pushed a commit
that referenced
this pull request
Sep 22, 2026
… from input to output (#66369) ## Description A Ray Train job dies before it reads a single row. Its input pipeline shuffles a dataset that was already materialized: ```python ds = ray.data.range(100, override_num_blocks=10).materialize() ds = ds.randomize_block_order() (it,) = ds.streaming_split(1, equal=True) list(it.iter_rows()) ``` ``` (SplitCoordinator pid=42263) Split 0 epoch 0 get() failed after 0 rows: Cannot register an out-of-scope/freed callback for object 6f1bcddfc6570c62…: it is not owned by this worker (it may be owned by another worker, or have no ownership record). These callbacks can only be registered by the owner. ``` ### Why it happens `BlockRefCounter` tracks object-store memory. To do that, it asks Ray Core to call it back when a block is freed. Only the block's owner may register that callback, and the owner is the process that created the block. `streaming_split` runs the plan inside a `SplitCoordinator` actor. But the blocks were created earlier, by `materialize()` on the caller. The same holds for any `InputData` source, such as `from_arrow` or `from_pandas`. ``` caller SplitCoordinator actor ────────────── ────────────────────── materialize() ── refs ──▶ randomize_block_order → … → split(N) owns B1..B10 owns nothing it was handed ``` `AllToAllOperator.all_inputs_done` registered a callback for every block it sent downstream. That is right for sort, shuffle and repartition. Their output blocks come from reduce tasks the operator itself submitted, so it owns them. It is wrong for `RandomizeBlocks`. That operator creates no blocks. It reorders its input bundles and returns the same refs. So the actor asks Ray Core to watch blocks the caller owns, Ray Core refuses, and the execution fails. ### The fix Register a block only when its ref was not among the operator's inputs: ```python input_refs = {entry.ref for b in input_bundles for entry in b.blocks} ... for bundle in output_buffer: for entry in bundle.blocks: if entry.ref in input_refs: continue self._block_ref_counter.on_block_produced(...) ``` Returned refs are skipped. New ones are still registered. `OutputSplitter` already uses the same test on `_split_block` output. **Why not `RefBundle.owns_blocks`?** That flag says whether the blocks may be destroyed, not who made them. The shuffle, sort and split-repartition schedulers copy it from their input onto blocks their own reduce tasks made (`input_owned = all(b.owns_blocks for b in refs)` at `pull_based_shuffle_task_scheduler.py:50`, used at `:145`). A filter on that flag would drop real blocks from the counter whenever the source is `from_*` or `materialize`, and under-report their memory. Bugbot caught this in the first version of this PR. ### Where it came from #64157 added `BlockRefCounter` to the operators in 2.57, and the crash has been there since. It was reported from a Ray Train job on 2.58.0. That job's input pipeline is `from_arrow → repartition → materialize → randomize_block_order → map_batches → repartition → streaming_split`, and all four splits fail at 0 rows. ## Related issues None open. I searched ray-project/ray for open PRs and issues mentioning `BlockRefCounter`, `owns_blocks`, `streaming_split materialized`, and the error text "Cannot register an out-of-scope callback". Two open PRs touch the counter: #65878 (consumer-held bytes) and #65220 (deferring gRPC frees). Neither changes this registration path, and no open issue tracks the crash, so this is not duplicate work. ## Additional information **Tests.** `test_streaming_split_over_materialized_all_to_all` reproduces the failure end to end. The two tests in `test_operators.py` cover both sides of the check; the second fails if the check uses `owns_blocks`, which is what the first version of this PR did. ``` $ PYTHONPATH=python/ray/data/tests python -m pytest \ python/ray/data/tests/test_streaming_integration.py \ -k test_streaming_split_over_materialized_all_to_all -q 1 passed, 25 deselected in 9.28s # fails on master with the error above $ PYTHONPATH=python/ray/data/tests python -m pytest \ python/ray/data/tests/test_operators.py \ python/ray/data/tests/test_randomize_block_order.py \ python/ray/data/tests/unit/test_block_ref_counter.py \ python/ray/data/tests/unit/test_resource_manager.py -q 29 passed in 16.10s $ PYTHONPATH=python/ray/data/tests python -m pytest \ python/ray/data/tests/test_streaming_integration.py -k streaming_split -q 13 passed, 13 deselected in 68.67s ``` The last command needs #66366 applied locally. On master, `request_remaining=True` in `rate_based_cluster_autoscaler.py` raises `TypeError: 'bool' object is not iterable` in the autoscaling coordinator, which makes these tests flaky. **CI.** The `buildkite/premerge` failure here is that same master bug. All three pyrefly errors are in `rate_based_cluster_autoscaler.py`, a file this PR does not touch. #66366 and #66370 both fix it, and this PR is unblocked once either one lands. **AI assistance was used** for the diagnosis, the patch, and this description. --------- Signed-off-by: Marwan Sarieddine <[email protected]> Co-authored-by: Ayush Kumar <[email protected]>
owenowenisme
pushed a commit
to owenowenisme/ray
that referenced
this pull request
Sep 23, 2026
… from input to output (ray-project#66369) ## Description A Ray Train job dies before it reads a single row. Its input pipeline shuffles a dataset that was already materialized: ```python ds = ray.data.range(100, override_num_blocks=10).materialize() ds = ds.randomize_block_order() (it,) = ds.streaming_split(1, equal=True) list(it.iter_rows()) ``` ``` (SplitCoordinator pid=42263) Split 0 epoch 0 get() failed after 0 rows: Cannot register an out-of-scope/freed callback for object 6f1bcddfc6570c62…: it is not owned by this worker (it may be owned by another worker, or have no ownership record). These callbacks can only be registered by the owner. ``` ### Why it happens `BlockRefCounter` tracks object-store memory. To do that, it asks Ray Core to call it back when a block is freed. Only the block's owner may register that callback, and the owner is the process that created the block. `streaming_split` runs the plan inside a `SplitCoordinator` actor. But the blocks were created earlier, by `materialize()` on the caller. The same holds for any `InputData` source, such as `from_arrow` or `from_pandas`. ``` caller SplitCoordinator actor ────────────── ────────────────────── materialize() ── refs ──▶ randomize_block_order → … → split(N) owns B1..B10 owns nothing it was handed ``` `AllToAllOperator.all_inputs_done` registered a callback for every block it sent downstream. That is right for sort, shuffle and repartition. Their output blocks come from reduce tasks the operator itself submitted, so it owns them. It is wrong for `RandomizeBlocks`. That operator creates no blocks. It reorders its input bundles and returns the same refs. So the actor asks Ray Core to watch blocks the caller owns, Ray Core refuses, and the execution fails. ### The fix Register a block only when its ref was not among the operator's inputs: ```python input_refs = {entry.ref for b in input_bundles for entry in b.blocks} ... for bundle in output_buffer: for entry in bundle.blocks: if entry.ref in input_refs: continue self._block_ref_counter.on_block_produced(...) ``` Returned refs are skipped. New ones are still registered. `OutputSplitter` already uses the same test on `_split_block` output. **Why not `RefBundle.owns_blocks`?** That flag says whether the blocks may be destroyed, not who made them. The shuffle, sort and split-repartition schedulers copy it from their input onto blocks their own reduce tasks made (`input_owned = all(b.owns_blocks for b in refs)` at `pull_based_shuffle_task_scheduler.py:50`, used at `:145`). A filter on that flag would drop real blocks from the counter whenever the source is `from_*` or `materialize`, and under-report their memory. Bugbot caught this in the first version of this PR. ### Where it came from ray-project#64157 added `BlockRefCounter` to the operators in 2.57, and the crash has been there since. It was reported from a Ray Train job on 2.58.0. That job's input pipeline is `from_arrow → repartition → materialize → randomize_block_order → map_batches → repartition → streaming_split`, and all four splits fail at 0 rows. ## Related issues None open. I searched ray-project/ray for open PRs and issues mentioning `BlockRefCounter`, `owns_blocks`, `streaming_split materialized`, and the error text "Cannot register an out-of-scope callback". Two open PRs touch the counter: ray-project#65878 (consumer-held bytes) and ray-project#65220 (deferring gRPC frees). Neither changes this registration path, and no open issue tracks the crash, so this is not duplicate work. ## Additional information **Tests.** `test_streaming_split_over_materialized_all_to_all` reproduces the failure end to end. The two tests in `test_operators.py` cover both sides of the check; the second fails if the check uses `owns_blocks`, which is what the first version of this PR did. ``` $ PYTHONPATH=python/ray/data/tests python -m pytest \ python/ray/data/tests/test_streaming_integration.py \ -k test_streaming_split_over_materialized_all_to_all -q 1 passed, 25 deselected in 9.28s # fails on master with the error above $ PYTHONPATH=python/ray/data/tests python -m pytest \ python/ray/data/tests/test_operators.py \ python/ray/data/tests/test_randomize_block_order.py \ python/ray/data/tests/unit/test_block_ref_counter.py \ python/ray/data/tests/unit/test_resource_manager.py -q 29 passed in 16.10s $ PYTHONPATH=python/ray/data/tests python -m pytest \ python/ray/data/tests/test_streaming_integration.py -k streaming_split -q 13 passed, 13 deselected in 68.67s ``` The last command needs ray-project#66366 applied locally. On master, `request_remaining=True` in `rate_based_cluster_autoscaler.py` raises `TypeError: 'bool' object is not iterable` in the autoscaling coordinator, which makes these tests flaky. **CI.** The `buildkite/premerge` failure here is that same master bug. All three pyrefly errors are in `rate_based_cluster_autoscaler.py`, a file this PR does not touch. ray-project#66366 and ray-project#66370 both fix it, and this PR is unblocked once either one lands. **AI assistance was used** for the diagnosis, the patch, and this description. --------- Signed-off-by: Marwan Sarieddine <[email protected]> Co-authored-by: Ayush Kumar <[email protected]>
nadongjun
pushed a commit
to nadongjun/ray
that referenced
this pull request
Oct 6, 2026
… from input to output (ray-project#66369) ## Description A Ray Train job dies before it reads a single row. Its input pipeline shuffles a dataset that was already materialized: ```python ds = ray.data.range(100, override_num_blocks=10).materialize() ds = ds.randomize_block_order() (it,) = ds.streaming_split(1, equal=True) list(it.iter_rows()) ``` ``` (SplitCoordinator pid=42263) Split 0 epoch 0 get() failed after 0 rows: Cannot register an out-of-scope/freed callback for object 6f1bcddfc6570c62…: it is not owned by this worker (it may be owned by another worker, or have no ownership record). These callbacks can only be registered by the owner. ``` ### Why it happens `BlockRefCounter` tracks object-store memory. To do that, it asks Ray Core to call it back when a block is freed. Only the block's owner may register that callback, and the owner is the process that created the block. `streaming_split` runs the plan inside a `SplitCoordinator` actor. But the blocks were created earlier, by `materialize()` on the caller. The same holds for any `InputData` source, such as `from_arrow` or `from_pandas`. ``` caller SplitCoordinator actor ────────────── ────────────────────── materialize() ── refs ──▶ randomize_block_order → … → split(N) owns B1..B10 owns nothing it was handed ``` `AllToAllOperator.all_inputs_done` registered a callback for every block it sent downstream. That is right for sort, shuffle and repartition. Their output blocks come from reduce tasks the operator itself submitted, so it owns them. It is wrong for `RandomizeBlocks`. That operator creates no blocks. It reorders its input bundles and returns the same refs. So the actor asks Ray Core to watch blocks the caller owns, Ray Core refuses, and the execution fails. ### The fix Register a block only when its ref was not among the operator's inputs: ```python input_refs = {entry.ref for b in input_bundles for entry in b.blocks} ... for bundle in output_buffer: for entry in bundle.blocks: if entry.ref in input_refs: continue self._block_ref_counter.on_block_produced(...) ``` Returned refs are skipped. New ones are still registered. `OutputSplitter` already uses the same test on `_split_block` output. **Why not `RefBundle.owns_blocks`?** That flag says whether the blocks may be destroyed, not who made them. The shuffle, sort and split-repartition schedulers copy it from their input onto blocks their own reduce tasks made (`input_owned = all(b.owns_blocks for b in refs)` at `pull_based_shuffle_task_scheduler.py:50`, used at `:145`). A filter on that flag would drop real blocks from the counter whenever the source is `from_*` or `materialize`, and under-report their memory. Bugbot caught this in the first version of this PR. ### Where it came from ray-project#64157 added `BlockRefCounter` to the operators in 2.57, and the crash has been there since. It was reported from a Ray Train job on 2.58.0. That job's input pipeline is `from_arrow → repartition → materialize → randomize_block_order → map_batches → repartition → streaming_split`, and all four splits fail at 0 rows. ## Related issues None open. I searched ray-project/ray for open PRs and issues mentioning `BlockRefCounter`, `owns_blocks`, `streaming_split materialized`, and the error text "Cannot register an out-of-scope callback". Two open PRs touch the counter: ray-project#65878 (consumer-held bytes) and ray-project#65220 (deferring gRPC frees). Neither changes this registration path, and no open issue tracks the crash, so this is not duplicate work. ## Additional information **Tests.** `test_streaming_split_over_materialized_all_to_all` reproduces the failure end to end. The two tests in `test_operators.py` cover both sides of the check; the second fails if the check uses `owns_blocks`, which is what the first version of this PR did. ``` $ PYTHONPATH=python/ray/data/tests python -m pytest \ python/ray/data/tests/test_streaming_integration.py \ -k test_streaming_split_over_materialized_all_to_all -q 1 passed, 25 deselected in 9.28s # fails on master with the error above $ PYTHONPATH=python/ray/data/tests python -m pytest \ python/ray/data/tests/test_operators.py \ python/ray/data/tests/test_randomize_block_order.py \ python/ray/data/tests/unit/test_block_ref_counter.py \ python/ray/data/tests/unit/test_resource_manager.py -q 29 passed in 16.10s $ PYTHONPATH=python/ray/data/tests python -m pytest \ python/ray/data/tests/test_streaming_integration.py -k streaming_split -q 13 passed, 13 deselected in 68.67s ``` The last command needs ray-project#66366 applied locally. On master, `request_remaining=True` in `rate_based_cluster_autoscaler.py` raises `TypeError: 'bool' object is not iterable` in the autoscaling coordinator, which makes these tests flaky. **CI.** The `buildkite/premerge` failure here is that same master bug. All three pyrefly errors are in `rate_based_cluster_autoscaler.py`, a file this PR does not touch. ray-project#66366 and ray-project#66370 both fix it, and this PR is unblocked once either one lands. **AI assistance was used** for the diagnosis, the patch, and this description. --------- Signed-off-by: Marwan Sarieddine <[email protected]> Co-authored-by: Ayush Kumar <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Blocks handed to an iterator are deserialized as zero-copy views over plasma. The
ObjectRefis dropped as soon as the view exists, soBlockRefCounterstops counting bytes that are still resident and the driver sees headroom that isn't there.This PR helps track what the consumer holds (blocks in the batcher, plus batches built but not yet released) and report it to
ResourceManager, which charges it to the output operator so it feeds backpressure.streaming_splitconsumers have no local executor, so the value rides theget()RPC that already carriesprefetched_bytes, and the coordinator sums across splits.After this change, backpressure may get more conservative by the previously-uncounted amount.
Additional information
Three new tests:
test_consumer_held_memory_tracks_in_flight_batches: bytes stay counted from batch build to release, and never go negative when a batch is dropped without being yielded.test_consumer_held_bytes_charged_to_output_op: the reported total lands on the output operator's usage.test_stream_split_iterator_always_reports_consumer_held_bytes: a split consumer always builds a reporting callback. This is the regression test for the inertstreaming_splitpath.