fix(trainer): handle empty and memory-only container resource limits in get_container_devices #806
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
[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"]} -->
reproduced the crash on main and this fixes it, nice. the new tests fail without the fix too, so they cover it well.
one question: this also changes amd.com/gpu (or any other accelerator we don't list) from raising to showing "Unknown". that seems fine to me, just wanted to check it's intended, or should AMD be recognized here at some point?
I couldn't find a way to hit this one. a null limit value fails earlier when the response is parsed, so device_count always has a value by this point. fine to keep as a guard, just mentioning in case you'd rather drop it.
checked this against main and it works as described. memory-only and empty limits no longer crash get_job / list_jobs, and the mock pod change in backend_test makes those paths exercise it. also merged cleanly with current main for me, tests pass.
yeah intended, before it just crashed on anything we don't list. AMD can be its own follow-up if maintainers want it, didn't want to widen this PR
yep, can't be hit. dropped it in 47bf299
aniket-3001
rautaditya2606
What this PR does / why we need it:
In
kubeflow.trainer.backends.kubernetes.utils.get_container_devices, an unhandled genericExceptionwas raised whenever a container'sresources.limitswas empty ({}) or only contained non-compute resources (such as memory-only limits or ephemeral-storage).In real-world training jobs:
1. Dataset or model initializer containers often specify memory limits without CPU or accelerator limits.
2. Sidecars or pods with empty limits (
{}) causedget_container_devicesto raiseException: Unknown device type in the container resources: {'memory': ...}.Because
get_trainjob_initializer_step,get_trainjob_node_step, andget_runtime_trainerrely onget_container_devices, this unhandled exception crashedTrainerClient.get_job(),wait_for_job_status(), andlist_jobs().This PR fixes that by:
Nonewhenresources.limitsis empty or lacks recognized compute device keys, and logging a debug message with the limits.Noneby settingdevice="Unknown"anddevice_count="Unknown", so downstream behavior remains consistent.ValueErrorcheck for multiple MIG keys intact as that represents an invalid/unsupported configuration rather than an unmapped non-compute limit.backend_test.pywith memory limits to verify end-to-end TrainJob step retrieval.Which issue(s) this PR fixes:
Fixes #805
Checklist: