Skip to content

[train] Warn on Ray Train v1 mode, v1 trainers and v1-only public paths - #68144

Closed
pseudo-rnd-thoughts wants to merge 1 commit into
ray-project:masterfrom
pseudo-rnd-thoughts:train-deprecated/v1-warning
Closed

pseudo-rnd-thoughts wants to merge 1 commit into
ray-project:masterfrom
pseudo-rnd-thoughts:train-deprecated/v1-warning

Conversation

@pseudo-rnd-thoughts

Copy link
Copy Markdown
Member

Description

This PR starts the Ray 3.0 deprecation clock for Ray Train v1. Train v2 has been the default since Oct 2025, but nothing warns that v1 as a whole is deprecated. Each new warning names Ray 3.0 as the removal version and the replacement. RAY_TRAIN_ENABLE_V2_MIGRATION_WARNINGS=0 silences them, the same as the existing v1 migration warnings.

Trigger Change
RAY_TRAIN_V2_ENABLED=0 Warn once on import ray.train, pointing at the user's import. Ray worker processes skip it, so it doesn't repeat for every Train worker, Tune trial and RLlib learner.
Building a v1 trainer Warn in v1 BaseTrainer.__init__. The warning points at the user's line (not the super().__init__ calls inside Ray) and names the v2 replacement, e.g. ray.train.torch.TorchTrainer. It's skipped in worker processes, where Tune rebuilds the trainer.
ray.train.SyncConfig, ray.train.context.{TrainContext, get_context}, ray.train.error.SessionMisuseError These are now module __getattr__ aliases that warn. Ray's own code imports private names (_TrainContext, _SessionMisuseError, …). Lookups from inside the ray package, including ray.cloudpickle pickling by reference, don't warn, because users can't fix those. SyncConfig is removed from ray.train.__all__.
ray.train.torch.{accelerate, prepare_optimizer, backward} These already warn in v1 (#51066) and raise in v2. This PR only adds the message to their @Deprecated docs and says "Ray 3.0". The message is now defined once, in ray.train.constants.

Notes for review:

  • Pickles. SyncConfig keeps __module__ = "ray.train", so existing pickled RunConfig(sync_config=...) objects, including Tune experiment state, still load. Unpickling them in user code (not Ray's deserializer) emits the warning.
  • _find_caller in ray/train/utils.py attributes a warning to the first frame outside the ray package. It skips importlib's _handle_fromlist (package from x import y) and the pickle lookup machinery, and it matches CPython's rule of not counting frozen importlib frames in stacklevel.
  • Docs and redirects for these paths are a separate work package (the migration-guide/docs PR). deprecated.rst still resolves every name through __getattr__.

Related issues

Related to #49454 (Ray Train v2 migration).

Additional information

Not a duplicate: I searched open PRs for "train v1 deprecation warning" and "RAY_TRAIN_V2_ENABLED deprecat" and found nothing overlapping.

Tests:

  • New python/ray/train/tests/test_v1_deprecation_warnings.py, run with RAY_TRAIN_V2_ENABLED=0 as in its BUILD target. 17 passed. It covers:
    • the v1-mode import warning fires once and points at the user's import;
    • the opt-out works;
    • importing ray.train / ray.tune / ray.rllib raises no RayDeprecationWarning in either v1 or v2 mode;
    • each alias warns and returns the same object;
    • ray.cloudpickle pickling doesn't warn;
    • the trainer warning fires, points at the user's line, and names the right replacement.
  • Existing tests, each file run in its own process:
    • RAY_TRAIN_V2_ENABLED=0 python -m pytest python/ray/train/tests/{test_api_migrations,test_session,test_storage}.py: 7, 32 and 14 passed.
    • python -m pytest python/ray/tune/tests/{test_syncer,test_api_migrations,test_function_api}.py: 13, 3 and 12 passed.
    • train/v2/tests/test_torch_trainer.py was still running locally when I opened this PR. CI will cover it.
  • test_session.py::test_locking fails when it runs in the same process as test_api_migrations.py. It fails the same way on unmodified master and passes on its own; Bazel runs each file separately.
  • pre-commit run --files <changed files> is clean.

AI assistance: I wrote this change with Claude Code. I reviewed the diff and ran the tests listed above.

🤖 Generated with Claude Code

Start the Ray 3.0 deprecation clock for Ray Train v1 (T1.3 of the AIR /
Train v1 removal plan). Each warning names Ray 3.0 as the removal version
and the replacement, and RAY_TRAIN_ENABLE_V2_MIGRATION_WARNINGS=0 silences
it.

- Warn once on `import ray.train` when RAY_TRAIN_V2_ENABLED=0. Ray worker
  processes skip it.
- Warn in v1 `BaseTrainer.__init__`, attributed to the user's line and
  naming the v2 trainer that replaces it. Skipped in Ray worker processes,
  where Tune rebuilds the trainer.
- Turn `ray.train.SyncConfig`, `ray.train.context.{TrainContext,get_context}`
  and `ray.train.error.SessionMisuseError` into module `__getattr__`
  aliases that warn. Ray code imports private names, and lookups from
  inside the `ray` package (including pickling) don't warn.
- Add the deprecation message to the `@Deprecated` docs of the torch AMP
  utilities, which already warn in v1 and raise in v2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Mark Towers <[email protected]>
@pseudo-rnd-thoughts pseudo-rnd-thoughts added the train Ray Train Related Issue label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

train Ray Train Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant