Fix nested dictionary merge in SearchThread losing sampled hyperparameters#1494
Merged
Conversation
Co-authored-by: thinkall <3197038+thinkall@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix KeyError in config parameter handling
Fix nested dictionary merge in SearchThread losing sampled hyperparameters
Jan 20, 2026
thinkall
approved these changes
Jan 20, 2026
jianglibigdata
approved these changes
Jan 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
SearchThread.suggest()method usesdict.update()to merge constant config values with sampled hyperparameters. This fails for nested configurations (e.g., XGBoost'sparamsdict) becauseupdate()replaces entire nested dictionaries rather than merging them.Example of the bug:
Changes:
_recursive_dict_update()helper that recursively merges nested dictsconfig.update(self._const)with_recursive_dict_update(config, self._const)in line 93After fix:
Original prompt
This section details on the original issue you should resolve
<issue_title>[BUG] KeyError: 'params/eta'</issue_title>
<issue_description>## Bug details
I am running HPO for XGBoost with Ray and Bendsearch.
At flaml/tune/searcher/search_thread.py#L66, in my case, the
configis{ 'num_boost_round': 10, 'params': {'max_depth': 12, 'eta': 0.020168455186106736, 'min_child_weight': 1.4504723523894132, 'scale_pos_weight': 3.794258636185337, 'gamma': 0.4985070123025904} }and the
self._constis{ 'params': {'verbosity': 3, 'booster': 'gbtree', 'eval_metric': 'auc', 'tree_method': 'hist', 'objective': 'binary:logistic'} }after update step, I will get
{ 'num_boost_round': 10, 'params': {'verbosity': 3, 'booster': 'gbtree', 'eval_metric': 'auc', 'tree_method': 'hist', 'objective': 'binary:logistic'} }Values in
config['params']sampled from search space are all dropped.How to solve
I solved it by recursively update
config. Here is an example:Then just replace
config.update(self._const)withrecursive_update(config, self._const), then i can get:{ 'num_boost_round': 10, 'params': {'max_depth': 12, 'eta': 0.020168455186106736, 'min_child_weight': 1.4504723523894132, 'scale_pos_weight': 3.794258636185337, 'gamma': 0.4985070123025904, 'verbosity': 3, 'booster': 'gbtree', 'eval_metric': 'auc', 'tree_method': 'hist', 'objective': 'binary:logistic'} }My Traceback
</issue_description>
<agent_instructions>Run
pre-commit run --all-filesbefore commit your changes to avoid format issues.</agent_instructions>Comments on the Issue (you are @copilot in this section)
@thinkall > One way I worked around this bug is to ensure that `space`/`param_space` only contains hyperparameters defined with tune search space and remove any constants. I am using Ray Train TorchTrainer, so I moved the constants there instead. > > If you...KeyError: 'params/eta'#1246✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.