Skip to content

Commit

Permalink
add verification for objective metric name
Browse files Browse the repository at this point in the history
Signed-off-by: helenxie-bit <[email protected]>
  • Loading branch information
helenxie-bit committed Jan 23, 2025
1 parent b24b44f commit 5dfd1a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sdk/python/v1beta1/kubeflow/katib/api/katib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class name in this argument.

# If users choose to use a custom objective function.
if objective is not None or parameters is not None:
if objective is None or base_image is None or parameters is None:
if not objective or not parameters:
raise ValueError("One of the required parameters is None")

# Add metrics collector to the Katib Experiment.
Expand Down
17 changes: 16 additions & 1 deletion sdk/python/v1beta1/kubeflow/katib/api/katib_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,9 @@ def create_experiment(
"valid flow with custom objective tuning",
{
"name": "tune_test",
"objective": lambda x: x,
"objective": lambda x: print(f"a={x}"),
"parameters": {"a": katib.search.int(min=10, max=100)},
"objective_metric_name": "a",
},
TEST_RESULT_SUCCESS,
),
Expand All @@ -500,6 +501,8 @@ def create_experiment(
learning_rate=katib.search.double(min=1e-05, max=5e-05),
),
),
"objective_metric_name": "train_loss",
"objective_type": "minimize",
},
TEST_RESULT_SUCCESS,
),
Expand Down Expand Up @@ -607,6 +610,12 @@ def test_tune(katib_client, test_name, kwargs, expected_output):
feasible_space=V1beta1FeasibleSpace(min="10", max="100"),
),
]
# Verify objective_spec
assert experiment.spec.objective == V1beta1ObjectiveSpec(
type="maximize",
objective_metric_name="a",
additional_metric_names=[],
)

elif test_name == "valid flow with external model tuning":
# Verify input_params
Expand Down Expand Up @@ -637,6 +646,12 @@ def test_tune(katib_client, test_name, kwargs, expected_output):
),
),
]
# Verify objective_spec
assert experiment.spec.objective == V1beta1ObjectiveSpec(
type="minimize",
objective_metric_name="train_loss",
additional_metric_names=[],
)

except Exception as e:
assert type(e) is expected_output
Expand Down

0 comments on commit 5dfd1a3

Please sign in to comment.