Repository navigation
[tune] Stop Repeater raising KeyError on unknown trial IDs - #65952
akashjainn wants to merge 1 commit into
Conversation
Repeater.on_trial_complete logs "cannot report score" when a trial is missing from _trial_id_to_group, then falls through and indexes that same mapping, raising KeyError and aborting the experiment. On resume, Tune can restore a trial that was suggested after the last search algorithm checkpoint was written, so the restored mapping does not contain that trial. Return after the log so the trial is skipped, which is what the log message already claims happens. Closes ray-project#11918 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01QtvvymoPBWrpb7JZQ4zEBc Signed-off-by: akashjainn <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request prevents a KeyError in Repeater.on_trial_complete when a trial is not found in the _trial_id_to_group mapping by adding an early return statement. It also introduces a corresponding unit test, test_repeater_ignores_unknown_trial, to verify this behavior. There are no review comments, and I have no additional feedback to provide.
|
Closing this — I could not substantiate the impact claim in the description, and I would rather withdraw it than spend reviewer time on it. What I got wrong: the description asserts that Tune checkpoints trial state and search algorithm state on separate cadences, leaving a window where a resumed trial is missing from the restored What I found when I did verify it, on 2.58 with
Restored trials do not report back through the search algorithm on resume, so The one-line change is still defensible on its own terms: the branch logs Separately, and more usefully: #11918 looks stale. The 2020 traceback does not reproduce on current Ray, and the fix appears to have come from changes elsewhere in the resume path rather than in Apologies for the noise. |
Why are these changes needed?
Repeater.on_trial_completeguards against a trial that is missing from its_trial_id_to_groupmapping, logs"Trial {} not in group; cannot report score",and then immediately indexes that same mapping anyway:
The log message says the score cannot be reported, but there is no
return, sothe next line raises
KeyErrorand the exception propagates up throughSearchGenerator.on_trial_completeinto_process_trial, taking down the wholeexperiment rather than skipping the one trial.
This is reachable on resume. Tune checkpoints the search algorithm and the trial
state on separate cadences, so a trial suggested after the last search algorithm
checkpoint is still restored from the trial state while being absent from the
restored
_trial_id_to_group. When it completes,Repeaterhas never seen theID. That matches the original report, where resume fails when the last trial
before the interruption was incomplete.
This change adds the missing
returnso the trial is skipped, which is thebehavior the existing log message already describes. The group bookkeeping for
trials the
Repeaterdoes know about is unchanged.Worth noting for reviewers: the 2020 comment on the issue suggested the cause was
that
save/restorewere not implemented forRepeater. That is no longer thecase.
SearchGenerator.save_to_dir/restore_from_dirwalk the wrapper chainand call
get_state()/set_state()on each wrapper, soRepeaterstate ischeckpointed today. What remains is only the missing early return on the
unknown-trial path.
Related issue number
Closes #11918
Not a duplicate
gh pr list --repo ray-project/ray --state open --search "11918 in:body"→ no resultsgh pr list --repo ray-project/ray --state all --search "repeater in:title"→ no resultsChecks
Environment: Python 3.11.16,
ray[tune]2.58.0 in a venv, withpython/ray/tunesymlinked to this branch via
python/ray/setup-dev.py -y --allow tune.Added
test_repeater_ignores_unknown_trial, which reproduces the reportedfailure. Before the fix it fails with the same signature as the issue report:
After the fix:
Lint:
Commit is DCO signed off.
AI assistance
Per
AGENTS.md: AI assistance (Claude Code) was used for this change. Thediagnosis, the fix, and the regression test were reviewed and the tests were run
locally as shown above before opening this PR.
🤖 Generated with Claude Code
https://claude.ai/code/session_01QtvvymoPBWrpb7JZQ4zEBc