feat(us-016): smart shard gap detection for auto-join and --model-id

Tracker /v1/network/assign now accepts an optional `hf_repo` query param
to restrict assignment to a specific model, and returns `gap_found: bool`
so callers know whether they received a real gap vs a redundancy slot.

Node startup with --model-id (no explicit shard args) now queries the
tracker first for an uncovered gap for that model before defaulting to
full coverage (0..n-1). This means a second node with --model-id will
serve only the missing layers, not the whole model again.

Auto-join fallback (no --model-id) now prints why it fell through
instead of silently switching to stub-model.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Dobromir Popov
2026-06-30 00:48:34 +03:00
parent 97eefd3d5e
commit 3286e42783
3 changed files with 104 additions and 7 deletions

View File

@@ -788,9 +788,11 @@ class _TrackerHandler(http.server.BaseHTTPRequestHandler):
Query params:
vram_mb — integer VRAM in MB (0 = CPU-only node)
device — "cuda" | "cpu"
hf_repo — optional; if set, restrict search to this repo only
Returns:
{hf_repo, shard_start, shard_end, num_layers}
{hf_repo, shard_start, shard_end, num_layers, gap_found}
gap_found=true means a real uncovered gap was assigned; false means redundancy.
"""
server: _TrackerHTTPServer = self.server # type: ignore[assignment]
params = urllib.parse.parse_qs(parsed.query)
@@ -799,6 +801,7 @@ class _TrackerHandler(http.server.BaseHTTPRequestHandler):
except ValueError:
vram_mb = 0
device = params.get("device", ["cpu"])[0]
filter_repo = params.get("hf_repo", [None])[0] # optional repo filter
with server.lock:
self._purge_expired_nodes()
@@ -811,10 +814,16 @@ class _TrackerHandler(http.server.BaseHTTPRequestHandler):
and n.shard_start is not None
and n.shard_end is not None
and n.num_layers is not None
and (filter_repo is None or n.hf_repo == filter_repo)
]
if not hf_nodes:
self._send_json(503, {"error": "no HF-model nodes registered; cannot assign shards"})
msg = (
f"no HF-model nodes registered for {filter_repo!r}"
if filter_repo
else "no HF-model nodes registered; cannot assign shards"
)
self._send_json(503, {"error": msg})
return
# Group by hf_repo; pick the one with the largest total_layers and biggest gap.
@@ -853,7 +862,8 @@ class _TrackerHandler(http.server.BaseHTTPRequestHandler):
best_repo = repo
best_num_layers = total
if best_repo is None or best_gap_size <= 0:
gap_found = best_gap_size > 0
if not gap_found:
# All shards are covered — still assign to the model with most nodes for redundancy.
best_repo = max(repo_groups, key=lambda r: len(repo_groups[r]))
best_gap_start = 0
@@ -874,6 +884,7 @@ class _TrackerHandler(http.server.BaseHTTPRequestHandler):
"shard_start": shard_start,
"shard_end": shard_end,
"num_layers": total_l,
"gap_found": gap_found,
})
def _handle_route(self, parsed: urllib.parse.ParseResult):