Skip to content
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
8 changes: 8 additions & 0 deletions keras_remote/backend/gke_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,14 @@ def _check_node_pool_exists_cached(selector_items) -> bool:
"cloud.google.com/gke-tpu-topology", ""
)

# Infer accelerator count from machine type using registry
# This is robust because it uses the same source of truth as the Pod spec generation
for tpu_spec in accelerators.TPUS.values():
for chips, topo_spec in tpu_spec.topologies.items():
if topo_spec.machine_type == machine_type:
pool_labels["cloud.google.com/gke-accelerator-count"] = str(chips)
break
Comment on lines +466 to +470
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The break on line 470 only exits the inner loop. The outer loop continues to iterate through the remaining tpu_specs even after a match is found, which is inefficient. You can use a for...else construct to break out of both loops once a match is found.

Suggested change
for tpu_spec in accelerators.TPUS.values():
for chips, topo_spec in tpu_spec.topologies.items():
if topo_spec.machine_type == machine_type:
pool_labels["cloud.google.com/gke-accelerator-count"] = str(chips)
break
for tpu_spec in accelerators.TPUS.values():
for chips, topo_spec in tpu_spec.topologies.items():
if topo_spec.machine_type == machine_type:
pool_labels["cloud.google.com/gke-accelerator-count"] = str(chips)
break
else:
continue
break


if all(pool_labels.get(k) == str(v) for k, v in selector.items()):
return True
return False
Expand Down
Loading