Skip to content

[Data][Train] Remove top-level ray.data imports to decouple Ray Train from Ray Data - #60292

Merged
bveeramani merged 7 commits into
ray-project:masterfrom
KaisennHu:decouple-ray-data
Jan 20, 2026
Merged

bveeramani merged 7 commits into
ray-project:masterfrom
KaisennHu:decouple-ray-data

Conversation

@KaisennHu

@KaisennHu KaisennHu commented Jan 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Remove all top-level imports of ray.data from the ray.train module. Imports needed only for type annotations should be guarded behind if TYPE_CHECKING:. Imports needed at runtime should be moved inline (lazy imports within functions/methods).
@tianyi-ge

Related issues

Fixes #60152.

@KaisennHu
KaisennHu requested a review from a team as a code owner January 19, 2026 11:48

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively decouples Ray Train from Ray Data by removing top-level ray.data imports. The changes are implemented consistently across all modified files, using TYPE_CHECKING guards for type annotations and lazy, inline imports for runtime dependencies. This is a solid refactoring that improves modularity and dependency management within the Ray ecosystem. The implementation is clean and correct, and I have no further suggestions.

@ray-gardener ray-gardener Bot added train Ray Train Related Issue community-contribution Contributed by the community labels Jan 19, 2026

@bveeramani bveeramani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. Only questions are about _get_execution_options_class() and _get_execution_resources_class()

Comment on lines +12 to +25
def _get_execution_options_class():
"""Lazy import of ExecutionOptions."""
from ray.data import ExecutionOptions

return ExecutionOptions


def _get_execution_resources_class():
"""Lazy import of ExecutionResources."""
from ray.data._internal.execution.interfaces.execution_options import (
ExecutionResources,
)

return ExecutionResources

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we import these under if TYPE_CHECKING? If that doesn't work, what happens if we import these in the function definitions (e.g., in the DataConfig constructor?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it.

@bveeramani
bveeramani enabled auto-merge (squash) January 20, 2026 21:03
@github-actions github-actions Bot added the go add ONLY when ready to merge, run all tests label Jan 20, 2026
@bveeramani
bveeramani merged commit b16808c into ray-project:master Jan 20, 2026
@KaisennHu
KaisennHu deleted the decouple-ray-data branch January 24, 2026 02:04
goutamvenkat-anyscale pushed a commit that referenced this pull request Oct 30, 2026
…raining worker side (#66562)

> Stacked on #66563. Only review the last commit: "[Train] Support
mid-epoch resumption with dataset checkpoint configs".

## Description

Adds mid-epoch resumption to Ray Train V2 through data iterator
checkpointing.

User-facing API:

```python
trainer = TorchTrainer(
    train_fn,
    datasets={"train": ds},
    dataset_config=ray.train.DataConfig(
        dataset_checkpoint_configs={
            "train": ray.train.DatasetCheckpointConfig(id_column="id")
        }
    ),
)

def train_fn(config):
    state_dict = ...  # loaded from the latest ray.train checkpoint, if any
    it = ray.train.get_dataset_shard("train", state_dict=state_dict)
    for batch in it.iter_torch_batches():
        ...
        # Save alongside the model checkpoint.
        data_state = it.state_dict()
```

Changes:
- `ray.train.get_dataset_shard(dataset_name, state_dict=None)`, with a
new `DatasetShardMetadata.state_dict` field.
- `DataConfig(dataset_checkpoint_configs=...)`. It raises
`NotImplementedError` for datasets that aren't in `datasets_to_split`,
since only `streaming_split` plans support checkpointing.
- `ray.train.DatasetCheckpointConfig` (defined in
`ray.data.checkpoint.interfaces`), exported with V2 only and added to
the Train API reference (`doc/source/train/api/config.md`). It's
annotated `PublicAPI(stability="alpha")` where it's defined in Ray Data
(#66563), which also whitelists it in the Data API docs check since it's
documented here. Like the other `ray.train` exports, its `__module__` is
set to `ray.train`, so it shows up and pickles as
`ray.train.DatasetCheckpointConfig`.
- `DatasetManager` imports the data iterator checkpointer lazily,
following #60292, which keeps `ray.data` imports out of module scope in
Ray Train.
- `DatasetManager`:
- Restore: builds the restore `CheckpointConfig` from the state dict
(partition filter, `_should_restore`) and sets `_execution_idx` so file
shuffle order can be reproduced.
- Save: attaches a `RowIDBasedDataIteratorCheckpointer` to each rank's
iterator.
- `DatasetsCallback`:
- Defaults `checkpoint_path` to
`{experiment_fs_path}/ray_data_checkpoints/{dataset_name}`, on the
`RunConfig` storage filesystem. If the user sets `checkpoint_path` but
not `override_filesystem`, the filesystem is inferred from the path
instead.
- Raises a `ValueError` if two datasets use the same `checkpoint_path`,
since the checkpoint files aren't partitioned by dataset.
- The shard provider rejects a `state_dict` passed on a later
`get_dataset_shard` call.

## Related issues

Not a duplicate: I searched open and closed PRs for "iterator
checkpoint", "mid-epoch" and "state_dict" and found nothing overlapping.

The release test for this feature is stacked on this PR: #66680

## Additional information

Tests (run locally, Python 3.11, macOS):
- `RAY_TRAIN_V2_ENABLED=1 pytest
python/ray/train/v2/tests/test_dataset_checkpointing.py`: 6 passed. This
covers e2e restore from mid-epoch and from an epoch boundary with
injected failures, checkpoint path and filesystem defaults, `DataConfig`
validation, and data-order reproducibility after restore.
- `pre-commit run` on all changed files: passed

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]>
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 go add ONLY when ready to merge, run all tests train Ray Train Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Data][Train] Remove top-level ray.data imports to decouple Ray Train from Ray Data

3 participants