Skip to content

[Data][Chkpt][4/5] DSv2: excluded_rows hook to drop rows of partly finished read units - #66735

Closed
abhishekverma-ray wants to merge 1 commit into
ray-project:masterfrom
abhishekverma-ray:rgc2-4-excluded-rows-hook
Closed

abhishekverma-ray wants to merge 1 commit into
ray-project:masterfrom
abhishekverma-ray:rgc2-4-excluded-rows-hook

Conversation

@abhishekverma-ray

Copy link
Copy Markdown
Contributor

Why are these changes needed?

The listing hook excluded_read_unit_ids (#66398) lets a resumed job skip read units it finished. A unit it finished only partly still has to be read, for example a Parquet row group that was being written when the job crashed. But its already-done rows must not be processed again, or they're written twice. DSv2 has no way to say "drop these rows" today: plan_read_files_op.do_read ignores its TaskContext, and Reader.read takes only the manifest.

This adds that hook, generic and in the same style as #66398. Nothing in it is checkpoint-specific.

What changes

  • EXCLUDED_ROWS_KWARG_NAME (interfaces/read_units.py): the TaskContext.kwargs key on the ReadFiles operator. It maps a ReadUnit.id to a boolean mask over the rows the reader produces from that unit, where True means drop. The module docstring explains how it pairs with EXCLUDED_READ_UNIT_IDS_KWARG_NAME.
  • Reader.read(input_split, excluded_rows=None): an optional argument. do_read passes the kwarg through. Without it, nothing changes.
  • FileReader.read drops masked rows right after synthesized columns are added, so those columns (e.g. a checkpoint ID) still see every row's original position.
    • The limit now counts rows after dropping, so a limit still returns the requested number of rows.
    • Batches left empty aren't yielded.
    • Rows past the end of a mask are kept, and unknown unit ids are ignored.

The mapping stays small: only units that were in flight when a job stopped are partly done.

cc @AarryaSaraf, since this is a new DSv2 hook (the proposal from Slack: excluded_rows, filtered after synthesis).

Related issue number

N/A. Not a duplicate (no open PR adds row-level exclusion; see 1/5 for the search). Note: this and 3/5 both add a private helper next to each other in common/file_reader.py; whichever lands second needs a trivial rebase. I verified both together on a combined branch.

Checks

  • I've signed off every commit (DCO).
  • I've run pre-commit on all changed files: clean.
  • AI assistance (Claude Code) was used for the development of this PR. I, Abhishek Verma, am the human submitter signing off on it: I have reviewed every changed line, run the tests below locally, and can defend the change end-to-end.
  • Testing:
    • pytest python/ray/data/tests/unit/datasource_v2/test_excluded_rows.py: 9 passed. Covers masked rows dropped across batch edges, kept rows keeping their original row_hash, limit counted after exclusion, fully masked batches not yielded, short masks keeping the rest, and no change without the kwarg, with an empty mapping, or with unknown ids.
    • pytest python/ray/data/tests/unit/datasource_v2 python/ray/data/tests/datasource_v2: 213 passed.
    • pytest python/ray/data/tests/datasource/test_read_parquet_v2.py: 37 passed. pytest python/ray/data/tests/test_execution_optimizer_limit_pushdown.py: 28 passed.
    • pytest python/ray/data/tests/datasource/test_parquet.py: 21 failures, the identical set as unmodified master in my environment (pandas 3 large_string); everything else passes.

🤖 Generated with Claude Code

…uded_rows` hook

The listing hook `excluded_read_unit_ids` (ray-project#66398) lets a resumed job skip
read units it finished. A unit it finished only partly, such as a Parquet
row group that was mid-write when the job crashed, still has to be read,
but its already-done rows must not be processed again.

- `EXCLUDED_ROWS_KWARG_NAME` (`interfaces/read_units.py`): the
  `TaskContext.kwargs` key on the `ReadFiles` operator, mapping a read unit
  id to a boolean mask over the rows the reader produces from that unit.
- `Reader.read(input_split, excluded_rows=None)`: the read task passes the
  mapping through; without it nothing changes.
- `FileReader` drops masked rows right after synthesized columns are added,
  so those columns (e.g. a checkpoint ID) still see every row's position;
  the limit now counts rows after dropping, and batches left empty are not
  yielded.

The mapping stays small: only units that were in flight when a job
stopped are partly done. Nothing sets the kwarg yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@abhishekverma-ray

Copy link
Copy Markdown
Contributor Author

Closing per review: no DSv2 reader change is needed. Each row's generated ID already names its file, row group and row_id, so 3/4 (#66736) drops the committed rows of partly done row groups with a DropCommittedRows step right after the read, fused into the read task. Thanks @AarryaSaraf for the suggestion.

1 similar comment
@abhishekverma-ray

Copy link
Copy Markdown
Contributor Author

Closing per review: no DSv2 reader change is needed. Each row's generated ID already names its file, row group and row_id, so 3/4 (#66736) drops the committed rows of partly done row groups with a DropCommittedRows step right after the read, fused into the read task. Thanks @AarryaSaraf for the suggestion.

goutamvenkat-anyscale pushed a commit that referenced this pull request Oct 16, 2026
…ng committed work at the source (#66736)

Follow-up to 1/4 (#66732) and 2/4 (#66733), both merged. 4/4 (#66734) is
an independent speed-up that lands last; this PR doesn't need it.

## Why are these changes needed?

This switches the feature on. A resumed `generated_id_column` job now
skips work it already committed, as early as possible. It doesn't run
the actor-pool `CheckpointFilter` that the `id_column` path applies to
every row.

## What changes

- **Planner routing** (`planner.py`). Generated-ID jobs get:
- `ListFiles` → `plan_list_files_op_with_done_read_units`: passes the
checkpoint's done unit ids as `EXCLUDED_READ_UNIT_IDS_KWARG_NAME` (the
hook from #66398). Fully committed files are never listed, and fully
committed row groups are never read.
- `ReadFiles` → `plan_read_files_op_with_done_rows`: the normal read
followed by a `DropCommittedRows` step for row groups that were only
partly committed.
- Each row's generated ID names its file, row group and `row_id`, so the
step looks up the row group's mask and drops rows where `mask[row_id]`
is set.
- The step fuses into the read task
(`ReadFilesParquetV2->DropCommittedRows->...`), so no extra stage runs.
- Thanks @AarryaSaraf for suggesting this over a new reader hook (the
former 4/5, #66735, now closed).
- The checkpoint's masks arrive as an Arrow table; each task indexes
them once (`_partial_mask_lookup`) and reuses the lookup for every
block. Masks stay numpy.
  - `Write` → the existing checkpoint two-phase commit.
- The `id_column` path is unchanged. 1/4's interim write-only gate is
removed.
- **Listing accepts Arrow ids** (`listing_utils.py`): the checkpoint
passes done unit ids as an Arrow array. Listing converts them to Python
strings before building its lookup set; a set built straight from an
Arrow array would hold Arrow values and never match.
  
- **Loading:** `LoadCheckpointCallback` loads the checkpoint once when
execution starts (`load_generated_id_checkpoint`, from 2/4). Both plan
functions read it through task kwargs set lazily
(`add_map_task_kwargs_fn`), because it isn't loaded at planning time. A
crashed run's pending checkpoints are still cleaned up while planning,
before the load.
- **Runs that don't restore** (`CheckpointConfig._should_restore`, from
#66563): after a successful run sets it to `False` (e.g. later training
epochs), the planner plans only the checkpoint write, as for
`id_column`, and `LoadCheckpointCallback` skips loading the generated-ID
checkpoint, since no operator reads it.
- **Validation:** plans whose sources aren't V2 Parquet reads
(`ReadFiles` over a `ParquetScanner`) raise `InvalidCheckpointingConfig`
with a pointer to `id_column`. This covers the V1 `Read` path and
non-Parquet V2 scanners.
- **Docs:** a "Checkpoint without an ID column" section in
`doc/source/data/execution-configurations.md`.

Note: like the `id_column` path's filter, `DropCommittedRows` runs after
the read, so a `limit` pushed into the read counts rows before they're
dropped.

## Related issue number

N/A. Not a duplicate (see 1/4). Replaces my pre-reorg drafts #65886,
#65887 and #65888.

## Checks

- [x] I've signed off every commit (DCO).
- [x] I've run pre-commit on all changed files: clean. `vale` (v3.17.1,
as in CI) on the docs page: 0 errors, 0 warnings, 0 suggestions.
- [x] AI assistance (Claude Code) was used for the development of this
PR. I, Abhishek Verma, am the human submitter signing off on it: I have
reviewed every changed line, run the tests below locally, and can defend
the change end-to-end.
- Testing:
- `pytest python/ray/data/tests/unit/test_generated_id_checkpoint.py`:
15 passed. New: masked rows dropped per row group in a block mixing row
groups and files; rows past a short mask kept; no matching mask means no
change; mask lookup across table chunks.
- `test_read_units.py`: listing skips done units whether the ids arrive
as a set, an Arrow array, or a chunked array. The Arrow cases fail
without the conversion.
- With `_should_restore=False`, a run ignores the kept checkpoint, reads
every row, never loads the checkpoint, and still writes checkpoints. I
checked that this test fails without the callback fix.
- On current master, `pytest python/ray/data/tests/test_checkpoint.py
python/ray/data/tests/test_data_iterator_checkpointer.py
python/ray/data/tests/unit/test_generated_id_checkpoint.py
python/ray/data/tests/unit/datasource_v2`: 299 passed, 1 failed. The
failure, `test_skip_checkpoint_flag[s3]`, is a pre-existing local
moto-S3 flake that also fails on unmodified master.
  - New end-to-end tests in `python/ray/data/tests/test_checkpoint.py`:
- Crash partway, then rerun: no missing rows, and the checkpoint is
deleted on success.
- Resume skips a fully committed file, a committed row group, and the
committed rows of a partly committed row group, and reads a never-seen
file in full. The output is exactly the uncommitted rows. I checked that
this test fails with `DropCommittedRows` disabled.
    - A rerun after a full success writes nothing.
- The plan has no `CheckpointFilter` op, and `DropCommittedRows` is
fused into the read.
    - Non-Parquet and V1 inputs are rejected.
- `pytest python/ray/data/tests/unit/test_generated_id_checkpoint.py`:
15 passed. New: masked rows dropped per row group in a block mixing row
groups and files; rows past a short mask kept; no matching mask means no
change; mask lookup across table chunks.
- Block sizing: a `generated_id_column` read produces the same number of
blocks per task as a plain read (`DropCommittedRows` keeps
`target_max_block_size`).
- `test_read_units.py`: listing skips done units whether the ids arrive
as a set, an Arrow array, or a chunked array. The Arrow cases fail
without the conversion.
- With `_should_restore=False`, a run ignores the kept checkpoint, reads
every row, never loads the checkpoint, and still writes checkpoints. I
checked that this test fails without the callback fix.
- On current master, `pytest python/ray/data/tests/test_checkpoint.py
python/ray/data/tests/test_data_iterator_checkpointer.py
python/ray/data/tests/unit/test_generated_id_checkpoint.py
python/ray/data/tests/unit/datasource_v2`: 299 passed, 1 failed. The
failure, `test_skip_checkpoint_flag[s3]`, is a pre-existing local
moto-S3 flake that also fails on unmodified master.
- `pytest python/ray/data/tests/unit
python/ray/data/tests/datasource_v2`: 1500 passed.
- Five modules didn't collect locally for missing optional dependencies
(torch, pyiceberg, freezegun).
- Two failures in `test_dynamic_work_queue.py`, which also fail on
unmodified master.
- **Together with 4/4** (local combined branch): 237 DSv2/unit and 38
checkpoint tests passed. In a manual resume run (4 files × 4 row groups,
16 write tasks), I deleted 6 committed checkpoint files and the rerun
wrote **exactly those 6,000 rows**.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Abhishek Verma <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant