fix(router): handle None temp_c/vram_pct in gpu_health_score

AMD sidecar returns null for temp_c/power_w fields.
gpu_health_score now uses  fallback for all numeric fields.
check_gpu_health also defaults temp_c and gpu_util_pct to 0.

Fixes 500 error on /metrics/gpu-health
This commit is contained in:
Abiba
2026-06-12 18:11:23 +00:00
parent 574076119c
commit 316f2f5f45
+4 -4
View File
@@ -226,13 +226,13 @@ def gpu_health_score(model):
h = check_gpu_health(model, sidecar_timeout=1.5, gpu_timeout=1) h = check_gpu_health(model, sidecar_timeout=1.5, gpu_timeout=1)
if h.get("status") == "down": if h.get("status") == "down":
return 999 # never pick down GPUs return 999 # never pick down GPUs
vram_pct = h.get("vram_pct", 50) vram_pct = h.get("vram_pct") or 50
temp_c = h.get("temp_c", 50) temp_c = h.get("temp_c") or 50
active = gpu_active_count(model) active = gpu_active_count(model)
max_c = GPU_MAX_CONCURRENT.get(model, 1) max_c = GPU_MAX_CONCURRENT.get(model, 1)
load_pct = (active / max_c) * 100 load_pct = (active / max_c) * 100 if max_c > 0 else 0
# Score: lower = better (more headroom, cooler, less loaded) # Score: lower = better (more headroom, cooler, less loaded)
score = vram_pct * 0.4 + max(temp_c - 30, 0) * 0.3 + load_pct * 0.3 score = (vram_pct or 0) * 0.4 + max((temp_c or 50) - 30, 0) * 0.3 + load_pct * 0.3
return score return score
def select_best_gpu(candidates, reason, agent=""): def select_best_gpu(candidates, reason, agent=""):