diff --git a/router/router.py b/router/router.py index f82d968..e0a1b1d 100644 --- a/router/router.py +++ b/router/router.py @@ -119,7 +119,11 @@ def is_gpu_busy(model): return active >= max_c def select_best_gpu(candidates, reason): - """Pick the best GPU from candidates, preferring least-loaded.""" + """Pick the best GPU from candidates IN ORDER — first non-busy one wins.""" + for m in candidates: + if not is_gpu_busy(m): + return {"model": m, "reason": reason} + # All busy — pick least loaded best = None best_load = 999 for m in candidates: @@ -128,10 +132,7 @@ def select_best_gpu(candidates, reason): best_load = load best = m if best: - actual_reason = reason - if is_gpu_busy(best): - actual_reason = "load_balanced_" + reason - return {"model": best, "reason": actual_reason} + return {"model": best, "reason": "load_balanced_" + reason} return None def route(rd, tier): @@ -182,7 +183,7 @@ def route(rd, tier): # TIER 3: Heavy reasoning — large context or very long conversations if t > 4000 or turns > 8: - candidates = [m for m in ["qwen3.6-35B-A3B","qwen3.5-9b-vlm","qwen3.6-27B-code"] if m in avail] + candidates = [m for m in ["qwen3.6-27B-code","qwen3.6-35B-A3B","qwen3.5-9b-vlm"] if m in avail] result = select_best_gpu(candidates, "heavy_reasoning") if result: return result