feat(trainer): make RuntimeTrainer.image optional for BYOI #810
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign electronic-waste for approval. For more information see the Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
<details open>
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
</details>
<!-- META={"approvers":["electronic-waste"]} -->
/ok-to-test
/retest
Thanks for working on this @kliushenkov! I left a few comments. Note: this review was done with the help of AI tools.
Please remove these helpers from the public types module (they become public API). Since RuntimeTrainer.image defaults to Unknown (like device), compare inline: runtime.trainer.image == common_constants.UNKNOWN. See suggestions below.
This check is not needed: get_trainer_cr_from_builtin_trainer already fails at TrainJob creation, and raising here makes list_runtimes() fail entirely for one image-less TorchTune runtime. Please also drop the matching test_get_runtime_trainer_image case.
trainer = types.RuntimeTrainer(
trainer_type=(
types.TrainerType.BUILTIN_TRAINER
if framework == types.TORCH_TUNE
else types.TrainerType.CUSTOM_TRAINER
),
framework=framework,
image=trainer_container.image or common_constants.UNKNOWN,
This now always pins the runtime image in the TrainJob spec, which changes behavior for every existing user. Only set the image when the user provides it, and fail only when both images are unset:
# Set the TrainJob trainer image if that is set.
if trainer.image:
trainer_cr.image = trainer.image
elif runtime.trainer.image == common_constants.UNKNOWN:
raise ValueError("Trainer image is required. Set image in CustomTrainer or in the Runtime.")
The runtime image used when custom trainer image unset test should then expect None.
if runtime.trainer.image == common_constants.UNKNOWN:
if runtime.trainer.image == common_constants.UNKNOWN:
elif runtime.trainer.image == common_constants.UNKNOWN:
Please revert this: the TrainJob shouldn't get the runtime image when the user didn't set one.
Needs import kubeflow.common.constants as common_constants.
if runtime.trainer.image == common_constants.UNKNOWN:
# Resolve image before allocating workdir/network so invalid configs fail early.
image = trainer.image or runtime.trainer.image
if image == common_constants.UNKNOWN:
raise ValueError(
"Trainer image is required. Set image in CustomTrainer or in the Runtime."
)
Please add container backend_test.py cases: train() with an image-less runtime (succeeds with CustomTrainer.image, raises without it and creates no network/containers), and get_runtime_packages() raising when the image is unset.
Local runtimes always have an image and this method doesn't use it, so this check can't fire. Please remove it and the matching test.
andreyvelich
kliushenkov
Summary
RuntimeTrainer.imagedefault toUnknownso TrainingRuntime / ClusterTrainingRuntime can omit a pinned image for bring-your-own-image workflows.ValueError; require a runtime image for BuiltinTrainer and when trainer is omitted.get_runtime_packagesacross Kubernetes, container, and localprocess backends to raise when the runtime image is unset; validate container image before allocating workdir/network.Fixes #494
Test plan
Unknown), trainer override success, and missing-image failureget_runtime_packagesraises consistently when image isUnknownclient.train(runtime=..., trainer=CustomTrainer(..., image=...))with an image-less runtimeMade with Cursor