Repository navigation
[Data] Remove unused _split_at_index - #45481
Merged
Merged
Conversation
Signed-off-by: Balaji Veeramani <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
bveeramani
requested review from
amogkam,
c21,
ericl,
omatthew98,
raulchen,
scottjlee,
scv119 and
stephanie-wang
as code owners
May 21, 2024 19:14
c21
approved these changes
May 21, 2024
bveeramani
enabled auto-merge (squash)
May 21, 2024 19:16
richardliaw
pushed a commit
that referenced
this pull request
Nov 18, 2026
…_blocks_rows (#67662) ## Summary Fixes a lost `BlockMetadata.num_rows` update and sequential `ray.get` bottleneck in `_calculate_blocks_rows` (`python/ray/data/_internal/split.py`). ## Before When PR `#61059` made `BlockMetadata` immutable (`@dataclass(frozen=True)`), `_calculate_blocks_rows` was updated from `metadata.num_rows = num_rows` to `metadata = replace(metadata, num_rows=num_rows)` inside `for block, metadata in blocks_with_metadata:`, which only rebound the local loop variable without writing `(block, metadata)` back into `blocks_with_metadata[i]`. In addition, when multiple blocks had `metadata.num_rows is None`, `_calculate_blocks_rows` executed `ray.get(get_num_rows.remote(block))` sequentially one block at a time. As a result, whenever any input block had `metadata.num_rows is None`: 1. `_equalize()` in `python/ray/data/_internal/equalize.py:51` crashed with `TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'` at `sum([meta.num_rows for _, meta in shaved_split])` because untouched blocks retained `meta.num_rows is None`. 2. `_split_leftovers` -> `_split_at_indices` (`equalize.py:66`) had to re-run `get_num_rows.remote(block)` a second time on leftover blocks whose `metadata.num_rows` was never persisted. ```mermaid flowchart LR subgraph Sub["Subsystem: Shuffle / aggregation"] subgraph Mod["Module: split.py / equalize.py"] calc["_calculate_blocks_rows()<br/>1. Serial ray.get per block<br/>2. Local `metadata = replace(...)` lost"] eq["_equalize()<br/>sum(meta.num_rows) -> TypeError: int + NoneType"] calc --> eq end end style calc fill:#f8d7da,stroke:#dc3545,color:#000 style eq fill:#f8d7da,stroke:#dc3545,color:#000 ``` ## After `_calculate_blocks_rows` collects all indices with `metadata.num_rows is None`, fetches their row counts in a single batched `ray.get([get_num_rows.remote(...) for i in missing_indices])` call, and writes `(block, replace(metadata, num_rows=num_rows))` back into `blocks_with_metadata[i]`. ```mermaid flowchart LR subgraph Sub["Subsystem: Shuffle / aggregation"] subgraph Mod["Module: split.py / equalize.py"] calc["_calculate_blocks_rows()<br/>1. Batched ray.get across missing blocks<br/>2. Persists replace(metadata, num_rows=...) in blocks_with_metadata"] eq["_equalize()<br/>All shaved & leftover blocks have populated meta.num_rows"] calc --> eq end end style calc fill:#d4edda,stroke:#28a745,color:#000 style eq fill:#d4edda,stroke:#28a745,color:#000 ``` ## Subsystems - [x] Shuffle / aggregation (`python/ray/data/_internal/split.py`, `python/ray/data/_internal/equalize.py`) ## Testing - Added `test_calculate_blocks_rows_updates_metadata_and_batches_ray_get` and `test_equalize_with_unknown_num_rows_metadata` in `python/ray/data/tests/test_split.py`. - Verified `_calculate_blocks_rows`, `_split_at_indices`, and `_equalize` with `BlockMetadata(num_rows=None, ...)`. ## Duplicate-Work Check & Acknowledgments - Searched open and closed issues and PRs in `ray-project/ray` for `_calculate_blocks_rows`, `_equalize`, and `BlockMetadata` `num_rows`; no existing issue or PR covers this bug. - Credits and thanks to Alexey Kudinkin (`@alexeykudinkin`, `#61059`), `@wufeiye` (`#62665`), and Balaji Veeramani (`@bveeramani`, `#45481`) for their work on immutable `BlockMetadata` and Ray Data splitting/equalization. - *AI assistance disclosure: GitHub Copilot CLI (Claude Sonnet 4.6) was used to assist with test scaffolding and PR formatting; all changes were verified locally.* --------- Signed-off-by: Parth Vadera <[email protected]> Co-authored-by: Copilot <[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.
Why are these changes needed?
The
_split_at_indexfunction isn't used anywhere. This PR removes it.Related issue number
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.