Add "best_trial": best_trial.number to results_to_serialize in _impl.py #3081
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Adding the
best_trial_numberto the finaloptimization_results.yamlfile provides several key benefits for analysis, debugging, and automation.Traceability and Debugging
The trial number serves as a unique identifier that directly links the summary results to the specific, detailed logs for that single run. Hydra saves each trial's output (like logs, model checkpoints, and plots) in a numbered subdirectory. Knowing the
best_trial_numbertells you exactly which folder to inspect to reproduce or debug the best-performing run without having to manually search for it.Analysis of the Optimization Process
Knowing when the best result occurred during the hyperparameter search offers valuable insights:
Simplified Post-Processing
For automated workflows, having a direct identifier is crucial. A script can parse the results file, grab the
best_trial_number, and use it to reliably retrieve the correct model artifact from the corresponding trial directory for deployment, further evaluation, or archiving. This makes the entire MLOps pipeline more robust and less complex.Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
(How should this PR be tested? Do you require special setup to run the test or repro the fixed bug?)
No. All you need is to run an experiment and check if the
best_trial_numberis added to theoptimization_results.yaml. If this is, then that is exactly the purpose of this PR.Related Issues and PRs
(Is this PR part of a group of changes? Link the other relevant PRs and Issues here. Use https://help.github.com/en/articles/closing-issues-using-keywords for help on GitHub syntax)
No.