Repository navigation
[Data][Train] Remove top-level ray.data imports to decouple Ray Train from Ray Data - #60292
Conversation
… from Ray Data Signed-off-by: Haichuan Hu <[email protected]>
There was a problem hiding this comment.
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.
bveeramani
left a comment
There was a problem hiding this comment.
LGTM overall. Only questions are about _get_execution_options_class() and _get_execution_resources_class()
| 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 |
There was a problem hiding this comment.
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?)
… from Ray Data Signed-off-by: Haichuan Hu <[email protected]>
… from Ray Data Signed-off-by: Haichuan Hu <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
Signed-off-by: Balaji Veeramani <[email protected]>
…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]>
Description
Remove all top-level imports of
ray.datafrom theray.trainmodule. Imports needed only for type annotations should be guarded behind ifTYPE_CHECKING:. Imports needed at runtime should be moved inline (lazy imports within functions/methods).@tianyi-ge
Related issues
Fixes #60152.