Skip to content

[Tune] Fix Tune search for python 3.14#63575

Merged
matthewdeng merged 2 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:fix-tune-search-3.14
May 22, 2026
Merged

[Tune] Fix Tune search for python 3.14#63575
matthewdeng merged 2 commits into
ray-project:masterfrom
pseudo-rnd-thoughts:fix-tune-search-3.14

Conversation

@pseudo-rnd-thoughts

@pseudo-rnd-thoughts pseudo-rnd-thoughts commented May 21, 2026

Copy link
Copy Markdown
Member

Description

In updating the release tests to check Python 3.14, I found

Traceback (most recent call last):
--
  | File "/tmp/ray/session_2026-05-21_07-44-59_419182_2769/runtime_resources/working_dir_files/s3_ray-release-automation-results_working_dirs_tune_scalability_bookkeeping_overhead_aws_pwtghglleu__anyscale_pkg_5362fa14e94acaf695fd9b81bc1cfc3c/workloads/test_bookkeeping_overhead.py", line 43, in <module>
  | main()
  | ~~~~^^
  | File "/tmp/ray/session_2026-05-21_07-44-59_419182_2769/runtime_resources/working_dir_files/s3_ray-release-automation-results_working_dirs_tune_scalability_bookkeeping_overhead_aws_pwtghglleu__anyscale_pkg_5362fa14e94acaf695fd9b81bc1cfc3c/workloads/test_bookkeeping_overhead.py", line 33, in main
  | timed_tune_run(
  | ~~~~~~~~~~~~~~^
  | name="bookkeeping overhead",
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | ...<3 lines>...
  | max_runtime=max_runtime,
  | ^^^^^^^^^^^^^^^^^^^^^^^^
  | )
  | ^
  | File "/home/ray/anaconda3/lib/python3.14/site-packages/ray/tune/utils/release_test_util.py", line 153, in timed_tune_run
  | analysis = tune.run(
  | _train,
  | ...<3 lines>...
  | **run_kwargs,
  | )
  | File "/home/ray/anaconda3/lib/python3.14/site-packages/ray/tune/tune.py", line 986, in run
  | runner.step()
  | ~~~~~~~~~~~^^
  | File "/home/ray/anaconda3/lib/python3.14/site-packages/ray/tune/execution/tune_controller.py", line 701, in step
  | raise e
  | File "/home/ray/anaconda3/lib/python3.14/site-packages/ray/tune/execution/tune_controller.py", line 698, in step
  | self.checkpoint()
  | ~~~~~~~~~~~~~~~^^
  | File "/home/ray/anaconda3/lib/python3.14/site-packages/ray/tune/execution/tune_controller.py", line 352, in checkpoint
  | self._checkpoint_manager.sync_up_experiment_state(
  | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
  | save_fn=self.save_to_dir, force=force, wait=wait
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | )
  | ^
  | File "/home/ray/anaconda3/lib/python3.14/site-packages/ray/tune/execution/experiment_state.py", line 167, in sync_up_experiment_state
  | save_fn()
  | ~~~~~~~^^
  | File "/home/ray/anaconda3/lib/python3.14/site-packages/ray/tune/execution/tune_controller.py", line 348, in save_to_dir
  | self._search_alg.save_to_dir(driver_staging_path, session_str=self._session_str)
  | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | File "/home/ray/anaconda3/lib/python3.14/site-packages/ray/tune/search/basic_variant.py", line 406, in save_to_dir
  | _atomic_save(
  | ~~~~~~~~~~~~^
  | state=state_dict,
  | ^^^^^^^^^^^^^^^^^
  | ...<2 lines>...
  | tmp_file_name=f"tmp-{file_name}",
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | )
  | ^
  | File "/home/ray/anaconda3/lib/python3.14/site-packages/ray/tune/utils/util.py", line 416, in _atomic_save
  | cloudpickle.dump(state, f)
  | ~~~~~~~~~~~~~~~~^^^^^^^^^^
  | File "/home/ray/anaconda3/lib/python3.14/site-packages/ray/cloudpickle/cloudpickle.py", line 1526, in dump
  | Pickler(file, protocol=protocol, buffer_callback=buffer_callback).dump(obj)
  | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  | File "/home/ray/anaconda3/lib/python3.14/site-packages/ray/cloudpickle/cloudpickle.py", line 1313, in dump
  | return super().dump(obj)
  | ~~~~~~~~~~~~^^^^^
  | TypeError: cannot pickle 'itertools.chain' object
  | when serializing dict item '_trial_iter'
  | Subprocess return code: 1

Reviewing python 3.14 release notes, https://docs.python.org/3/whatsnew/3.14.html#itertools, pickle support has been explicitly removed from all itertool functions.
To resolve this problem, we can just lazily evaluate _trial_iter as it is updated in next_trial based on _trial_generator

Related

#63270

Signed-off-by: Mark Towers <mark@anyscale.com>
@pseudo-rnd-thoughts pseudo-rnd-thoughts requested a review from a team as a code owner May 21, 2026 16:08
@pseudo-rnd-thoughts pseudo-rnd-thoughts added tune Tune-related issues go add ONLY when ready to merge, run all tests labels May 21, 2026

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

Copy link
Copy Markdown
Contributor

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 updates the state serialization and restoration logic in python/ray/tune/search/basic_variant.py by excluding _trial_iter from the saved state and resetting it to None in set_state. Feedback was provided regarding set_state, suggesting that _trial_generator should be explicitly cleared before reconstructing the iterator chain to avoid redundant trials and deep nesting of itertools.chain objects when an object is reused.

Comment thread python/ray/tune/search/basic_variant.py

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 438c278. Configure here.

Comment thread python/ray/tune/search/basic_variant.py
Signed-off-by: Mark Towers <mark@anyscale.com>

@TimothySeah TimothySeah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, also ran the release test on this PR.

@matthewdeng matthewdeng merged commit 722a600 into ray-project:master May 22, 2026
6 checks passed
Neelansh-Khare pushed a commit to Neelansh-Khare/ray-clone that referenced this pull request Jun 5, 2026
Signed-off-by: Neelansh Khare <kharen@uci.edu>
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.

3 participants