Skip to content

Commit aef4735

Browse files
committed
Assign values in get pod template
1 parent 0bd07c5 commit aef4735

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

sdk/python/kubeflow/training/api/training_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def train(
107107
dataset_provider_parameters=None,
108108
train_parameters=None,
109109
resources_per_worker: Union[dict, models.V1ResourceRequirements, None] = None,
110-
# Dict[Literal["gpu", "cpu", "memory"], any] = None,
111110
):
112111
"""
113112
Higher level train api
@@ -223,14 +222,14 @@ def train(
223222
worker_pod_template_spec = utils.get_pod_template_spec(
224223
containers=[container_spec],
225224
init_containers=[init_container_spec],
226-
volumes_spec=[constants.STORAGE_INITIALIZER_VOLUME],
225+
volumes=[constants.STORAGE_INITIALIZER_VOLUME],
227226
)
228227

229228
# create master pod spec
230229
master_pod_template_spec = utils.get_pod_template_spec(
231230
containers=[container_spec],
232231
init_containers=[init_container_spec],
233-
volumes_spec=[constants.STORAGE_INITIALIZER_VOLUME],
232+
volumes=[constants.STORAGE_INITIALIZER_VOLUME],
234233
)
235234

236235
job = utils.get_pytorchjob_template(
@@ -365,7 +364,8 @@ def create_job(
365364
pip_index_url=pip_index_url,
366365
resources=resources_per_worker,
367366
)
368-
# Get Pod template spec from function or image.
367+
368+
# Get Pod template spec using the above container.
369369
pod_template_spec = utils.get_pod_template_spec(
370370
containers=[container_spec],
371371
)

sdk/python/kubeflow/training/utils/utils.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def get_command_using_train_func(
134134
pip_index_url: str = constants.DEFAULT_PIP_INDEX_URL,
135135
) -> Tuple[List[str], List[str]]:
136136
"""
137-
Get container args and command using the given training function and parameters.
137+
Get container args and command from the given training function and parameters.
138138
"""
139139
# Check if function is callable.
140140
if not callable(train_func):
@@ -179,7 +179,7 @@ def get_command_using_train_func(
179179
+ exec_script
180180
)
181181

182-
# Return container command and args execution script to the container arguments.
182+
# Return container command and args to execute training function.
183183
return ["bash", "-c"], [exec_script]
184184

185185

@@ -202,19 +202,18 @@ def get_container_spec(
202202
raise ValueError("Container name or base image cannot be none")
203203

204204
# Create initial container spec.
205-
container_spec = models.V1Container(name=name, image=base_image)
205+
container_spec = models.V1Container(
206+
name=name, image=base_image, args=args, volume_mounts=volume_mounts
207+
)
206208

207-
# If Training function is set, convert training function to the container args and command.
209+
# If training function is set, override container command and args to execute the function.
208210
if train_func is not None:
209211
container_spec.command, container_spec.args = get_command_using_train_func(
210212
train_func=train_func,
211213
train_func_parameters=train_func_parameters,
212214
packages_to_install=packages_to_install,
213215
pip_index_url=pip_index_url,
214216
)
215-
# Otherwise, get container args from the input.
216-
else:
217-
container_spec.args = args
218217

219218
# Convert dict to the Kubernetes container resources if that is required.
220219
if isinstance(resources, dict):
@@ -228,34 +227,33 @@ def get_container_spec(
228227
limits=resources,
229228
)
230229

231-
# Assign the rest container spec. If the value is None, container doesn't have that spec.
230+
# Add resources to the container spec.
232231
container_spec.resources = resources
233-
container_spec.volume_mounts = volume_mounts
234232

235233
return container_spec
236234

237235

238236
def get_pod_template_spec(
239237
containers: List[models.V1Container],
240238
init_containers: Optional[List[models.V1Container]] = None,
241-
volumes_spec: Optional[List[models.V1Volume]] = None,
239+
volumes: Optional[List[models.V1Volume]] = None,
242240
) -> models.V1PodTemplateSpec:
243241
"""
244242
Get Pod template spec for the given parameters.
245243
"""
246244

247-
# Create initial Pod template spec.
245+
# Create Pod template spec. If the value is None, Pod doesn't have that parameter
248246
pod_template_spec = models.V1PodTemplateSpec(
249247
metadata=models.V1ObjectMeta(
250248
annotations={constants.ISTIO_SIDECAR_INJECTION: "false"}
251249
),
252-
spec=models.V1PodSpec(containers=[containers]),
250+
spec=models.V1PodSpec(
251+
init_containers=init_containers,
252+
containers=containers,
253+
volumes=volumes,
254+
),
253255
)
254256

255-
# Assign the rest Pod spec. If the value is None, container doesn't have that spec.
256-
pod_template_spec.spec.init_containers = init_containers
257-
pod_template_spec.spec.volumes = volumes_spec
258-
259257
return pod_template_spec
260258

261259

0 commit comments

Comments
 (0)