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

* refactor(sdk): added option for custom metric collector for tune in… #2406

Closed
wants to merge 13 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions sdk/python/v1beta1/kubeflow/katib/api/katib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def tune(
retain_trials: bool = False,
packages_to_install: List[str] = None,
pip_index_url: str = "https://pypi.org/simple",
metrics_collector_config: Dict[str, Any] = {"kind": "StdOut"},
metrics_collector_config: Dict[str, Any] = {"kind": "StdOut", "custom_collector": None},
):
"""Create HyperParameter Tuning Katib Experiment from the objective function.

Expand Down Expand Up @@ -251,8 +251,8 @@ def tune(
pip_index_url: The PyPI url from which to install Python packages.
metrics_collector_config: Specify the config of metrics collector,
for example, `metrics_collector_config = {"kind": "Push"}`.
Currently, we only support `StdOut` and `Push` metrics collector.
Copy link
Member

Choose a reason for hiding this comment

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

I think we may need to tell users about the supported types of MC. So can you re-add this line?


for using custom metric collectors use "custom_collector" key,
for example, `metrics_collector_config = {"custom_collector": "prometheus"}`.
Copy link
Member

Choose a reason for hiding this comment

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

I guess prometheus is not a custom collector, since we define it here:

PrometheusMetricCollector CollectorKind = "PrometheusMetric"
DefaultPrometheusPath string = "/metrics"
DefaultPrometheusPort int = 8080
CustomCollector CollectorKind = "Custom"

Here are some relevant resources which may be helpful for you:
https://github.com/kubeflow/katib/blob/master/examples/v1beta1/metrics-collector/custom-metrics-collector.yaml

Copy link
Member

Choose a reason for hiding this comment

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

Btw, custom_collector accepts V1Container as its input, not a str:

class V1beta1CollectorSpec(object):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
"""
Attributes:
openapi_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {
'custom_collector': 'V1Container',
'kind': 'str'
}
attribute_map = {
'custom_collector': 'customCollector',
'kind': 'kind'
}

Can you add some comments to remind users of this usage?

Copy link
Member

Choose a reason for hiding this comment

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

Also, can you add some e2e tests like this (an example for StdOut Collector)?

def run_e2e_experiment_create_by_tune(

Copy link
Author

@prakhar479 prakhar479 Aug 15, 2024

Choose a reason for hiding this comment

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

Thanks @Electronic-Waste, I have made the appropriate changes in the function comments to reflect the correct usage

for e2e tests, should I modify the existing run-e2e-tune-api.py test to use metrics_collector_config or should I create a separate test script for it altogether

Copy link
Member

Choose a reason for hiding this comment

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

@prakhar479 I think modifying the existing run-e2e-tune-api.py test is better since it's hard to pass the collector config to the test script: https://github.com/kubeflow/katib/blob/master/test/e2e/v1beta1/scripts/gh-actions/run-e2e-tune-api.sh. WDYT👀 @andreyvelich @tenzen-y @johnugeorge

Also a small tip for reference: you can build images you need here

# Testing image for tune function
if "$TUNE_API"; then
echo -e "\nPulling and building testing image for tune function..."
_build_containers "suggestion-hyperopt" "$CMD_PREFIX/suggestion/hyperopt/$VERSION/Dockerfile"
fi

Copy link
Author

Choose a reason for hiding this comment

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

Thanks @Electronic-Waste for the helpful insights 😄

Raises:
ValueError: Function arguments have incorrect type or value.
TimeoutError: Timeout to create Katib Experiment.
Expand Down Expand Up @@ -387,7 +387,9 @@ def tune(
# Add metrics collector to the Katib Experiment.
# Up to now, We only support parameter `kind`, of which default value is `StdOut`, to specify the kind of metrics collector.
experiment.spec.metrics_collector_spec = models.V1beta1MetricsCollectorSpec(
collector=models.V1beta1CollectorSpec(kind=metrics_collector_config["kind"])
collector=models.V1beta1CollectorSpec(
kind=metrics_collector_config["kind"],
custom_collector=metrics_collector_config["custom_collector"])
)

# Create Trial specification.
Expand Down