Skip to content

Commit 5267a91

Browse files
Rename trial_timeout to trial_active_deadline_seconds
- Updated parameter name in function signatures and documentation - Updated test cases and assertions to use new parameter name - Fixed line length issues to meet linting requirements - Maintains backward compatibility with Kubernetes activeDeadlineSeconds field
1 parent f5ff598 commit 5267a91

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

sdk/python/v1beta1/kubeflow/katib/api/katib_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def tune(
216216
packages_to_install: List[str] = None,
217217
pip_index_url: str = "https://pypi.org/simple",
218218
metrics_collector_config: Dict[str, Any] = {"kind": "StdOut"},
219-
trial_timeout: Optional[int] = None,
219+
trial_active_deadline_seconds: Optional[int] = None,
220220
):
221221
"""
222222
Create HyperParameter Tuning Katib Experiment using one of the following
@@ -356,7 +356,8 @@ class name in this argument.
356356
metrics_collector_config: Specify the config of metrics collector,
357357
for example, `metrics_collector_config = {"kind": "Push"}`.
358358
Currently, we only support `StdOut` and `Push` metrics collector.
359-
trial_timeout: Optional timeout in seconds for each trial. If None, no timeout is
359+
trial_active_deadline_seconds: Optional timeout in seconds for each trial.
360+
If None, no timeout is
360361
applied. For Job-based trials, this sets the activeDeadlineSeconds field.
361362
For PyTorchJob-based trials, this sets the activeDeadlineSeconds field on the
362363
Master replica. This prevents individual trials from running indefinitely and
@@ -517,15 +518,15 @@ class name in this argument.
517518
resources_per_trial,
518519
training_utils.get_pod_template_spec(containers=[container_spec]),
519520
training_utils.get_pod_template_spec(containers=[container_spec]),
520-
trial_timeout,
521+
trial_active_deadline_seconds,
521522
)
522523
# Otherwise, Trial uses Job for model training.
523524
else:
524525
trial_template = utils.get_trial_template_with_job(
525526
retain_trials,
526527
trial_parameters,
527528
training_utils.get_pod_template_spec(containers=[container_spec]),
528-
trial_timeout,
529+
trial_active_deadline_seconds,
529530
)
530531

531532
# If users choose to use external models and datasets.
@@ -702,7 +703,7 @@ class name in this argument.
702703
resources_per_trial,
703704
master_pod_template_spec,
704705
worker_pod_template_spec,
705-
trial_timeout,
706+
trial_active_deadline_seconds,
706707
)
707708

708709
# Add parameters to the Katib Experiment.

sdk/python/v1beta1/kubeflow/katib/api/katib_client_test.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -542,19 +542,19 @@ def create_experiment(
542542
TEST_RESULT_SUCCESS,
543543
),
544544
(
545-
"valid flow with trial_timeout for Job-based trials",
545+
"valid flow with trial_active_deadline_seconds for Job-based trials",
546546
{
547547
"name": "tune_test",
548548
"objective": lambda x: print(f"a={x}"),
549549
"parameters": {"a": katib.search.int(min=10, max=100)},
550550
"objective_metric_name": "a",
551551
"resources_per_trial": {"gpu": "2"},
552-
"trial_timeout": 3600, # 1 hour timeout
552+
"trial_active_deadline_seconds": 3600, # 1 hour timeout
553553
},
554554
TEST_RESULT_SUCCESS,
555555
),
556556
(
557-
"valid flow with trial_timeout for PyTorchJob-based trials",
557+
"valid flow with trial_active_deadline_seconds for PyTorchJob-based trials",
558558
{
559559
"name": "tune_test",
560560
"objective": lambda x: print(f"a={x}"),
@@ -565,7 +565,7 @@ def create_experiment(
565565
num_procs_per_worker=2,
566566
resources_per_worker={"gpu": "2"},
567567
),
568-
"trial_timeout": 7200, # 2 hours timeout
568+
"trial_active_deadline_seconds": 7200, # 2 hours timeout
569569
},
570570
TEST_RESULT_SUCCESS,
571571
),
@@ -695,8 +695,10 @@ def test_tune(katib_client, test_name, kwargs, expected_output):
695695
KubeflowOrgV1PyTorchJob,
696696
)
697697

698-
elif test_name == "valid flow with trial_timeout for Job-based trials":
699-
# Verify trial_timeout is set on Job spec
698+
elif test_name == (
699+
"valid flow with trial_active_deadline_seconds for Job-based trials"
700+
):
701+
# Verify trial_active_deadline_seconds is set on Job spec
700702
job_spec = experiment.spec.trial_template.trial_spec.spec
701703
assert job_spec.active_deadline_seconds == 3600
702704
# Verify other Job-specific fields
@@ -710,9 +712,9 @@ def test_tune(katib_client, test_name, kwargs, expected_output):
710712

711713
elif (
712714
test_name
713-
== "valid flow with trial_timeout for PyTorchJob-based trials"
715+
== "valid flow with trial_active_deadline_seconds for PyTorchJob-based trials"
714716
):
715-
# Verify trial_timeout is set on PyTorchJob run_policy
717+
# Verify trial_active_deadline_seconds is set on PyTorchJob run_policy
716718
pytorch_spec = experiment.spec.trial_template.trial_spec.spec
717719
assert pytorch_spec.run_policy.active_deadline_seconds == 7200
718720
# Verify PyTorchJob type

sdk/python/v1beta1/kubeflow/katib/utils/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def get_trial_template_with_job(
284284
retain_trials: bool,
285285
trial_parameters: List[models.V1beta1TrialParameterSpec],
286286
pod_template_spec: client.V1PodTemplateSpec,
287-
trial_timeout: Optional[int] = None,
287+
trial_active_deadline_seconds: Optional[int] = None,
288288
) -> models.V1beta1TrialTemplate:
289289
"""
290290
Get Trial template with Job as a Trial's Worker
@@ -298,7 +298,7 @@ def get_trial_template_with_job(
298298
api_version="batch/v1",
299299
kind="Job",
300300
spec=client.V1JobSpec(
301-
template=pod_template_spec, active_deadline_seconds=trial_timeout
301+
template=pod_template_spec, active_deadline_seconds=trial_active_deadline_seconds
302302
),
303303
)
304304

@@ -317,7 +317,7 @@ def get_trial_template_with_pytorchjob(
317317
resources_per_trial: types.TrainerResources,
318318
master_pod_template_spec: models.V1PodTemplateSpec,
319319
worker_pod_template_spec: models.V1PodTemplateSpec,
320-
trial_timeout: Optional[int] = None,
320+
trial_active_deadline_seconds: Optional[int] = None,
321321
) -> models.V1beta1TrialTemplate:
322322
"""
323323
Get Trial template with PyTorchJob as a Trial's Worker
@@ -330,7 +330,7 @@ def get_trial_template_with_pytorchjob(
330330
spec=training_models.KubeflowOrgV1PyTorchJobSpec(
331331
run_policy=training_models.KubeflowOrgV1RunPolicy(
332332
clean_pod_policy=None,
333-
active_deadline_seconds=trial_timeout,
333+
active_deadline_seconds=trial_active_deadline_seconds,
334334
),
335335
nproc_per_node=str(resources_per_trial.num_procs_per_worker),
336336
pytorch_replica_specs={

0 commit comments

Comments
 (0)