Proxy in front of vLLM too; dashboard reset/clear; opencode effort variants
- Move the MLX proxy into backends/proxy.py and run it on both backends: public port 1134 is the proxy, the model server listens on 127.0.0.1:1135. On vLLM this brings the reasoning chooser, the "default" alias and the per-request table. Effort levels the model lacks map to the nearest it has (high -> xhigh on qwen3.8); vLLM's own key is sent upstream; streamed runs are counted from the usage chunk (MTP packs several tokens per chunk). - Dashboard: restore METRIC_RE (vLLM page stuck on "loading"); Statistics header with Reset, Requests header with Clear; drop the TTFT chart; rename token columns; Peak KV shows "-" when no samples cover a run. - opencode: config snippet's model points at <provider>/default, and reasoning models get variants built from the levels the template accepts. - README: proxy on both platforms; NVIDIA checklist split into verified / open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1121c3f908
commit
8879db44a0
12 changed files with 886 additions and 493 deletions
|
|
@ -8,14 +8,14 @@ import harness
|
|||
|
||||
ROOT = harness.setup()
|
||||
from llmhost import paths
|
||||
from llmhost.backends import mlx
|
||||
from llmhost.backends import mlx, proxy
|
||||
from llmhost.web import server as web
|
||||
|
||||
harness.guard(paths, ROOT)
|
||||
check = harness.Checks()
|
||||
|
||||
print("\n1. KV is picked out of mlx_lm's log line")
|
||||
st = mlx.Stats()
|
||||
st = proxy.Stats()
|
||||
st.kv_budget = int(77.27 * 2**30)
|
||||
for seg in [b"2026-11-03 01:13:31,176 - INFO - Prompt Cache: 10 sequences, 1.58 GB\n",
|
||||
b"2026-11-03 01:14:32,794 - INFO - Prompt Cache: 12 sequences, 4.24 GB\n",
|
||||
|
|
@ -33,20 +33,20 @@ check("fraction against --prompt-cache-bytes", abs(snap["kv"] - 2.00e9 / (77.27
|
|||
check("budget reported", snap["kv_budget_bytes"] == int(77.27 * 2**30))
|
||||
|
||||
print("\n2. no budget -> no fraction, but still a size")
|
||||
st2 = mlx.Stats(); st2.set_kv(4, 1.5e9)
|
||||
st2 = proxy.Stats(); st2.set_kv(4, 1.5e9)
|
||||
check("kv is None", st2.snapshot()["kv"] is None)
|
||||
check("kv_bytes still there", st2.snapshot()["kv_bytes"] == 1.5e9)
|
||||
check("fresh Stats reports nothing", mlx.Stats().snapshot()["kv"] is None)
|
||||
check("fresh Stats reports nothing", proxy.Stats().snapshot()["kv"] is None)
|
||||
|
||||
print("\n3. run records survive the round trip")
|
||||
st3 = mlx.Stats()
|
||||
st3 = proxy.Stats()
|
||||
st3.add_run({"start": 100.0, "end": 110.0, "dur": 10.0, "gen": 200, "prompt": 7667,
|
||||
"ttft": 2.0, "aborted": False})
|
||||
check("recent carries the run", len(st3.snapshot()["recent"]) == 1)
|
||||
for i in range(mlx.RECENT_RUNS + 10):
|
||||
for i in range(proxy.RECENT_RUNS + 10):
|
||||
st3.add_run({"start": float(i), "end": float(i) + 1, "dur": 1.0, "gen": 1, "prompt": 1,
|
||||
"ttft": 0.1, "aborted": False})
|
||||
check(f"bounded to {mlx.RECENT_RUNS}", len(st3.snapshot()["recent"]) == mlx.RECENT_RUNS,
|
||||
check(f"bounded to {proxy.RECENT_RUNS}", len(st3.snapshot()["recent"]) == proxy.RECENT_RUNS,
|
||||
len(st3.snapshot()["recent"]))
|
||||
|
||||
print("\n4. the sampler splits a run into prefill and generation")
|
||||
|
|
@ -142,4 +142,68 @@ check("nothing claimed to be a disconnect", not any("disconnected" in l for l in
|
|||
check("ordinary lines pass through", web.collapse_disconnects(["a", "b"]) == ["a", "b"])
|
||||
check("empty input", web.collapse_disconnects([]) == [])
|
||||
|
||||
print("\n8. vLLM's /metrics is parsed (lines captured from vLLM 0.33 on an RTX PRO 6000)")
|
||||
VLLM_METRICS = """# HELP vllm:num_requests_running Number of requests in model execution batches.
|
||||
vllm:num_requests_running{engine="0",model_name="qwen3.8-27b"} 2.0
|
||||
vllm:num_requests_waiting{engine="0",model_name="qwen3.8-27b"} 1.0
|
||||
vllm:num_requests_waiting_by_reason{engine="0",model_name="qwen3.8-27b",reason="capacity"} 5.0
|
||||
vllm:kv_cache_usage_perc{engine="0",model_name="qwen3.8-27b"} 0.25
|
||||
vllm:prefix_cache_queries_total{engine="0",model_name="qwen3.8-27b"} 57.0
|
||||
vllm:prefix_cache_hits_total{engine="0",model_name="qwen3.8-27b"} 0.0
|
||||
vllm:num_preemptions_total{engine="0",model_name="qwen3.8-27b"} 0.0
|
||||
vllm:prompt_tokens_total{engine="0",model_name="qwen3.8-27b"} 57.0
|
||||
vllm:generation_tokens_total{engine="0",model_name="qwen3.8-27b"} 37.0
|
||||
vllm:time_to_first_token_seconds_bucket{engine="0",le="0.1",model_name="qwen3.8-27b"} 1.0
|
||||
vllm:time_to_first_token_seconds_count{engine="0",model_name="qwen3.8-27b"} 1.0
|
||||
vllm:time_to_first_token_seconds_sum{engine="0",model_name="qwen3.8-27b"} 0.03685879707336426
|
||||
vllm:time_to_first_token_seconds_created{engine="0",model_name="qwen3.8-27b"} 1793704000.0"""
|
||||
vm = web.parse_vllm_metrics(VLLM_METRICS)
|
||||
check("running / waiting", vm["running"] == 2.0 and vm["waiting"] == 1.0, vm)
|
||||
check("waiting_by_reason not added into waiting", vm["waiting"] == 1.0, vm["waiting"])
|
||||
check("kv usage", vm["kv"] == 0.25, vm["kv"])
|
||||
check("token totals", vm["prompt_total"] == 57.0 and vm["gen_total"] == 37.0, vm)
|
||||
check("ttft sum and count, buckets and _created skipped",
|
||||
vm["ttft_count"] == 1.0 and abs(vm["ttft_sum"] - 0.0369) < 1e-3, vm)
|
||||
check("empty body", web.parse_vllm_metrics("")["kv"] is None)
|
||||
|
||||
check.section("9. Statistics reset rebases the counters; Requests clear empties the table")
|
||||
smp = web.Sampler(harness.config(), "k")
|
||||
raw = {"gen_total": 1000.0, "prompt_total": 5000.0, "ttft_sum": 4.0, "ttft_count": 8.0,
|
||||
"prefix_hits": 300.0, "prefix_queries": 1000.0, "kv": 0.2, "running": 1}
|
||||
check("before a reset: as reported", smp.since_reset(raw) == raw)
|
||||
smp.prev = (0, raw)
|
||||
smp.history.append({"t": 0, "kv": 20.0})
|
||||
smp.reset_stats()
|
||||
check("charts emptied", len(smp.history) == 0)
|
||||
check("reset time recorded", smp.stats_since is not None)
|
||||
later = dict(raw, gen_total=1040.0, prompt_total=5100.0, ttft_sum=4.5, ttft_count=9.0,
|
||||
prefix_hits=350.0, prefix_queries=1100.0)
|
||||
sh = smp.since_reset(later)
|
||||
check("counters count from the reset", sh["gen_total"] == 40 and sh["prompt_total"] == 100, sh)
|
||||
check("averages are of what came after", sh["ttft_sum"] / sh["ttft_count"] == 0.5 and
|
||||
sh["prefix_hits"] / sh["prefix_queries"] == 0.5, sh)
|
||||
check("live values untouched", sh["kv"] == 0.2 and sh["running"] == 1, sh)
|
||||
check("the reported metrics aren't modified", later["gen_total"] == 1040.0)
|
||||
restarted = dict(raw, gen_total=12.0, prompt_total=30.0, ttft_sum=0.1, ttft_count=1.0,
|
||||
prefix_hits=0.0, prefix_queries=30.0)
|
||||
check("a server restart after the reset: its own counters already start later",
|
||||
smp.since_reset(restarted)["gen_total"] == 12.0, smp.since_reset(restarted))
|
||||
smp.history.extend([{"t": 1, "kv": 5.0}, {"t": 2, "kv": 9.0}, {"t": 3, "kv": None}])
|
||||
check("peak KV since the reset comes from the samples",
|
||||
smp.kv_peak_pct({"kv_peak_bytes": 8e9, "kv_budget_bytes": 1e10}) == 9.0)
|
||||
|
||||
smp.runs.extend([{"t": 1}, {"t": 2}])
|
||||
smp._seen_runs.update({(1, 1), (2, 2)})
|
||||
smp.clear_runs()
|
||||
check("requests cleared", len(smp.runs) == 0)
|
||||
check("cleared requests stay seen (they don't come back)", {(1, 1), (2, 2)} <= smp._seen_runs)
|
||||
|
||||
check.section("10. a run's peak KV comes from samples in its window, or not at all")
|
||||
hist = [{"t": 10, "kv": 4.0}, {"t": 12, "kv": 7.5}, {"t": 14, "kv": 3.0}, {"t": 16, "kv": None}]
|
||||
check("max over the window", web.run_kv_peak(hist, {"start": 9, "end": 15}, 15, 0.0) == 7.5)
|
||||
check("a short run just finished: the reading right after it",
|
||||
web.run_kv_peak(hist, {"start": 16.2, "end": 16.9}, 17.0, 2.5) == 2.5)
|
||||
check("a run picked up long after (dashboard restarted): unknown, not 0%",
|
||||
web.run_kv_peak([], {"start": 100, "end": 400}, 900, 0.0) is None)
|
||||
|
||||
check.done(ROOT)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue