Skip to content

[tune][train] Improve ray.train method deprecations called from Tune functions#57810

Merged
justinvyu merged 2 commits intoray-project:masterfrom
justinvyu:tune_train_method_deprecation
Oct 17, 2025
Merged

[tune][train] Improve ray.train method deprecations called from Tune functions#57810
justinvyu merged 2 commits intoray-project:masterfrom
justinvyu:tune_train_method_deprecation

Conversation

@justinvyu
Copy link
Contributor

@justinvyu justinvyu commented Oct 16, 2025

Description

Ray Tune users need to stop using ray.train.get_context(), ray.train.get_checkpoint() and ray.train.report. This PR improves the error messages raise if they try to call these instead of the ray.tune counterparts. Note that we've already soft-deprecated this usage with a warning message for 6+ months.

Related issues

#49454

Additional information

Before:

ray.exceptions.RayTaskError(RuntimeError): ray::ImplicitFunc.train() (pid=3034, ip=127.0.0.1, actor_id=b88a8a6f297b83cd04bc6a5001000000, repr=tune_fn)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justin/Developer/ray/python/ray/tune/trainable/trainable.py", line 331, in train
    raise skipped from exception_cause(skipped)
  File "/Users/justin/Developer/ray/python/ray/air/_internal/util.py", line 107, in run
    self._ret = self._target(*self._args, **self._kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justin/Developer/ray/python/ray/tune/trainable/function_trainable.py", line 44, in <lambda>
    training_func=lambda: self._trainable_func(self.config),
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justin/Developer/ray/python/ray/tune/trainable/function_trainable.py", line 249, in _trainable_func
    output = fn()
             ^^^^
  File "/Users/justin/Developer/ray/python/ray/tune/tests/test_api_migrations.py", line 25, in tune_fn
    ray.train.get_checkpoint()
  File "/Users/justin/Developer/ray/python/ray/train/v2/api/train_fn_utils.py", line 182, in get_checkpoint
    return get_train_fn_utils().get_checkpoint()
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/justin/Developer/ray/python/ray/train/v2/_internal/execution/train_fn_utils.py", line 264, in get_train_fn_utils
    raise RuntimeError("TrainFnUtils has not been initialized.")
RuntimeError: TrainFnUtils has not been initialized.

After:

ray.exceptions.RayTaskError(DeprecationWarning): ray::ImplicitFunc.train() (pid=97276, ip=127.0.0.1, actor_id=c9cd63f30250e52577c0b4c601000000, repr=tune_fn)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justin/Developer/ray/python/ray/tune/trainable/trainable.py", line 331, in train
    raise skipped from exception_cause(skipped)
  File "/Users/justin/Developer/ray/python/ray/air/_internal/util.py", line 107, in run
    self._ret = self._target(*self._args, **self._kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justin/Developer/ray/python/ray/tune/trainable/function_trainable.py", line 44, in <lambda>
    training_func=lambda: self._trainable_func(self.config),
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/justin/Developer/ray/python/ray/tune/trainable/function_trainable.py", line 249, in _trainable_func
    output = fn()
             ^^^^
  File "/Users/justin/Developer/ray/python/ray/tune/tests/test_api_migrations.py", line 44, in tune_fn
    ray.train.get_checkpoint()
  File "/Users/justin/Developer/ray/python/ray/train/v2/api/train_fn_utils.py", line 203, in get_checkpoint
    raise DeprecationWarning(
DeprecationWarning: `ray.train.get_checkpoint` is deprecated when running in a function passed to Ray Tune. Please use `ray.tune.get_checkpoint` instead. See this issue for more context: https://github.com/ray-project/ray/issues/49454

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Justin Yu <justinvyu@anyscale.com>
Copy link
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 improves the deprecation warnings for ray.train APIs when used within Ray Tune, which is a great enhancement for user experience. The implementation correctly raises DeprecationWarning and the accompanying tests cover both the new and old behavior. My review includes a couple of suggestions to improve code maintainability by reducing duplication in both the implementation and the tests. Overall, the changes are solid.

@justinvyu justinvyu added the go add ONLY when ready to merge, run all tests label Oct 16, 2025
@ray-gardener ray-gardener bot added the tune Tune-related issues label Oct 17, 2025
@justinvyu justinvyu merged commit be46118 into ray-project:master Oct 17, 2025
5 of 6 checks passed
@justinvyu justinvyu deleted the tune_train_method_deprecation branch October 17, 2025 17:49
justinyeh1995 pushed a commit to justinyeh1995/ray that referenced this pull request Oct 20, 2025
…e functions (ray-project#57810)

Ray Tune users need to stop using `ray.train.get_context()`,
`ray.train.get_checkpoint()` and `ray.train.report`. This PR improves
the error messages raise if they try to call these instead of the
`ray.tune` counterparts. Note that we've already soft-deprecated this
usage with a warning message for 6+ months.

---------

Signed-off-by: Justin Yu <justinvyu@anyscale.com>
xinyuangui2 pushed a commit to xinyuangui2/ray that referenced this pull request Oct 22, 2025
…e functions (ray-project#57810)

Ray Tune users need to stop using `ray.train.get_context()`,
`ray.train.get_checkpoint()` and `ray.train.report`. This PR improves
the error messages raise if they try to call these instead of the
`ray.tune` counterparts. Note that we've already soft-deprecated this
usage with a warning message for 6+ months.

---------

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
…e functions (#57810)

Ray Tune users need to stop using `ray.train.get_context()`,
`ray.train.get_checkpoint()` and `ray.train.report`. This PR improves
the error messages raise if they try to call these instead of the
`ray.tune` counterparts. Note that we've already soft-deprecated this
usage with a warning message for 6+ months.

---------

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
…e functions (ray-project#57810)

Ray Tune users need to stop using `ray.train.get_context()`,
`ray.train.get_checkpoint()` and `ray.train.report`. This PR improves
the error messages raise if they try to call these instead of the
`ray.tune` counterparts. Note that we've already soft-deprecated this
usage with a warning message for 6+ months.

---------

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
…e functions (ray-project#57810)

Ray Tune users need to stop using `ray.train.get_context()`,
`ray.train.get_checkpoint()` and `ray.train.report`. This PR improves
the error messages raise if they try to call these instead of the
`ray.tune` counterparts. Note that we've already soft-deprecated this
usage with a warning message for 6+ months.

---------

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
…e functions (ray-project#57810)

Ray Tune users need to stop using `ray.train.get_context()`,
`ray.train.get_checkpoint()` and `ray.train.report`. This PR improves
the error messages raise if they try to call these instead of the
`ray.tune` counterparts. Note that we've already soft-deprecated this
usage with a warning message for 6+ months.

---------

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 tune Tune-related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants