-
Notifications
You must be signed in to change notification settings - Fork 448
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 validation for NAS job in Katib controller #398
Changes from 6 commits
9f9a99a
0b171ab
46221b2
d407be8
c5c284f
14cc8be
36958e0
76f8397
c3e54cb
345d66b
e45216e
3dc4f3e
4b47650
3a7e0b0
c16690e
30e876e
38febad
8a01094
ea896ae
b88030b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,25 @@ import ( | |
) | ||
|
||
func initializeStudy(instance *katibv1alpha1.StudyJob) error { | ||
if validErr := validateStudy(instance); validErr != nil { | ||
instance.Status.Condition = katibv1alpha1.ConditionFailed | ||
return validErr | ||
} | ||
|
||
if getJobType(instance) != jobTypeNAS { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use suggestionSpec.suggestionAlgorithm to return jobTypeNAS or jobTypeHP in getJobType to handle the invalid studyjob case: .Spec.NasConfig is not nil and suggestionSpec.suggestionAlgorithm is not nas-like |
||
//Validate HP job | ||
if validJobErr := validateHPJob(instance); validJobErr != nil { | ||
instance.Status.Condition = katibv1alpha1.ConditionFailed | ||
return validJobErr | ||
} | ||
} else { | ||
//Validate NAS job | ||
if validJobErr := validateNASJob(instance); validJobErr != nil { | ||
instance.Status.Condition = katibv1alpha1.ConditionFailed | ||
return validJobErr | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move validateHPJob and validateNASJob into validateStudy, and move validateStudy away from initializeStudy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You want to put validateStudy function before initializeStudy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, validateStudy has been moved to https://github.com/kubeflow/katib/blob/master/pkg/controller/studyjob/validating_webhook.go#L44 |
||
if instance.Spec.SuggestionSpec.SuggestionAlgorithm == "" { | ||
instance.Spec.SuggestionSpec.SuggestionAlgorithm = "random" | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"reflect" | ||
"strings" | ||
|
||
katibapi "github.com/kubeflow/katib/pkg/api" | ||
|
@@ -206,6 +207,91 @@ func contains(l []string, s string) bool { | |
return false | ||
} | ||
|
||
func validateHPJob(instance *katibv1alpha1.StudyJob) error { | ||
log.Printf("Validation for the HP job") | ||
if instance.Spec.ParameterConfigs == nil { | ||
return fmt.Errorf("No Spec.ParameterConfigs specified") | ||
} | ||
err := validateParameterConfigs(instance.Spec.ParameterConfigs, jobTypeHP, instance.Spec.SuggestionSpec.SuggestionAlgorithm) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
func validateNASJob(instance *katibv1alpha1.StudyJob) error { | ||
log.Printf("Validation for the NAS job") | ||
if instance.Spec.NasConfig == nil { | ||
return fmt.Errorf("No Spec.NasConfig specified") | ||
} | ||
|
||
if reflect.DeepEqual(instance.Spec.NasConfig.GraphConfig, katibv1alpha1.GraphConfig{}) { | ||
return fmt.Errorf("Missing GraphConfig in NasConfig: %v", instance.Spec.NasConfig) | ||
} | ||
|
||
if instance.Spec.NasConfig.GraphConfig.InputSize == nil { | ||
return fmt.Errorf("Missing InputSize in NasConfig.GraphConfig: %v", instance.Spec.NasConfig.GraphConfig) | ||
} | ||
|
||
if instance.Spec.NasConfig.GraphConfig.OutputSize == nil { | ||
return fmt.Errorf("Missing OutputSize in NasConfig.GraphConfig: %v", instance.Spec.NasConfig.GraphConfig) | ||
} | ||
|
||
if instance.Spec.NasConfig.GraphConfig.NumLayers == 0 && instance.Spec.SuggestionSpec.SuggestionAlgorithm == suggestionAlgorithmRL { | ||
return fmt.Errorf("Missing NumLayers in NasConfig.GraphConfig: %v", instance.Spec.NasConfig.GraphConfig) | ||
} | ||
|
||
if instance.Spec.NasConfig.Operations == nil { | ||
return fmt.Errorf("Missing Operations in NasConfig: %v", instance.Spec.NasConfig) | ||
} | ||
|
||
for _, op := range instance.Spec.NasConfig.Operations { | ||
if op.OperationType == "" { | ||
return fmt.Errorf("Missing OperationType in Operation: %v", op) | ||
} | ||
if op.ParameterConfigs == nil { | ||
return fmt.Errorf("Missing ParameterConfig in Operation: %v", op) | ||
} | ||
err := validateParameterConfigs(op.ParameterConfigs, jobTypeNAS, instance.Spec.SuggestionSpec.SuggestionAlgorithm) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func validateParameterConfigs(parameterConfigs []katibv1alpha1.ParameterConfig, jobType string, suggestionAlgorithm string) error { | ||
for _, pc := range parameterConfigs { | ||
if pc.Name == "" { | ||
return fmt.Errorf("Missing Name in ParameterConfig: %v", pc) | ||
} | ||
if pc.ParameterType == "" { | ||
return fmt.Errorf("Missing ParameterType in ParameterConfig: %v", pc) | ||
} | ||
if reflect.DeepEqual(pc.Feasible, katibv1alpha1.FeasibleSpace{}) { | ||
return fmt.Errorf("Missing Feasible in ParameterConfig: %v", pc) | ||
} | ||
if pc.ParameterType == katibv1alpha1.ParameterTypeCategorical { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not only categorical but discrete. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In discrete we also use only List structure or something else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently discrete only need List. But we may need more type for discretes, int or double. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
if pc.Feasible.List == nil { | ||
return fmt.Errorf("Missing List in ParameterConfig.Feasible: %v", pc.Feasible) | ||
} | ||
} | ||
if pc.ParameterType == katibv1alpha1.ParameterTypeDouble || pc.ParameterType == katibv1alpha1.ParameterTypeInt { | ||
if pc.Feasible.Min == "" { | ||
return fmt.Errorf("Missing Min in ParameterConfig.Feasible: %v", pc.Feasible) | ||
} | ||
if pc.Feasible.Max == "" { | ||
return fmt.Errorf("Missing Max in ParameterConfig.Feasible: %v", pc.Feasible) | ||
} | ||
if jobType == jobTypeNAS && pc.Feasible.Step == "" && pc.ParameterType == katibv1alpha1.ParameterTypeDouble && suggestionAlgorithm == suggestionAlgorithmRL { | ||
return fmt.Errorf("Missing Step in ParameterConfig.Feasible for NAS job: %v", pc.Feasible) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. define a suggestionNASList (now only nasrl is in) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Better way to handle this? |
||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func getMyNamespace() string { | ||
data, _ := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") | ||
return strings.TrimSpace(string(data)) | ||
|
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.
s/suggestionAlgorithmRL/suggestionNASRL