Skip to content

Commit

Permalink
[1/n] Lightweight Ray AIR API refactor (ray-project#36706)
Browse files Browse the repository at this point in the history
This PR removes some circularities in the Ray AIR import system so we can put the training related functions into `ray.train`. It introduces a training context and makes report, get_dataset_shard, Checkpoint, Result, and the following configs:

- CheckpointConfig
- DataConfig
- FailureConfig
- RunConfig
- ScalingConfig

available in `ray.train`. No user facing changes yet, the old APIs still work.

Going forward, it will be most consistent / symmetrical if these things are included in the following way:

```python
from ray import train, tune, serve # Pick the subset that is needed
from ray.train import CheckpointConfig, DataConfig, FailureConfig, RunConfig, ScalingConfig

def train_func():
    dataset_shard = train.get_dataset_shard("train")
    world_size = train.get_context().get_world_size()
    # ...
    train.report(...)

trainer = train.torch.TorchTrainer(
    train_func,
    scaling_config=ScalingConfig(num_workers=2),
)
result = trainer.fit()
```

We have many examples in ray-project#37123 on how this looks like in actual code.
  • Loading branch information
pcmoritz authored and Bhav00 committed Jul 28, 2023
1 parent 7b27d4b commit 617b73c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion python/ray/train/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from ray.train._internal.data_config import DataConfig
from ray.train._internal.session import get_dataset_shard, report
from ray.train.backend import BackendConfig
from ray.train.constants import TRAIN_DATASET_KEY
from ray.train.data_config import DataConfig
from ray.train.context import get_context
from ray.train.constants import TRAIN_DATASET_KEY
from ray.train._internal.session import get_dataset_shard, report
from ray.train.trainer import TrainingIterator

from ray.air import Checkpoint
Expand Down

0 comments on commit 617b73c

Please sign in to comment.