-
Notifications
You must be signed in to change notification settings - Fork 460
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
Add Goptuna based suggestion service for CMA-ES. #1131
Conversation
Hi @c-bata. Thanks for your PR. I'm waiting for a kubeflow member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
This comment has been minimized.
This comment has been minimized.
/ok-to-test |
Thank you, this is great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good and easy to read! I left few comments
@@ -0,0 +1,129 @@ | |||
package suggestion_goptuna_v1alpha3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to add service to /goptuna
folder or follow current design, when service is located under /suggestion/v1alpha3
folder?
I am not sure what is the best way to store Algorithms which is written in GO.
What do you think @gaocegege @johnugeorge ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Go, basically we can't put multiple packages in the same directory (except for *_test
package). So I think we need to put this service into /goptuna
folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
Thank you for the changes, overall /lgtm. I think, we can add yaml example, CI Tests, update /assign @johnugeorge @gaocegege Thank you for implementing this! |
/lgtm |
func isSameTrialParam(ktrial, gtrial goptuna.FrozenTrial) bool { | ||
// Compare trial parameters by "internal representation". | ||
// In the internal representation, all parameters are represented by `float64` to store the storage | ||
// (because Goptuna supports not only in-memory but also RDB storage backend). | ||
// To represent categorical parameters, Goptuna holds an index of the list in the database. | ||
// | ||
// SearchSpace: map[string]interface{}{"x1": Uniform{Min: -10, Max: 10}, "x2": Categorical{Choices: []string{"param-1", "param-2"}}} | ||
// External representation: map[string]interface{}{"x1": 5.5, "x2": "param-2"} | ||
// Internal representation: map[string]float64{"x1": 5.5, "x2": 1.0} | ||
for name := range gtrial.InternalParams { | ||
gtrialParamValue := gtrial.InternalParams[name] | ||
ktrialParamValue, ok := ktrial.InternalParams[name] | ||
if !ok { | ||
// must not reach here | ||
klog.Errorf("Detect inconsistent internal parameters: %v and %v", | ||
ktrial.InternalParams, gtrial.InternalParams) | ||
return false | ||
} | ||
if gtrialParamValue != ktrialParamValue { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this logic seems to be broken.
In Goptuna, the internal representation is not necessarily reproducible from external representation because of the following reason:
optuna/optuna#925
So we need to compare external representations because ktrial
is created from Katib parameter assignments which store external representation. I'll fix this soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is enough to use reflect.DeepEqual(gtrial.Params, ktrial.Params
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this at 8c21693 and tested on the following parameter settings:
# https://github.com/c-bata/katib-goptuna-example/blob/master/experiment-step.yaml
parameters:
- name: x1
parameterType: int
feasibleSpace:
min: "-15"
max: "15"
step: "2"
- name: x2
parameterType: double
feasibleSpace:
min: "-10"
max: "10"
step: 0.5
It works fine!
>>> logs -f example-step3-cmaes-54b4886448-cgkdm
I0414 06:22:33.668875 1 main.go:36] Start Goptuna suggestion service: 0.0.0.0:6789
I0414 06:22:47.179106 1 service.go:67] Success to sample new trial: trialID=0, assignments=[name:"x1" value:"3" name:"x2" value:"1.5" ]
I0414 06:22:47.182047 1 service.go:67] Success to sample new trial: trialID=1, assignments=[name:"x1" value:"5" name:"x2" value:"-1" ]
I0414 06:22:53.962858 1 service.go:100] Update trial mapping : trialName=example-step3-lvmdgldl -> trialID=1
I0414 06:22:53.962882 1 service.go:100] Update trial mapping : trialName=example-step3-458v8s2c -> trialID=0
I0414 06:22:53.962888 1 service.go:130] Detect changes of Trial (trialName=example-step3-458v8s2c, trialID=0) : State Complete, Evaluation 46.250000
I0414 06:22:53.962988 1 service.go:67] Success to sample new trial: trialID=2, assignments=[name:"x2" value:"0.5" name:"x1" value:"-3" ]
I0414 06:22:56.158324 1 service.go:100] Update trial mapping : trialName=example-step3-mrxdqpq9 -> trialID=2
I0414 06:22:56.158345 1 service.go:130] Detect changes of Trial (trialName=example-step3-lvmdgldl, trialID=1) : State Complete, Evaluation 16.000000
I0414 06:22:56.158473 1 service.go:67] Success to sample new trial: trialID=3, assignments=[name:"x1" value:"-7" name:"x2" value:"1" ]
I0414 06:22:59.670946 1 service.go:130] Detect changes of Trial (trialName=example-step3-mrxdqpq9, trialID=2) : State Complete, Evaluation 94.250000
I0414 06:22:59.670984 1 service.go:100] Update trial mapping : trialName=example-step3-z9p7rklk -> trialID=3
I0414 06:22:59.671069 1 service.go:67] Success to sample new trial: trialID=4, assignments=[name:"x1" value:"-1" name:"x2" value:"-1" ]
PTAL.
} | ||
} | ||
return nil, cmaes.NewSampler(opts...), nil | ||
} else if name == AlgorithmTPE { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we will have two suggestion providers which support TPE, do you think we should keep a prefix for it? Maybe gotuna-tpe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, we can name it goptuna-tpe and goptuna-random.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little bit concerned about the consistency of naming. It might be enough just updating katib-config
if we want to use Goptuna suggestion service.
:
suggestion: |-
{
"random": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-goptuna"
},
"tpe": {
"imagePullPolicy": "Always",
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-goptuna"
},
"cmaes": {
"imagePullPolicy": "Always",
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-goptuna"
},
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @c-bata .If we add prefix, user will be confused. User is not concerned about the internal implementation. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we should update doc which implementation we currently support for which algorithm.
E.g random: hyperopt, chocolate, goptuna.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM
Thanks for your contribution! 🎉 👍
It is huge contribution.
I think it is ready to merge, right @c-bata ? |
Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge it, I will create an issue for remaining work.
Thanks again @c-bata!
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andreyvelich The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* Add goptuna dependencies * Implement Goptuna based suggestion service * Add test cases * Validate duplicated parameters * Add test cases * Support step argument * Update vendor files * Support step argument for INT * Use new suggest APIs * Add refactor changes * Apply review feedbacks * Update vendor files * Apply review feedbacks * Fix tests * Add some refactor changes and add code comments * Fix tests * Refactor blank lines of import statements * Provide more algorithm settings * Create goptuna study and search space at first get suggestoins request * Compare trial parameters exactly * Fix isSameTrialParam() and refactor logging
What this PR does / why we need it:
Add CMA-ES suggestion service using Goptuna.
I tested this suggestion service with the following experiment:
https://github.com/c-bata/katib-goptuna-example
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #1100
Special notes for your reviewer:
katib-config
, you can optimize your objective function with Goptuna TPE and Goptuna Random.katib-config
. See Add Goptuna based suggestion service for CMA-ES. #1131 (comment)Release note: