Skip to content

[Data] Remove unused _split_at_index - #45481

Merged
bveeramani merged 3 commits into
ray-project:masterfrom
bveeramani:remove-split-at-index
May 21, 2024
Merged

bveeramani merged 3 commits into
ray-project:masterfrom
bveeramani:remove-split-at-index

Conversation

@bveeramani

Copy link
Copy Markdown
Member

Why are these changes needed?

The _split_at_index function isn't used anywhere. This PR removes it.

Related issue number

Checks

Signed-off-by: Balaji Veeramani <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
@bveeramani
bveeramani enabled auto-merge (squash) May 21, 2024 19:16
@github-actions github-actions Bot added the go add ONLY when ready to merge, run all tests label May 21, 2024
@github-actions
github-actions Bot disabled auto-merge May 21, 2024 21:05
@bveeramani
bveeramani merged commit cd3d3b7 into ray-project:master May 21, 2024
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants