Skip to content

Commit adbd2c2

Browse files
committed
fix: trial_spec variable is no longer exist after rebase
- rename all config_map to configmap Signed-off-by: truc0 <22969604+truc0@users.noreply.github.com>
1 parent 08eea26 commit adbd2c2

File tree

1 file changed

+23
-39
lines changed

1 file changed

+23
-39
lines changed

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

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,12 @@ class name in this argument.
302302
- volume: Either a kubernetes.client.V1Volume object or a dictionary
303303
containing volume configuration with required fields:
304304
- name: Name of the volume
305-
- type: One of "pvc", "secret", "config_map", or "empty_dir"
305+
- type: One of "pvc", "secret", "configmap", or "empty_dir"
306306
Additional fields based on volume type:
307307
- For pvc: claim_name, read_only (optional)
308308
- For secret: secret_name, items (optional), default_mode (optional),
309309
optional (optional)
310-
- For config_map: config_map_name, items (optional), default_mode
310+
- For configmap: configmap_name, items (optional), default_mode
311311
(optional), optional (optional)
312312
- For empty_dir: medium (optional), size_limit (optional)
313313
- mount_path: Either a kubernetes.client.V1VolumeMount object or a string
@@ -533,7 +533,6 @@ class name in this argument.
533533
if isinstance(storage_per_trial, dict):
534534
storage_per_trial = [storage_per_trial]
535535
for storage in storage_per_trial:
536-
print(f"storage: {storage}")
537536
volume = None
538537
if isinstance(storage["volume"], client.V1Volume):
539538
volume = storage["volume"]
@@ -576,11 +575,11 @@ class name in this argument.
576575
optional=storage["volume"].get("optional", False),
577576
),
578577
)
579-
elif volume_type == "config_map":
578+
elif volume_type == "configmap":
580579
volume = client.V1Volume(
581580
name=volume_name,
582-
config_map=client.V1ConfigMapVolumeSource(
583-
name=storage["volume"].get("config_map_name"),
581+
configmap=client.V1ConfigMapVolumeSource(
582+
name=storage["volume"].get("configmap_name"),
584583
items=storage["volume"].get("items", []),
585584
default_mode=storage["volume"].get(
586585
"default_mode", None
@@ -624,52 +623,37 @@ class name in this argument.
624623
"client.V1VolumeMount or a str"
625624
)
626625

627-
# Create Trial specification.
628-
trial_spec = client.V1Job(
629-
api_version="batch/v1",
630-
kind="Job",
631-
spec=client.V1JobSpec(
632-
template=client.V1PodTemplateSpec(
633-
metadata=models.V1ObjectMeta(
634-
annotations={"sidecar.istio.io/inject": "false"}
635-
),
636-
spec=client.V1PodSpec(
637-
restart_policy="Never",
638-
containers=[
639-
client.V1Container(
640-
name=constants.DEFAULT_PRIMARY_CONTAINER_NAME,
641-
image=base_image,
642-
command=["bash", "-c"],
643-
args=[exec_script],
644-
env=env if env else None,
645-
env_from=env_from if env_from else None,
646-
resources=resources_per_trial,
647-
volume_mounts=(
648-
volume_mounts if volume_mounts else None
649-
),
650-
)
651-
],
652-
volumes=volumes if volumes else None,
653-
),
654-
)
655-
),
656-
)
626+
# inject volume mounts to the container spec, do nothing if volume_mounts is empty
627+
if volume_mounts:
628+
if isinstance(container_spec.volume_mounts, list):
629+
container_spec.volume_mounts.extend(volume_mounts)
630+
else:
631+
container_spec.volume_mounts = volume_mounts
657632

658633
# Trial uses PyTorchJob for distributed training if TrainerResources is set.
659634
if isinstance(resources_per_trial, TrainerResources):
660635
trial_template = utils.get_trial_template_with_pytorchjob(
661636
retain_trials,
662637
trial_parameters,
663638
resources_per_trial,
664-
training_utils.get_pod_template_spec(containers=[container_spec]),
665-
training_utils.get_pod_template_spec(containers=[container_spec]),
639+
training_utils.get_pod_template_spec(
640+
containers=[container_spec],
641+
volumes=volumes if volumes else None,
642+
),
643+
training_utils.get_pod_template_spec(
644+
containers=[container_spec],
645+
volumes=volumes if volumes else None,
646+
),
666647
)
667648
# Otherwise, Trial uses Job for model training.
668649
else:
669650
trial_template = utils.get_trial_template_with_job(
670651
retain_trials,
671652
trial_parameters,
672-
training_utils.get_pod_template_spec(containers=[container_spec]),
653+
training_utils.get_pod_template_spec(
654+
containers=[container_spec],
655+
volumes=volumes if volumes else None,
656+
),
673657
)
674658

675659
# If users choose to use external models and datasets.

0 commit comments

Comments
 (0)