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

[GSoC] Add unit tests for tune API #2423

Merged
merged 27 commits into from
Jan 24, 2025

Conversation

helenxie-bit
Copy link
Contributor

@helenxie-bit helenxie-bit commented Sep 5, 2024

What this PR does / why we need it:
This PR adds unit tests for tune API.

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 #

Checklist:

  • Docs included if any changes are user facing

Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
@helenxie-bit
Copy link
Contributor Author

helenxie-bit commented Sep 5, 2024

/area gsoc

@helenxie-bit
Copy link
Contributor Author

Ref: #2339

Signed-off-by: helenxie-bit <[email protected]>
@helenxie-bit helenxie-bit changed the title [GSoC] Add unit tests for tune API [WIP] Add unit tests for tune API Sep 5, 2024
Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thank you for doing this @helenxie-bit!

test/unit/v1beta1/tune-api/test_tune_api.py Outdated Show resolved Hide resolved
Signed-off-by: helenxie-bit <[email protected]>
@google-oss-prow google-oss-prow bot added size/L and removed size/XL labels Sep 9, 2024
Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
@helenxie-bit helenxie-bit changed the title [WIP] Add unit tests for tune API [GSoC] Add unit tests for tune API Sep 11, 2024
@helenxie-bit
Copy link
Contributor Author

@andreyvelich The unit test for tune API is ready. I have also fixed some errors in this PR. Please have a look when you have time. Thanks!

Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

@helenxie-bit
Copy link
Contributor Author

@andreyvelich Thank you so much for reviewing this! I’ve replied to all your feedback, and please take a look when you have time.

Copy link
Member

@Electronic-Waste Electronic-Waste left a comment

Choose a reason for hiding this comment

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

Thanks for your great contribution @helenxie-bit ! I left some suggestions about the name of UTs for your reference

I guess it will be more friendly for other developers to understand these UTs if we could specify the scope of each UTs:)

Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
@helenxie-bit
Copy link
Contributor Author

Thanks for your great contribution @helenxie-bit ! I left some suggestions about the name of UTs for your reference

I guess it will be more friendly for other developers to understand these UTs if we could specify the scope of each UTs:)

@Electronic-Waste Thank you so much for your suggestions! I have incorporated your advice into the UTs.

…ing[huggingface' into dependencies

Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
@helenxie-bit
Copy link
Contributor Author

@andreyvelich I’ve added the kubeflow-training dependency to the unit tests, allowing values and parameters to be fetched from there instead of redefining them within the Katib unit tests. You can find the change here:

kubeflow-training[huggingface]==1.8.1

Additionally, I have added verification for the experiment object in two valid flow cases in the following section:
call_args = mock_create_experiment.call_args
experiment = call_args[0][0]
if test_name == "valid flow with custom objective tuning":
# Verify input_params
args_content = "".join(
experiment.spec.trial_template.trial_spec.spec.template.spec.containers[
0
].args
)
assert "'a': '${trialParameters.a}'" in args_content
# Verify trial_params
assert experiment.spec.trial_template.trial_parameters == [
V1beta1TrialParameterSpec(name="a", reference="a"),
]
# Verify experiment_params
assert experiment.spec.parameters == [
V1beta1ParameterSpec(
name="a",
parameter_type="int",
feasible_space=V1beta1FeasibleSpace(min="10", max="100"),
),
]
elif test_name == "valid flow with external model tuning":
# Verify input_params
args_content = "".join(
experiment.spec.trial_template.trial_spec.spec.pytorch_replica_specs[
"Master"
]
.template.spec.containers[0]
.args
)
assert (
'"learning_rate": "${trialParameters.learning_rate}"'
in args_content
)
# Verify trial_params
assert experiment.spec.trial_template.trial_parameters == [
V1beta1TrialParameterSpec(
name="learning_rate", reference="learning_rate"
),
]
# Verify experiment_params
assert experiment.spec.parameters == [
V1beta1ParameterSpec(
name="learning_rate",
parameter_type="double",
feasible_space=V1beta1FeasibleSpace(
min="1e-05", max="5e-05"
),
),
]

Please review when you have time. Thanks!

@helenxie-bit
Copy link
Contributor Author

@andreyvelich Please review this PR when you have time 👀. I'll adjust the e2e tests for the tune API after this PR is merged, as it fixes some small bugs in the tune API.

@helenxie-bit
Copy link
Contributor Author

Since @mahdikhashan is currently working on the notebook with instructions for this API, and this PR also includes some bug fixes for the API, @andreyvelich, would it be better to separate the bug fixes into a standalone PR to make the review process more convenient? Please let me know your thoughts.

@andreyvelich
Copy link
Member

Since @mahdikhashan is currently working on the notebook with instructions for this API, and this PR also includes some bug fixes for the API, @andreyvelich, would it be better to separate the bug fixes into a standalone PR to make the review process more convenient? Please let me know your thoughts.

Sure, please create separate PR for the bug fixes.

@andreyvelich andreyvelich added this to the v0.18 milestone Jan 20, 2025
Copy link
Member

@Electronic-Waste Electronic-Waste left a comment

Choose a reason for hiding this comment

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

Basically LGTM! I left a few comments concerned with objective_metric_name for you.

Thanks for your great contribution! @helenxie-bit

sdk/python/v1beta1/kubeflow/katib/api/katib_client_test.py Outdated Show resolved Hide resolved
Comment on lines +590 to +609
if test_name == "valid flow with custom objective tuning":
# Verify input_params
args_content = "".join(
experiment.spec.trial_template.trial_spec.spec.template.spec.containers[
0
].args
)
assert "'a': '${trialParameters.a}'" in args_content
# Verify trial_params
assert experiment.spec.trial_template.trial_parameters == [
V1beta1TrialParameterSpec(name="a", reference="a"),
]
# Verify experiment_params
assert experiment.spec.parameters == [
V1beta1ParameterSpec(
name="a",
parameter_type="int",
feasible_space=V1beta1FeasibleSpace(min="10", max="100"),
),
]
Copy link
Member

Choose a reason for hiding this comment

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

It would be better if we also verify the objective_metric_name parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your suggestions! I will add that.

Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
Signed-off-by: helenxie-bit <[email protected]>
@helenxie-bit
Copy link
Contributor Author

/rerun-all

@helenxie-bit
Copy link
Contributor Author

@andreyvelich @Electronic-Waste This PR is ready for review. But I'm not sure why the ci test Publusi Katib Core images/Publish Image (katib-ui, cmd/ui/v1beta1/Dockerfile) kept failing due to network connectivity issue. Do you have any ideas?

Copy link
Member

@Electronic-Waste Electronic-Waste left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your great contribution! As for the CI error, it occurred occasionally. You could rerun it after a while:)

/lgtm
/rerun-all

@google-oss-prow google-oss-prow bot added the lgtm label Jan 24, 2025
Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thank you for this great contribution @helenxie-bit!
/lgtm
/approve

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andreyvelich, Electronic-Waste

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit 40e1e65 into kubeflow:master Jan 24, 2025
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants