Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[k8s] Fix AssertionError in show-gpus when all GPUs were allocated #4558

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sky/clouds/service_catalog/kubernetes_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ def _list_accelerators(

If the user does not have sufficient permissions to list pods in all
namespaces, the function will return free GPUs as -1.

Returns:
A tuple of three dictionaries:
- qtys_map: Dict mapping accelerator names to lists of InstanceTypeInfo
objects with quantity information.
- total_accelerators_capacity: Dict mapping accelerator names to their
total capacity in the cluster.
- total_accelerators_available: Dict mapping accelerator names to their
current availability. Returns -1 for each accelerator if
realtime=False or if insufficient permissions.
"""
# TODO(romilb): This should be refactored to use get_kubernetes_node_info()
# function from kubernetes_utils.
Expand Down Expand Up @@ -243,6 +253,10 @@ def _list_accelerators(

accelerators_available = accelerator_count - allocated_qty

# Initialize the entry if it doesn't exist yet
if accelerator_name not in total_accelerators_available:
total_accelerators_available[accelerator_name] = 0
Comment on lines +257 to +258
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: we can also use collections.defaultdict(int) if needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm might be better to use regular dict here to reduce bugs when downstream methods try to check for GPUs that don't exist in the cluster (e.g., accessing total_accelerators_available['A100'] will return 0, giving a impression its currently in-use, when it might not exist at all in the cluster).


if accelerators_available >= min_quantity_filter:
quantized_availability = min_quantity_filter * (
accelerators_available // min_quantity_filter)
Expand Down
Loading