Skip to content

Commit

Permalink
fixed validation logic for min and max
Browse files Browse the repository at this point in the history
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
  • Loading branch information
shashank-iitbhu committed Oct 4, 2024
1 parent 5198ad1 commit 262912d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
17 changes: 13 additions & 4 deletions examples/v1beta1/hp-tuning/hyperopt-distribution.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,25 @@ spec:
min: "0.01"
max: "0.05"
step: "0.01"
distribution: "normal"
distribution: normal
- name: momentum
parameterType: double
feasibleSpace:
min: "0.001"
max: "1"
distribution: "uniform"
distribution: uniform
- name: epochs
parameterType: int
feasibleSpace:
min: "1"
max: "3"
distribution: logUniform
- name: batch_size
parameterType: int
feasibleSpace:
min: "32"
max: "64"
distribution: "logNormal"
distribution: logNormal
trialTemplate:
primaryContainerName: training-container
trialParameters:
Expand All @@ -43,6 +49,9 @@ spec:
- name: momentum
description: Momentum for the training model
reference: momentum
- name: epochs
description: Epochs
reference: epochs
- name: batchSize
description: Batch Size
reference: batch_size
Expand All @@ -58,7 +67,7 @@ spec:
command:
- "python3"
- "/opt/pytorch-mnist/mnist.py"
- "--epochs=1"
- "--epochs=${trialParameters.epochs}"
- "--batch-size=${trialParameters.batchSize}"
- "--lr=${trialParameters.learningRate}"
- "--momentum=${trialParameters.momentum}"
Expand Down
24 changes: 8 additions & 16 deletions pkg/suggestion/v1beta1/hyperopt/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,9 @@ def create_hyperopt_domain(self):
math.log(float(param.max)),
)
elif param.distribution == api_pb2.NORMAL:
if param.min == "" or param.max == "":
mu = 0
sigma = 1
else:
mu = (float(param.min) + float(param.max)) / 2
# We consider the normal distribution based on the range of ±3 sigma.
sigma = (float(param.max) - float(param.min)) / 6
mu = (float(param.min) + float(param.max)) / 2
# We consider the normal distribution based on the range of ±3 sigma.
sigma = (float(param.max) - float(param.min)) / 6

if param.step:
hyperopt_search_space[param.name] = hyperopt.hp.qnormal(
Expand All @@ -119,15 +115,11 @@ def create_hyperopt_domain(self):
sigma,
)
elif param.distribution == api_pb2.LOG_NORMAL:
if param.min == "" or param.max == "":
mu = 0
sigma = 1
else:
log_min = math.log(float(param.min))
log_max = math.log(float(param.max))
mu = (log_min + log_max) / 2
# We consider the normal distribution based on the range of ±3 sigma.
sigma = (log_max - log_min) / 6
log_min = math.log(float(param.min))
log_max = math.log(float(param.max))
mu = (log_min + log_max) / 2
# We consider the normal distribution based on the range of ±3 sigma.
sigma = (log_max - log_min) / 6

if param.step:
hyperopt_search_space[param.name] = hyperopt.hp.qlognormal(
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/v1beta1/experiment/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (g *DefaultValidator) validateParameters(parameters []experimentsv1beta1.Pa
allErrs = append(allErrs, field.Invalid(parametersPath.Index(i).Child("feasibleSpace").Child("list"),
param.FeasibleSpace.List, fmt.Sprintf("feasibleSpace.list is not supported for parameterType: %v", param.ParameterType)))
}
if param.FeasibleSpace.Max == "" && param.FeasibleSpace.Min == "" {
if param.FeasibleSpace.Max == "" || param.FeasibleSpace.Min == "" {
allErrs = append(allErrs, field.Required(parametersPath.Index(i).Child("feasibleSpace").Child("max"),
fmt.Sprintf("feasibleSpace.max or feasibleSpace.min must be specified for parameterType: %v", param.ParameterType)))
}
Expand Down

0 comments on commit 262912d

Please sign in to comment.