Skip to content

[train] Raise errors when mixing V1 and V2 API usage#57570

Merged
justinvyu merged 12 commits intoray-project:masterfrom
justinvyu:v2_migration_message
Oct 9, 2025
Merged

[train] Raise errors when mixing V1 and V2 API usage#57570
justinvyu merged 12 commits intoray-project:masterfrom
justinvyu:v2_migration_message

Conversation

@justinvyu
Copy link
Copy Markdown
Contributor

Summary

Raise if users try running with a cross of V1/V2 APIs. This includes V1 Trainer with V2 configs and V2 Trainer with V1 configs.

Examples

V1 Trainer with V2 configs:

import os

os.environ["RAY_TRAIN_V2_ENABLED"] = "1"

import ray.train
from ray.train.data_parallel_trainer import DataParallelTrainer

DataParallelTrainer(
    lambda: ray.train.get_dataset_shard("train"),
    scaling_config=ray.train.ScalingConfig(num_workers=1),
).fit()
DeprecationWarning: Detected use of a deprecated Trainer import from `ray.train.data_parallel_trainer`. This Trainer class is not compatible with Ray Train V2.
To fix this:
  - Update to use the new import path. For example, `from ray.train.torch.torch_trainer import TorchTrainer` -> `from ray.train.torch import TorchTrainer`
  - Or, explicitly disable V2 by setting: RAY_TRAIN_V2_ENABLED=0

V2 Trainer with V1 configs:

import os

os.environ["RAY_TRAIN_V2_ENABLED"] = "1"

import ray.air
import ray.tune
import ray.train

from ray.train.v2.api.data_parallel_trainer import DataParallelTrainer


DataParallelTrainer(
    lambda: ray.train.get_dataset_shard("train"),
    scaling_config=ray.train.ScalingConfig(num_workers=1),
    run_config=ray.air.RunConfig(failure_config=ray.tune.FailureConfig(max_failures=1)),
).fit()
Traceback (most recent call last):
  File "/Users/justin/Developer/random/v1_to_v2.py", line 24, in <module>
    DataParallelTrainer(
  File "/Users/justin/Developer/ray/python/ray/train/v2/api/data_parallel_trainer.py", line 111, in __init__
    self._validate_configs()
  File "/Users/justin/Developer/ray/python/ray/train/v2/api/data_parallel_trainer.py", line 129, in _validate_configs
    raise ValueError(
ValueError: Invalid `RunConfig` type: <class 'ray.air.config.RunConfig'>. Use `ray.train.RunConfig` instead.

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
@justinvyu justinvyu requested a review from a team as a code owner October 8, 2025 20:33
cursor[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

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

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 is a great step towards improving the user experience by preventing the mixing of V1 and V2 APIs in Ray Train. The added validation checks will make the transition smoother for users and reduce potential confusion. I've identified a couple of areas for improvement in the tests to make them more robust and complete. My comments are below.

Copy link
Copy Markdown
Contributor

@liulehui liulehui left a comment

Choose a reason for hiding this comment

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

🚢

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
@justinvyu justinvyu enabled auto-merge (squash) October 8, 2025 22:44
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Oct 8, 2025
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
@github-actions github-actions bot disabled auto-merge October 8, 2025 23:39
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
@ray-gardener ray-gardener bot added the train Ray Train Related Issue label Oct 9, 2025
@justinvyu justinvyu merged commit 2d037c0 into ray-project:master Oct 9, 2025
6 checks passed
@justinvyu justinvyu deleted the v2_migration_message branch October 9, 2025 17:16
pavitrabhalla pushed a commit to superserve-ai/ray that referenced this pull request Oct 10, 2025
Raise if users try running with a cross of V1/V2 APIs. This includes V1
Trainer with V2 configs and V2 Trainer with V1 configs.

---------

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Pavitra Bhalla <pavitra@rayai.com>
joshkodi pushed a commit to joshkodi/ray that referenced this pull request Oct 13, 2025
Raise if users try running with a cross of V1/V2 APIs. This includes V1
Trainer with V2 configs and V2 Trainer with V1 configs.

---------

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Josh Kodi <joshkodi@gmail.com>
ArturNiederfahrenhorst pushed a commit to ArturNiederfahrenhorst/ray that referenced this pull request Oct 13, 2025
Raise if users try running with a cross of V1/V2 APIs. This includes V1
Trainer with V2 configs and V2 Trainer with V1 configs.

---------

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
harshit-anyscale pushed a commit that referenced this pull request Oct 15, 2025
Raise if users try running with a cross of V1/V2 APIs. This includes V1
Trainer with V2 configs and V2 Trainer with V1 configs.

---------

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
justinyeh1995 pushed a commit to justinyeh1995/ray that referenced this pull request Oct 20, 2025
Raise if users try running with a cross of V1/V2 APIs. This includes V1
Trainer with V2 configs and V2 Trainer with V1 configs.

---------

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
xinyuangui2 pushed a commit to xinyuangui2/ray that referenced this pull request Oct 22, 2025
Raise if users try running with a cross of V1/V2 APIs. This includes V1
Trainer with V2 configs and V2 Trainer with V1 configs.

---------

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: xgui <xgui@anyscale.com>
elliot-barn pushed a commit that referenced this pull request Oct 23, 2025
Raise if users try running with a cross of V1/V2 APIs. This includes V1
Trainer with V2 configs and V2 Trainer with V1 configs.

---------

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
Raise if users try running with a cross of V1/V2 APIs. This includes V1
Trainer with V2 configs and V2 Trainer with V1 configs.

---------

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Aydin-ab pushed a commit to Aydin-ab/ray-aydin that referenced this pull request Nov 19, 2025
Raise if users try running with a cross of V1/V2 APIs. This includes V1
Trainer with V2 configs and V2 Trainer with V1 configs.

---------

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Aydin Abiar <aydin@anyscale.com>
Future-Outlier pushed a commit to Future-Outlier/ray that referenced this pull request Dec 7, 2025
Raise if users try running with a cross of V1/V2 APIs. This includes V1
Trainer with V2 configs and V2 Trainer with V1 configs.

---------

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Future-Outlier <eric901201@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants