Skip to content

[data][train] Mid-epoch resumption (4/n): Support generated ID columns - #66800

Merged
goutamvenkat-anyscale merged 2 commits into
ray-project:masterfrom
justinvyu:justinvyu/generated-id-mid-epoch-resume
Oct 31, 2026
Merged

goutamvenkat-anyscale merged 2 commits into
ray-project:masterfrom
justinvyu:justinvyu/generated-id-mid-epoch-resume

Conversation

@justinvyu

Copy link
Copy Markdown
Contributor

Stacked on #66680 (which is stacked on #66562 and #66563). Only review the last commit: "[Data][Train] Support generated ID columns for mid-epoch resumption".

Depends on the generated-ID checkpointing stack: #66732 adds CheckpointConfig(generated_id_column=...), and #66733 / #66736 skip committed rows on restore. This PR assumes that API and can't merge before #66732.

Description

Adds DatasetCheckpointConfig(generate_id_column=True) for mid-epoch resumption. Users whose datasets have no unique ID column can then checkpoint the data iterator with row IDs that Ray Data generates from each row's location in its Parquet file.

Changes:

  • DatasetCheckpointConfig: generate_id_column=True no longer raises NotImplementedError. Only Parquet reads on the V2 datasource path are supported.
  • CheckpointingBatchIterator: when the ID column is generated, it's recorded in BatchMetadata.row_ids for checkpointing, then removed from the batch before it's yielded, so users only see their own columns. A user-provided id_column is kept.
  • DatasetManager._build_restoration_checkpoint_config: builds the dataset's CheckpointConfig with generated_id_column= instead of id_column= when generating. The config is set even when there's nothing to restore, because the reader needs it to generate the ID column.
  • Release test: mid_epoch_resume_benchmark_{{scale}} passes --generate_id_column.

Related issues

Not a duplicate: this adds Train-ingest support on top of the generated-ID checkpointing stack (#66732, #66733, #66736), which covers batch inference only.

Additional information

Tests (run locally, Python 3.11, macOS):

  • pytest python/ray/data/tests/test_data_iterator_checkpointer.py: 25 passed. This includes the new test_generated_id_column_removed_from_batches, which checks that the column is removed from batches when generated and kept otherwise, and that the IDs are checkpointed either way.
  • RAY_TRAIN_V2_ENABLED=1 pytest python/ray/train/v2/tests/test_dataset_checkpointing.py python/ray/train/v2/tests/test_dataset_manager.py:
  • pre-commit run on the changed files: passed.

AI assistance (Claude Code) was used to develop this change.

🤖 Generated with Claude Code

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@justinvyu justinvyu changed the title [Data][Train] Support generated ID columns for mid-epoch resumption [data][train] Mid-epoch resumption (4/n): Support generated ID columns Oct 7, 2026
@justinvyu
justinvyu force-pushed the justinvyu/generated-id-mid-epoch-resume branch 2 times, most recently from 35ffbc4 to 3030e3e Compare October 7, 2026 17:27
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

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.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Oct 22, 2026
goutamvenkat-anyscale added a commit that referenced this pull request Oct 23, 2026
…() (#67157)

## Description

`CheckpointConfig(generated_id_column=...)` can be set on a dataset
after `read_parquet()` built it — Ray Train's `DatasetManager` does
exactly this (see #66800). Previously `read_parquet()` snapshotted the
config at call time and baked the generated ID column into the
datasource constructor, so a config set afterwards never produced the
column and checkpointing silently recorded nothing.

This PR moves the binding to plan time:

- New logical rule `BindGeneratedIdColumn`, run in
`LogicalOptimizer._post_optimize` (after the rule loop, before
`DeriveListFilesPushdown`): adds the column to the `ParquetScanner` and
to `Project`s built before the config was set.
- `read_parquet()` no longer binds the column; its call-time config
snapshot and the `_add_generated_id_column` /
`extra_synthesized_columns` plumbing are removed.
- `_validate_generated_id_plan` now runs on every generated-ID plan and
fails at planning if a scanner is missing the column.
- `schema()` / `columns()` agree with execution: `_base_schema` applies
`BindGeneratedIdColumn` when the configured column is missing from its
answer (metadata is inferred from the unoptimized DAG, which doesn't run
the rule), including over a schema cached before the config was set.

ID *values* are unchanged (`GeneratedIdColumn.compute()` in the read
tasks); only where the column attaches to the plan moved.

### Why plan time: who knows what, when

This change exists for Ray Train's mid-epoch resumption (#66800): there,
`DatasetManager` derives the `CheckpointConfig` from fit-time state —
the restored `state_dict` and its restore filter — and stamps it onto
the user's already-built dataset. That config cannot exist yet when the
user calls `read_parquet()`, and since each dataset snapshots its own
`DataContext` at build time, setting it globally afterwards would never
reach an already-built dataset either. The only ordering that works is
the one #66800 uses — stamp the built dataset — with Ray Data picking
the config up when the executed plan is optimized:

```mermaid
sequenceDiagram
    participant U as user code
    participant T as Ray Train (DatasetManager)
    participant D as dataset's DataContext / plan

    U->>D: ds = ray.data.read_parquet(...)
    Note over D: DataContext.copy() snapshot — checkpoint_config: None
    U->>T: trainer.fit(datasets={"train": ds})
    rect rgba(66, 135, 245, 0.25)
        T->>T: rank 0 requests its shard: get_dataset_shard("train", state_dict=...)
        T->>D: ds.context.checkpoint_config = CheckpointConfig(generated_id_column=..., restore filter)
    end
    rect rgba(235, 140, 60, 0.3)
        loop each epoch
            D->>D: optimize plan — BindGeneratedIdColumn binds the column — then execute
        end
    end
```

🟦 Train's mid-epoch-resume wiring (PR 66800) · 🟧 this PR (plan-time
binding) · unshaded steps are pre-existing behavior.

### New flow

```mermaid
flowchart TB
    subgraph build["Dataset build (lazy)"]
        RP["read_parquet()<br/>builds ListFiles → ReadFiles<br/><i>no column decision</i>"]
        CFG["ds.context.checkpoint_config = CheckpointConfig(generated_id_column=...)<br/><i>at any point before execution</i>"]
    end
    subgraph opt["Execution: LogicalOptimizer"]
        LOOP["Ruleset loop<br/>(projection pushdown, ...)"]
        BIND["<b>BindGeneratedIdColumn</b><br/>reads plan.context.checkpoint_config,<br/>appends GeneratedIdColumn to the ParquetScanner,<br/>keeps it through earlier-built Projects"]
        DLP["DeriveListFilesPushdown<br/>listing sees the bound projection"]
    end
    subgraph plan["Planner"]
        VAL["_validate_generated_id_plan<br/>every source is a V2 Parquet read<br/><b>and carries the column</b>, else<br/>InvalidCheckpointingConfig at planning"]
    end
    subgraph exec["Read tasks"]
        COMPUTE["GeneratedIdColumn.compute()<br/>stamps (file, row group, row offset)<br/>per batch — unchanged"]
    end
    RP --> CFG --> LOOP --> BIND --> DLP --> VAL --> COMPUTE
```

## Testing

```
pytest python/ray/data/tests/unit/datasource_v2/test_bind_generated_id_column.py \
       python/ray/data/tests/unit/datasource_v2/test_generated_id_column.py
# 22 passed

cd python/ray/data/tests && pytest test_checkpoint.py -k "generated_id"
# 26 passed (includes new tests: config set after the dataset is built, with
# select_columns / with_column / streaming_split, and plan-validation failures)
```

## Notes

- Not a duplicate: no open PR binds the generated ID column at plan
time. #66800 (Train mid-epoch resumption) is a consumer of this
behavior, not an implementation of it; coordinated with that stack.
- AI assistance was used for this PR. I reviewed every changed line and
ran the tests above locally.

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

---------

Signed-off-by: Goutam <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Oct 24, 2026
goutamvenkat-anyscale pushed a commit that referenced this pull request Oct 31, 2026
…mark (#66680)

> Stacked on #66562 (and #66563). Only review the last commit: "[Train]
Add mid-epoch resumption release test".

## Description

Adds a nightly release test for mid-epoch resumption with data iterator
checkpointing: `mid_epoch_resume_benchmark_{10M,3B}`.

`release/train_tests/mid_epoch_resume_benchmark/microbenchmark.py` runs
a `TorchTrainer` with 16 mock-GPU workers over a Parquet dataset of 10M
or 3B rows, using `DataConfig(dataset_checkpoint_configs={"train":
DatasetCheckpointConfig(id_column="id", ...)})`.
- It saves a data checkpoint with `DataIterator.state_dict()` every
`checkpoint_interval` batches and at the end of each epoch, and stores
it in the Ray Train checkpoint.
- It injects a failure 90% of the way through the epoch
(`--error_at=0.9`) and resumes from the latest checkpoint with
`ray.train.get_dataset_shard("train", state_dict=...)`.
- **Correctness:** after training, it checks that each epoch's
checkpoint files cover exactly `total_dataset_rows` rows, so every row
is seen exactly once per epoch, even across the restart.
- **Performance:** it reports the total duration and the time to first
batch with and without a data checkpoint, which includes the checkpoint
load time.

Release test config:
- One test entry with a `scale` matrix (`10M`, `3B`), nightly, `byod:
gpu`, `anyscale_sdk_2026: true`, and a 2700s timeout.
- Compute configs (`compute_configs/{10M,3B}.yaml`): an `m5.2xlarge`
head node with no CPUs, plus 10 or 50 `m5.8xlarge` workers with
`MOCK_GPU: 4` and a 64 GB object store.
- `--generate_id_column` is supported by the script but not passed,
since `DatasetCheckpointConfig(generate_id_column=True)` isn't
implemented yet (it depends on #65885–#65888).

## Related issues

Not a duplicate: there's no existing release test for data iterator
checkpointing or mid-epoch resumption.

Generated ID column support (and `--generate_id_column` in this release
test) is stacked on this PR: #66800

## Additional information

Testing:
- `pre-commit run` on the changed files: passed.
- The release test itself hasn't been run yet. I'll trigger it before
marking this ready.

AI assistance (Claude Code) was used to develop this change.

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

Signed-off-by: Justin Yu <[email protected]>
@goutamvenkat-anyscale
goutamvenkat-anyscale force-pushed the justinvyu/generated-id-mid-epoch-resume branch from 3030e3e to d567ad5 Compare October 31, 2026 02:58
@goutamvenkat-anyscale
goutamvenkat-anyscale force-pushed the justinvyu/generated-id-mid-epoch-resume branch from d567ad5 to 1866524 Compare October 31, 2026 03:00
@goutamvenkat-anyscale
goutamvenkat-anyscale marked this pull request as ready for review October 31, 2026 03:02
@goutamvenkat-anyscale
goutamvenkat-anyscale requested a review from a team as a code owner October 31, 2026 03:02
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@goutamvenkat-anyscale
goutamvenkat-anyscale requested review from a team as code owners October 31, 2026 03:02
@goutamvenkat-anyscale goutamvenkat-anyscale added go add ONLY when ready to merge, run all tests and removed unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. labels Oct 31, 2026
@goutamvenkat-anyscale
goutamvenkat-anyscale enabled auto-merge (squash) October 31, 2026 03:41
@ray-gardener ray-gardener Bot added train Ray Train Related Issue data Ray Data-related issues release-test release test labels Oct 31, 2026
@ray-gardener ray-gardener Bot added the community-contribution Contributed by the community label Oct 31, 2026
@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit 03d3d8a into ray-project:master Oct 31, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues go add ONLY when ready to merge, run all tests release-test release test train Ray Train Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants