Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: grid hp samping ignored empty nests #9966

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/release-notes/9966-fix-grid.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:orphan:

**Fixes**

- Previously, during a grid search, if a hyperparameter contained an empty nested hyperparameter
(that is, just an empty map), that hyperparameter would not appear in the hparams passed to the
trial.
7 changes: 6 additions & 1 deletion master/pkg/searcher/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,13 @@ func getGridAxes(route []string, h expconf.Hyperparameter) []gridAxis {
return []gridAxis{axis}
case h.RawNestedHyperparameter != nil:
axes := []gridAxis{}
// Use h.Each for deterministic ordering.
nested := expconf.Hyperparameters(*h.RawNestedHyperparameter)
// Make sure empty maps don't disappear after sampling.
if len(nested) == 0 {
axes = append(axes, gridAxis{axisValue{route, map[string]interface{}{}}})
return axes
}
// Use h.Each for deterministic ordering.
nested.Each(func(name string, subparam expconf.HyperparameterV0) {
// make a completely clean copy of route
var subroute []string
Expand Down
14 changes: 14 additions & 0 deletions master/pkg/searcher/grid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ func TestHyperparameterGridMethod(t *testing.T) {
len(getGridAxes([]string{"x"}, expconf.Hyperparameter{RawConstHyperparameter: &constParam})[0]),
1,
)
// Regression test: make sure empty nested hyperparameters don't disappear during sampling.
Copy link
Contributor

Choose a reason for hiding this comment

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

🤘

nestedParam := map[string]expconf.Hyperparameter{
"empty": {RawNestedHyperparameter: &map[string]expconf.Hyperparameter{}},
"full": {RawCategoricalHyperparameter: &catParam},
}
result := getGridAxes([]string{"x"}, expconf.Hyperparameter{RawNestedHyperparameter: &nestedParam})
assert.DeepEqual(t, result, []gridAxis{
[]axisValue{{Route: []string{"x", "empty"}, Value: map[string]interface{}{}}},
[]axisValue{
{Route: []string{"x", "full"}, Value: 1},
{Route: []string{"x", "full"}, Value: 2},
{Route: []string{"x", "full"}, Value: 3},
},
})
}

func TestGrid(t *testing.T) {
Expand Down
Loading