@simplexai/localmodels-darwin-x64 0.1.0-dev.100 → 0.1.0-dev.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +31 -29
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/app.py +35 -7
- package/modules/localmodels/auth_proxy.py +337 -14
- package/modules/localmodels/catalog.json +16 -10
- package/modules/localmodels/engine_adapters/suite_plan.py +4 -2
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.7.json +94 -0
- package/modules/localmodels/guard-requirements.in +3 -0
- package/modules/localmodels/guard-requirements.lock +4 -4
- package/modules/localmodels/guard.py +2 -2
- package/modules/localmodels/program_scheduler.py +1198 -0
- package/modules/localmodels/slot_cache.py +71 -5
- package/modules/localmodels/speech_jobs.py +2 -0
- package/modules/localmodels/speech_workers.py +62 -10
- package/modules/localmodels/stack_capacity.py +37 -1
- package/modules/localmodels/stack_cli.py +1 -0
- package/modules/localmodels/stack_hardware.py +18 -16
- package/modules/localmodels/stack_plan.py +21 -0
- package/modules/localmodels/stack_progress.py +15 -0
- package/modules/localmodels/stack_run.py +25 -2
- package/modules/localmodels/stack_suite.py +54 -12
- package/modules/localmodels/{strata-poly-serve-0.2.20-poly.6.txt → strata-poly-serve-0.2.20-poly.7.txt} +1 -1
- package/modules/localmodels/suite.py +10 -1
- package/modules/{simplex_localmodels-0.1.0.dev100.dist-info → simplex_localmodels-0.1.0.dev102.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev100.dist-info → simplex_localmodels-0.1.0.dev102.dist-info}/RECORD +28 -26
- package/modules/{simplex_localmodels-0.1.0.dev100.dist-info → simplex_localmodels-0.1.0.dev102.dist-info}/licenses/NOTICE +1 -1
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.6.json +0 -94
- /package/modules/{simplex_localmodels-0.1.0.dev100.dist-info → simplex_localmodels-0.1.0.dev102.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev100.dist-info → simplex_localmodels-0.1.0.dev102.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev100.dist-info → simplex_localmodels-0.1.0.dev102.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -19,6 +19,7 @@ import hmac
|
|
|
19
19
|
import http.client
|
|
20
20
|
import http.server
|
|
21
21
|
import io
|
|
22
|
+
import json
|
|
22
23
|
import os
|
|
23
24
|
import selectors
|
|
24
25
|
import signal
|
|
@@ -29,7 +30,7 @@ import threading
|
|
|
29
30
|
import time
|
|
30
31
|
from email.message import Message
|
|
31
32
|
from pathlib import Path
|
|
32
|
-
from typing import Callable
|
|
33
|
+
from typing import Any, Callable
|
|
33
34
|
|
|
34
35
|
# Hop-by-hop headers and those this proxy sets itself.
|
|
35
36
|
DROPPED = {
|
|
@@ -62,6 +63,110 @@ ADDR_IN_USE = frozenset(
|
|
|
62
63
|
|
|
63
64
|
|
|
64
65
|
DISCARD_MAX = 256 << 20 # a refused upload larger than this is cut off, not read
|
|
66
|
+
_KV_TYPES = frozenset({"f16", "q8_0", "q4_0"})
|
|
67
|
+
_PROGRAM_VALUE_FLAGS = frozenset(
|
|
68
|
+
{
|
|
69
|
+
"--program-model",
|
|
70
|
+
"--program-window",
|
|
71
|
+
"--program-slots",
|
|
72
|
+
"--program-kv-k",
|
|
73
|
+
"--program-kv-v",
|
|
74
|
+
"--program-cache-mib",
|
|
75
|
+
"--program-max-resident",
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _load_program_scheduler() -> Any:
|
|
81
|
+
try:
|
|
82
|
+
from localmodels import program_scheduler
|
|
83
|
+
except ImportError:
|
|
84
|
+
import program_scheduler # type: ignore[import-not-found,no-redef]
|
|
85
|
+
return program_scheduler
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def parse_program_flags(
|
|
89
|
+
argv: list[str],
|
|
90
|
+
) -> tuple[dict[str, Any], list[str]] | None:
|
|
91
|
+
"""Split leading opt-in ``--program-*`` flags from ``argv``, returning ``(overrides, rest)``."""
|
|
92
|
+
overrides: dict[str, Any] = {}
|
|
93
|
+
index = 0
|
|
94
|
+
while index < len(argv) and argv[index].startswith("--") and argv[index] != "--":
|
|
95
|
+
arg = argv[index]
|
|
96
|
+
if arg == "--program-aware":
|
|
97
|
+
overrides["enabled"] = True
|
|
98
|
+
index += 1
|
|
99
|
+
continue
|
|
100
|
+
if "=" in arg:
|
|
101
|
+
name, raw = arg.split("=", 1)
|
|
102
|
+
step = 1
|
|
103
|
+
else:
|
|
104
|
+
name = arg
|
|
105
|
+
raw = argv[index + 1] if index + 1 < len(argv) else ""
|
|
106
|
+
step = 2
|
|
107
|
+
if name not in _PROGRAM_VALUE_FLAGS:
|
|
108
|
+
break
|
|
109
|
+
if step == 2 and index + 1 >= len(argv):
|
|
110
|
+
return None
|
|
111
|
+
parsed = _parse_program_flag_value(name, raw)
|
|
112
|
+
if parsed is None:
|
|
113
|
+
return None
|
|
114
|
+
key, value = parsed
|
|
115
|
+
overrides[key] = value
|
|
116
|
+
index += step
|
|
117
|
+
return overrides, argv[index:]
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _parse_program_flag_value(name: str, raw: str) -> tuple[str, Any] | None:
|
|
121
|
+
if name == "--program-model":
|
|
122
|
+
return ("model_id", raw.strip()) if raw.strip() else None
|
|
123
|
+
if name in ("--program-kv-k", "--program-kv-v"):
|
|
124
|
+
val = raw.strip().lower()
|
|
125
|
+
if val not in _KV_TYPES:
|
|
126
|
+
return None
|
|
127
|
+
return ("kv_k" if name == "--program-kv-k" else "kv_v", val)
|
|
128
|
+
int_keys = {
|
|
129
|
+
"--program-window": ("window_tokens", 1),
|
|
130
|
+
"--program-slots": ("slots", 1),
|
|
131
|
+
"--program-cache-mib": ("prompt_cache_mib", 0),
|
|
132
|
+
"--program-max-resident": ("max_resident_programs", 0),
|
|
133
|
+
}
|
|
134
|
+
key, minimum = int_keys[name]
|
|
135
|
+
try:
|
|
136
|
+
num = int(raw)
|
|
137
|
+
except ValueError:
|
|
138
|
+
return None
|
|
139
|
+
return (key, num) if num >= minimum else None
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def build_program_scheduler(
|
|
143
|
+
overrides: dict[str, Any], *, defaults: dict[str, Any] | None = None
|
|
144
|
+
) -> Any:
|
|
145
|
+
"""Return a ``ProgramAwareScheduler`` if opted in via flags or env, else ``None``."""
|
|
146
|
+
env_on = (os.environ.get("LOCALMODELS_PROGRAM_AWARE") or "").strip().lower() in {
|
|
147
|
+
"1",
|
|
148
|
+
"true",
|
|
149
|
+
"yes",
|
|
150
|
+
"on",
|
|
151
|
+
}
|
|
152
|
+
if not overrides.get("enabled") and not env_on:
|
|
153
|
+
return None
|
|
154
|
+
ps = _load_program_scheduler()
|
|
155
|
+
merged: dict[str, Any] = {}
|
|
156
|
+
if defaults:
|
|
157
|
+
merged.update(defaults)
|
|
158
|
+
merged.update(overrides)
|
|
159
|
+
opts = ps.options_from_env(**merged)
|
|
160
|
+
if not opts.enabled:
|
|
161
|
+
return None
|
|
162
|
+
return ps.scheduler_from_options(opts)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
class ProxyHTTPServer(http.server.ThreadingHTTPServer):
|
|
166
|
+
"""Loopback multi-threaded HTTP server sized for concurrent multi-agent cohorts."""
|
|
167
|
+
|
|
168
|
+
daemon_threads = True
|
|
169
|
+
request_queue_size = 64
|
|
65
170
|
|
|
66
171
|
|
|
67
172
|
def resolve_watchdog_ppid(cli_value: int | None) -> int | None:
|
|
@@ -139,6 +244,51 @@ def install_parent_watchdog(
|
|
|
139
244
|
return stop_event
|
|
140
245
|
|
|
141
246
|
|
|
247
|
+
def _parse_cli(
|
|
248
|
+
argv: list[str],
|
|
249
|
+
) -> tuple[int, str, list[str], int | None, dict[str, Any]] | None:
|
|
250
|
+
"""Parse ``[--watchdog-ppid PID] [--program-* ...] PORT KEY_FILE -- CMD`` in any flag order."""
|
|
251
|
+
program_overrides: dict[str, Any] = {}
|
|
252
|
+
base_argv: list[str] = []
|
|
253
|
+
index = 0
|
|
254
|
+
while index < len(argv) and argv[index].startswith("--") and argv[index] != "--":
|
|
255
|
+
arg = argv[index]
|
|
256
|
+
if arg == "--watchdog-ppid":
|
|
257
|
+
if index + 1 >= len(argv):
|
|
258
|
+
return None
|
|
259
|
+
base_argv.extend((arg, argv[index + 1]))
|
|
260
|
+
index += 2
|
|
261
|
+
continue
|
|
262
|
+
if arg.startswith("--watchdog-ppid="):
|
|
263
|
+
base_argv.append(arg)
|
|
264
|
+
index += 1
|
|
265
|
+
continue
|
|
266
|
+
split = parse_program_flags(argv[index:])
|
|
267
|
+
if split is None:
|
|
268
|
+
return None
|
|
269
|
+
parsed_opts, rest = split
|
|
270
|
+
if not parsed_opts:
|
|
271
|
+
return None
|
|
272
|
+
program_overrides.update(parsed_opts)
|
|
273
|
+
index = len(argv) - len(rest)
|
|
274
|
+
base_argv.extend(argv[index:])
|
|
275
|
+
parsed = _parse_args(base_argv)
|
|
276
|
+
if parsed is None:
|
|
277
|
+
return None
|
|
278
|
+
port, key_file, cmd, cli_ppid = parsed
|
|
279
|
+
return port, key_file, cmd, cli_ppid, program_overrides
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _dynamic_hop_headers(connection_values: list[str]) -> set[str]:
|
|
283
|
+
extra: set[str] = set()
|
|
284
|
+
for value in connection_values:
|
|
285
|
+
for token in value.split(","):
|
|
286
|
+
name = token.strip().lower()
|
|
287
|
+
if name:
|
|
288
|
+
extra.add(name)
|
|
289
|
+
return extra
|
|
290
|
+
|
|
291
|
+
|
|
142
292
|
def _parse_args(argv: list[str]) -> tuple[int, str, list[str], int | None] | None:
|
|
143
293
|
cli_ppid: int | None = None
|
|
144
294
|
index = 0
|
|
@@ -331,8 +481,11 @@ def send_head(
|
|
|
331
481
|
each frame flushes immediately) and close-delimited framing for HTTP/1.0 clients.
|
|
332
482
|
"""
|
|
333
483
|
to.send_response(resp.status)
|
|
334
|
-
|
|
335
|
-
|
|
484
|
+
resp_headers = resp.getheaders()
|
|
485
|
+
dynamic_hop = _dynamic_hop_headers([v for k, v in resp_headers if k.lower() == "connection"])
|
|
486
|
+
excluded = DROPPED | dynamic_hop
|
|
487
|
+
for k, v in resp_headers:
|
|
488
|
+
if k.lower() not in excluded:
|
|
336
489
|
to.send_header(k, v)
|
|
337
490
|
raw_length = resp.getheader("Content-Length")
|
|
338
491
|
length = body_length(raw_length) if raw_length is not None and not resp.chunked else -1
|
|
@@ -360,6 +513,8 @@ def forward_body(
|
|
|
360
513
|
resp: http.client.HTTPResponse,
|
|
361
514
|
mode: str,
|
|
362
515
|
expected: int | None,
|
|
516
|
+
*,
|
|
517
|
+
on_chunk: Callable[[bytes], None] | None = None,
|
|
363
518
|
) -> None:
|
|
364
519
|
"""Stream the backend's response body according to the framing chosen by ``send_head``."""
|
|
365
520
|
if mode == "none":
|
|
@@ -370,6 +525,8 @@ def forward_body(
|
|
|
370
525
|
data = resp.read1(65536)
|
|
371
526
|
if not data:
|
|
372
527
|
break
|
|
528
|
+
if on_chunk is not None:
|
|
529
|
+
on_chunk(data)
|
|
373
530
|
to.wfile.write(data)
|
|
374
531
|
to.wfile.flush()
|
|
375
532
|
written += len(data)
|
|
@@ -381,6 +538,8 @@ def forward_body(
|
|
|
381
538
|
data = resp.read1(65536)
|
|
382
539
|
if not data:
|
|
383
540
|
break
|
|
541
|
+
if on_chunk is not None:
|
|
542
|
+
on_chunk(data)
|
|
384
543
|
to.wfile.write(f"{len(data):x}\r\n".encode("ascii") + data + b"\r\n")
|
|
385
544
|
to.wfile.flush()
|
|
386
545
|
to.wfile.write(b"0\r\n\r\n")
|
|
@@ -390,6 +549,8 @@ def forward_body(
|
|
|
390
549
|
data = resp.read1(65536)
|
|
391
550
|
if not data:
|
|
392
551
|
break
|
|
552
|
+
if on_chunk is not None:
|
|
553
|
+
on_chunk(data)
|
|
393
554
|
to.wfile.write(data)
|
|
394
555
|
to.wfile.flush()
|
|
395
556
|
|
|
@@ -412,7 +573,7 @@ def bind_server(
|
|
|
412
573
|
deadline = time.monotonic() + (BIND_RETRY_S if wait_s is None else wait_s)
|
|
413
574
|
while True:
|
|
414
575
|
try:
|
|
415
|
-
return
|
|
576
|
+
return ProxyHTTPServer(address, handler_class)
|
|
416
577
|
except OSError as exc:
|
|
417
578
|
if exc.errno not in ADDR_IN_USE or time.monotonic() >= deadline:
|
|
418
579
|
raise
|
|
@@ -431,6 +592,8 @@ def _proxy_upstream(
|
|
|
431
592
|
upstream: int,
|
|
432
593
|
body: bytes | None,
|
|
433
594
|
headers: dict[str, str],
|
|
595
|
+
*,
|
|
596
|
+
on_chunk: Callable[[bytes], None] | None = None,
|
|
434
597
|
) -> bool:
|
|
435
598
|
"""Forward one request to ``upstream``; returns True once response headers were sent."""
|
|
436
599
|
conn = http.client.HTTPConnection("127.0.0.1", upstream, timeout=TIMEOUT_S)
|
|
@@ -443,7 +606,7 @@ def _proxy_upstream(
|
|
|
443
606
|
resp = conn.getresponse()
|
|
444
607
|
mode, expected_length = send_head(to, resp)
|
|
445
608
|
started = True
|
|
446
|
-
forward_body(to, resp, mode, expected_length)
|
|
609
|
+
forward_body(to, resp, mode, expected_length, on_chunk=on_chunk)
|
|
447
610
|
return True
|
|
448
611
|
except (OSError, http.client.HTTPException): # a reply cut short is not an OSError
|
|
449
612
|
if started:
|
|
@@ -457,8 +620,10 @@ class _ForwardBase(http.server.BaseHTTPRequestHandler):
|
|
|
457
620
|
protocol_version = "HTTP/1.1"
|
|
458
621
|
disable_nagle_algorithm = True
|
|
459
622
|
_expected: bytes | None = None
|
|
623
|
+
_control_expected: bytes | None = None
|
|
460
624
|
_upstream: int = 0
|
|
461
625
|
_dropped: frozenset[str] = frozenset(DROPPED)
|
|
626
|
+
_scheduler: Any = None
|
|
462
627
|
body_read = False
|
|
463
628
|
|
|
464
629
|
def log_message(self, *args: object) -> None:
|
|
@@ -506,11 +671,143 @@ class _ForwardBase(http.server.BaseHTTPRequestHandler):
|
|
|
506
671
|
except OSError:
|
|
507
672
|
self.close_connection = True
|
|
508
673
|
|
|
674
|
+
def _reply_json(self, code: int, payload: dict[str, Any]) -> None:
|
|
675
|
+
body = json.dumps(payload, separators=(",", ":"), sort_keys=True).encode("utf-8")
|
|
676
|
+
self._safe_reply(code, body)
|
|
677
|
+
|
|
678
|
+
def _control_authorized(self) -> bool:
|
|
679
|
+
expected = self._expected if self._expected is not None else self._control_expected
|
|
680
|
+
if expected is None:
|
|
681
|
+
return True
|
|
682
|
+
given = (self.headers.get("Authorization") or "").encode()
|
|
683
|
+
return hmac.compare_digest(given, expected)
|
|
684
|
+
|
|
685
|
+
def _handle_program_control(self, path: str) -> bool:
|
|
686
|
+
if self.command == "GET" and path == "/programs":
|
|
687
|
+
if not self._control_authorized():
|
|
688
|
+
self._safe_reply(401, b'{"error":{"code":401,"message":"invalid API key"}}')
|
|
689
|
+
return True
|
|
690
|
+
self._reply_json(200, self._scheduler.snapshot())
|
|
691
|
+
return True
|
|
692
|
+
if self.command == "POST" and path == "/programs/release":
|
|
693
|
+
if not self._control_authorized():
|
|
694
|
+
self._safe_reply(401, b'{"error":{"code":401,"message":"invalid API key"}}')
|
|
695
|
+
return True
|
|
696
|
+
self._handle_program_release()
|
|
697
|
+
return True
|
|
698
|
+
return False
|
|
699
|
+
|
|
700
|
+
def _handle_program_release(self) -> None:
|
|
701
|
+
try:
|
|
702
|
+
body = self._read_body()
|
|
703
|
+
except ValueError:
|
|
704
|
+
self.close_connection = True
|
|
705
|
+
self._safe_reply(400, b'{"error":{"code":400,"message":"invalid request body"}}')
|
|
706
|
+
return
|
|
707
|
+
except (EOFError, OSError):
|
|
708
|
+
self.close_connection = True
|
|
709
|
+
return
|
|
710
|
+
try:
|
|
711
|
+
payload = json.loads((body or b"").decode("utf-8"))
|
|
712
|
+
except (UnicodeDecodeError, ValueError):
|
|
713
|
+
self._reply_json(400, {"error": {"code": 400, "message": "invalid JSON"}})
|
|
714
|
+
return
|
|
715
|
+
pid = payload.get("program_id") if isinstance(payload, dict) else None
|
|
716
|
+
if not isinstance(pid, str) or not pid or len(pid) > 256:
|
|
717
|
+
self._reply_json(400, {"error": {"code": 400, "message": "invalid program_id"}})
|
|
718
|
+
return
|
|
719
|
+
found, released = self._scheduler.release_program(pid)
|
|
720
|
+
self._reply_json(
|
|
721
|
+
200,
|
|
722
|
+
{
|
|
723
|
+
"program_id": pid,
|
|
724
|
+
"accepted": found,
|
|
725
|
+
"released": released,
|
|
726
|
+
"deferred": found and not released,
|
|
727
|
+
},
|
|
728
|
+
)
|
|
729
|
+
|
|
730
|
+
def _forward_headers(self) -> dict[str, str]:
|
|
731
|
+
dynamic_hop = _dynamic_hop_headers(self.headers.get_all("Connection") or [])
|
|
732
|
+
excluded = self._dropped | dynamic_hop
|
|
733
|
+
headers = {k: v for k, v in self.headers.items() if k.lower() not in excluded}
|
|
734
|
+
headers["Connection"] = "close"
|
|
735
|
+
return headers
|
|
736
|
+
|
|
737
|
+
def _forward_scheduled_chat(self, body: bytes | None, headers: dict[str, str]) -> None:
|
|
738
|
+
sched = self._scheduler
|
|
739
|
+
ps = _load_program_scheduler()
|
|
740
|
+
raw_pid = (
|
|
741
|
+
self.headers.get("X-Agent-Run-ID") or self.headers.get("X-Session-ID") or ""
|
|
742
|
+
).strip()
|
|
743
|
+
ephemeral = not raw_pid
|
|
744
|
+
pid = sched.next_anonymous_id() if ephemeral else raw_pid
|
|
745
|
+
observer = ps.UsageObserver(ps.request_is_streaming(body))
|
|
746
|
+
prog = sched.get_or_create(pid)
|
|
747
|
+
with prog.request_lock:
|
|
748
|
+
try:
|
|
749
|
+
sched.begin_request(
|
|
750
|
+
prog,
|
|
751
|
+
len(body or b""),
|
|
752
|
+
is_cancelled=lambda: client_gone(self.connection),
|
|
753
|
+
)
|
|
754
|
+
except ps.ProgramCancelledError:
|
|
755
|
+
sched.cancel_waiting_request(prog)
|
|
756
|
+
self.close_connection = True
|
|
757
|
+
return
|
|
758
|
+
except ps.ProgramAdmissionTimeoutError:
|
|
759
|
+
sched.cancel_waiting_request(prog)
|
|
760
|
+
self._reply_json(
|
|
761
|
+
503,
|
|
762
|
+
{
|
|
763
|
+
"error": {
|
|
764
|
+
"code": 503,
|
|
765
|
+
"type": "admission_capacity_timeout",
|
|
766
|
+
"message": "program admission timed out",
|
|
767
|
+
}
|
|
768
|
+
},
|
|
769
|
+
)
|
|
770
|
+
return
|
|
771
|
+
except ps.ProgramReleasedError:
|
|
772
|
+
self._reply_json(
|
|
773
|
+
409,
|
|
774
|
+
{
|
|
775
|
+
"error": {
|
|
776
|
+
"code": 409,
|
|
777
|
+
"type": "program_released",
|
|
778
|
+
"message": "program was released while waiting",
|
|
779
|
+
}
|
|
780
|
+
},
|
|
781
|
+
)
|
|
782
|
+
return
|
|
783
|
+
|
|
784
|
+
try:
|
|
785
|
+
|
|
786
|
+
def on_chunk(chunk: bytes) -> None:
|
|
787
|
+
delta = observer.feed(chunk)
|
|
788
|
+
if delta:
|
|
789
|
+
sched.update_streaming_tokens(prog, delta)
|
|
790
|
+
|
|
791
|
+
if not _proxy_upstream(self, self._upstream, body, headers, on_chunk=on_chunk):
|
|
792
|
+
self._safe_reply(503, b'{"error":{"code":503,"message":"backend not ready"}}')
|
|
793
|
+
finally:
|
|
794
|
+
observer.finish()
|
|
795
|
+
sched.finish_request(
|
|
796
|
+
prog,
|
|
797
|
+
total_tokens=observer.total_tokens,
|
|
798
|
+
prompt_tokens=observer.prompt_tokens,
|
|
799
|
+
)
|
|
800
|
+
if ephemeral:
|
|
801
|
+
sched.release_program(pid)
|
|
802
|
+
|
|
509
803
|
def _forward(self) -> None:
|
|
510
804
|
given = (self.headers.get("Authorization") or "").encode()
|
|
511
805
|
if self._expected is not None and not hmac.compare_digest(given, self._expected):
|
|
512
806
|
self._safe_reply(401, b'{"error":{"code":401,"message":"invalid API key"}}')
|
|
513
807
|
return
|
|
808
|
+
path = self.path.split("?", 1)[0]
|
|
809
|
+
if self._scheduler is not None and self._handle_program_control(path):
|
|
810
|
+
return
|
|
514
811
|
try:
|
|
515
812
|
body = self._read_body()
|
|
516
813
|
except ValueError:
|
|
@@ -520,8 +817,16 @@ class _ForwardBase(http.server.BaseHTTPRequestHandler):
|
|
|
520
817
|
except (EOFError, OSError):
|
|
521
818
|
self.close_connection = True
|
|
522
819
|
return
|
|
523
|
-
headers =
|
|
524
|
-
|
|
820
|
+
headers = self._forward_headers()
|
|
821
|
+
should_schedule = (
|
|
822
|
+
self._scheduler is not None
|
|
823
|
+
and self.command == "POST"
|
|
824
|
+
and path.endswith("/chat/completions")
|
|
825
|
+
and self._control_authorized()
|
|
826
|
+
)
|
|
827
|
+
if should_schedule:
|
|
828
|
+
self._forward_scheduled_chat(body, headers)
|
|
829
|
+
return
|
|
525
830
|
if not _proxy_upstream(self, self._upstream, body, headers):
|
|
526
831
|
self._safe_reply(503, b'{"error":{"code":503,"message":"backend not ready"}}')
|
|
527
832
|
|
|
@@ -529,17 +834,26 @@ class _ForwardBase(http.server.BaseHTTPRequestHandler):
|
|
|
529
834
|
|
|
530
835
|
|
|
531
836
|
def handler(
|
|
532
|
-
key: str | None,
|
|
837
|
+
key: str | None,
|
|
838
|
+
upstream: int,
|
|
839
|
+
*,
|
|
840
|
+
pass_auth: bool = False,
|
|
841
|
+
scheduler: Any = None,
|
|
842
|
+
control_auth_key: str | None = None,
|
|
533
843
|
) -> type[http.server.BaseHTTPRequestHandler]:
|
|
534
844
|
"""The forwarding handler. ``key`` None checks no key here (the upstream checks its own);
|
|
535
|
-
``pass_auth`` lets the caller's Authorization header reach the upstream.
|
|
845
|
+
``pass_auth`` lets the caller's Authorization header reach the upstream. When ``scheduler``
|
|
846
|
+
is provided (opt-in), chat requests pass through program-aware admission control."""
|
|
536
847
|
expected = None if key is None else ("Bearer " + key).encode()
|
|
848
|
+
control_expected = None if not control_auth_key else ("Bearer " + control_auth_key).encode()
|
|
537
849
|
dropped = frozenset(DROPPED - {"authorization"} if pass_auth else DROPPED)
|
|
538
850
|
|
|
539
851
|
class Forward(_ForwardBase):
|
|
540
852
|
_expected = expected
|
|
853
|
+
_control_expected = control_expected
|
|
541
854
|
_upstream = upstream
|
|
542
855
|
_dropped = dropped
|
|
856
|
+
_scheduler = scheduler
|
|
543
857
|
|
|
544
858
|
return Forward
|
|
545
859
|
|
|
@@ -583,24 +897,29 @@ def _log_orphan(expected: int, observed: int) -> None:
|
|
|
583
897
|
|
|
584
898
|
|
|
585
899
|
def main(argv: list[str]) -> int:
|
|
586
|
-
parsed =
|
|
900
|
+
parsed = _parse_cli(argv)
|
|
587
901
|
if parsed is None:
|
|
588
902
|
print(
|
|
589
|
-
"usage: auth_proxy.py [--watchdog-ppid PID]
|
|
903
|
+
"usage: auth_proxy.py [--watchdog-ppid PID] [--program-aware ...] "
|
|
904
|
+
"PORT KEY_FILE -- CMD [ARG...]",
|
|
590
905
|
file=sys.stderr,
|
|
591
906
|
)
|
|
592
907
|
return 2
|
|
593
|
-
port, key_file, cmd, cli_ppid = parsed
|
|
908
|
+
port, key_file, cmd, cli_ppid, program_overrides = parsed
|
|
594
909
|
with open(key_file, encoding="utf-8") as f:
|
|
595
910
|
key = f.read().strip()
|
|
596
911
|
if not key:
|
|
597
912
|
print("auth_proxy: empty key file", file=sys.stderr)
|
|
598
913
|
return 2
|
|
914
|
+
try:
|
|
915
|
+
scheduler = build_program_scheduler(program_overrides)
|
|
916
|
+
except (ImportError, ValueError) as exc:
|
|
917
|
+
print(f"auth_proxy: program-aware scheduler error: {exc}", file=sys.stderr)
|
|
918
|
+
return 2
|
|
599
919
|
expected_ppid = resolve_watchdog_ppid(cli_ppid)
|
|
600
920
|
upstream = free_port()
|
|
601
921
|
# Bound before CMD starts: a port that stays taken ends the proxy with nothing to stop.
|
|
602
|
-
server = bind_server(("127.0.0.1", port), handler(key, upstream))
|
|
603
|
-
server.daemon_threads = True
|
|
922
|
+
server = bind_server(("127.0.0.1", port), handler(key, upstream, scheduler=scheduler))
|
|
604
923
|
# Whisper's conversion scratch files belong beside its deployment key, never in
|
|
605
924
|
# the controller's inherited (possibly sealed) installation directory.
|
|
606
925
|
child = subprocess.Popen(
|
|
@@ -639,9 +958,13 @@ def main(argv: list[str]) -> int:
|
|
|
639
958
|
if should_serve:
|
|
640
959
|
serve_entered = True
|
|
641
960
|
if should_serve:
|
|
961
|
+
if scheduler is not None:
|
|
962
|
+
scheduler.start()
|
|
642
963
|
threading.Thread(target=watch, daemon=True).start()
|
|
643
964
|
server.serve_forever()
|
|
644
965
|
finally:
|
|
966
|
+
if scheduler is not None:
|
|
967
|
+
scheduler.stop()
|
|
645
968
|
if watchdog_stop is not None:
|
|
646
969
|
watchdog_stop.set()
|
|
647
970
|
server.server_close()
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
]
|
|
78
78
|
},
|
|
79
79
|
"decode_fraction": 1.0,
|
|
80
|
+
"architecture": "qwen35",
|
|
80
81
|
"n_embd": 5120,
|
|
81
82
|
"tied_embeddings": false,
|
|
82
83
|
"ssm_d_inner": 6144,
|
|
@@ -148,6 +149,7 @@
|
|
|
148
149
|
]
|
|
149
150
|
},
|
|
150
151
|
"decode_fraction": 1.0,
|
|
152
|
+
"architecture": "qwen35",
|
|
151
153
|
"n_embd": 5120,
|
|
152
154
|
"tied_embeddings": false,
|
|
153
155
|
"ssm_d_inner": 6144,
|
|
@@ -231,6 +233,7 @@
|
|
|
231
233
|
]
|
|
232
234
|
},
|
|
233
235
|
"decode_fraction": 1.0,
|
|
236
|
+
"architecture": "qwen35",
|
|
234
237
|
"n_embd": 5120,
|
|
235
238
|
"tied_embeddings": false,
|
|
236
239
|
"ssm_d_inner": 6144,
|
|
@@ -749,6 +752,8 @@
|
|
|
749
752
|
"per_layer_f16": 1152,
|
|
750
753
|
"moe": true,
|
|
751
754
|
"n_vocab": 163840,
|
|
755
|
+
"architecture": "deepseek4",
|
|
756
|
+
"kv_k_only": true,
|
|
752
757
|
"draft": {
|
|
753
758
|
"path": "dspark-DeepSeek-V4-Flash-0731-Q8_0.gguf",
|
|
754
759
|
"size_bytes": 10896057440,
|
|
@@ -1351,7 +1356,7 @@
|
|
|
1351
1356
|
"n_ctx_train": 131072,
|
|
1352
1357
|
"full_layers": 6,
|
|
1353
1358
|
"recurrent_layers": 18,
|
|
1354
|
-
"per_layer_f16":
|
|
1359
|
+
"per_layer_f16": 1152,
|
|
1355
1360
|
"swa_layers": 0,
|
|
1356
1361
|
"swa_window": 0,
|
|
1357
1362
|
"moe": true,
|
|
@@ -1359,6 +1364,7 @@
|
|
|
1359
1364
|
"architecture": "bailingmoe3",
|
|
1360
1365
|
"n_embd": 1536,
|
|
1361
1366
|
"tied_embeddings": false,
|
|
1367
|
+
"kv_k_only": true,
|
|
1362
1368
|
"sampling": {
|
|
1363
1369
|
"top-k": "20",
|
|
1364
1370
|
"top-p": "0.95",
|
|
@@ -4458,8 +4464,8 @@
|
|
|
4458
4464
|
"vision": true
|
|
4459
4465
|
}
|
|
4460
4466
|
],
|
|
4461
|
-
"engine": "strata-poly-0.2.20-poly.
|
|
4462
|
-
"venv": "strata-poly-serve-0.2.20-poly.
|
|
4467
|
+
"engine": "strata-poly-0.2.20-poly.7",
|
|
4468
|
+
"venv": "strata-poly-serve-0.2.20-poly.7.txt",
|
|
4463
4469
|
"venv_bytes": 41943040,
|
|
4464
4470
|
"alias": "inkling-2-mini-ud-q4_k_xl",
|
|
4465
4471
|
"contract": "chat",
|
|
@@ -4539,7 +4545,7 @@
|
|
|
4539
4545
|
],
|
|
4540
4546
|
"health_path": "/health",
|
|
4541
4547
|
"verify_timeout_s": 1800,
|
|
4542
|
-
"note": "Thinking Machines Inkling 2 Mini UD-Q4_K_XL (Mainline_Support inkling2_loop, 5.41 BPW) on PolyStrata v0.2.20-poly.
|
|
4548
|
+
"note": "Thinking Machines Inkling 2 Mini UD-Q4_K_XL (Mainline_Support inkling2_loop, 5.41 BPW) on PolyStrata v0.2.20-poly.7 for 24 GB+ NVIDIA CUDA 13 cards (driver >= 580) with 128K FP8 KV cache and native vision (strata-vision GPU on >= 23.5 GiB cards, CPU below). Default concurrency is 2 parallel requests (parallel: 2 -> --batch 2); --prefer concurrent still falls back to llama.cpp Inkling 2 Mini pending live concurrent benchmarks.\nMeasured on local-118 GPU0 24 GB share (2026-11-23-polystrata-inkling2-mini-local118): all 3072/3072 routed experts fit in VRAM (14.7 GiB, 0.0 GiB offloaded), strata-vision GPU 791 MiB, whole-card peak 21,601 MiB across 58.4K and 105.6K prompts (2,463 MiB below the 24 GB gate), anonymous host RAM peak 1.7 GiB, 176.4 tok/s short decode, 6,869 tok/s prefill and 138.8 tok/s decode after 58.4K prompt (needle hit, vision and tool calling passed). Promoted above same-score llama.cpp Inkling on supported CUDA 13 NVIDIA hosts by roadmap decision 66.\nLinux enables --vram-pool via card_args (INK2VP, 2026-11-30-ink2-q4xl-vrampool-lab12021, physical RTX 4090 D 24 GB, parallel=2, GPU strata-vision 1,162 MiB): without --vram-pool whole-card VRAM peaks at 23,757-23,761 MiB (~205 MiB over the 23,552 MiB gate, leaving ~803 MiB free); with --vram-pool whole-card peak stays flat at 23,035-23,057 MiB across 2,582 samples (1,507 MiB free, 0 foreign MiB, oom_kill=0) with identical 1K-120K decode 122.4->86.1 tok/s, NIAH 4/4, 2x56K/2x100K/2x120K HTTP 200, 100K prefill interference 39.85 tok/s, and agentloop 9/9. Windows runs without --vram-pool until verified on a physical 24 GB Windows card.",
|
|
4543
4549
|
"quality": {
|
|
4544
4550
|
"score": 53,
|
|
4545
4551
|
"sources": [
|
|
@@ -4608,8 +4614,8 @@
|
|
|
4608
4614
|
"vision": true
|
|
4609
4615
|
}
|
|
4610
4616
|
],
|
|
4611
|
-
"engine": "strata-poly-0.2.20-poly.
|
|
4612
|
-
"venv": "strata-poly-serve-0.2.20-poly.
|
|
4617
|
+
"engine": "strata-poly-0.2.20-poly.7",
|
|
4618
|
+
"venv": "strata-poly-serve-0.2.20-poly.7.txt",
|
|
4613
4619
|
"venv_bytes": 41943040,
|
|
4614
4620
|
"alias": "inkling-2-mini-ud-q3_k_xl",
|
|
4615
4621
|
"contract": "chat",
|
|
@@ -4691,7 +4697,7 @@
|
|
|
4691
4697
|
],
|
|
4692
4698
|
"health_path": "/health",
|
|
4693
4699
|
"verify_timeout_s": 1800,
|
|
4694
|
-
"note": "Thinking Machines Inkling 2 Mini UD-Q3_K_XL (Mainline_Support inkling2_loop, 4.18 BPW) on PolyStrata v0.2.20-poly.
|
|
4700
|
+
"note": "Thinking Machines Inkling 2 Mini UD-Q3_K_XL (Mainline_Support inkling2_loop, 4.18 BPW) on PolyStrata v0.2.20-poly.7 for 8, 12 and 16 GB NVIDIA CUDA 13 cards (driver >= 580) with >= 24 GB RAM. Uses 64K FP8 KV cache, --vram-pool (caps prefill staging and KV growth strictly inside the card budget), --ram-experts-mib 6144, --tail-skip 0, and CPU strata-vision on < 23.5 GiB cards. Default concurrency is 2 parallel requests (parallel: 2 -> --batch 2) and LoopCD-Hidden (--loopcd-hidden 0.2) is enabled by default.\nMeasured on local-118 GPU0 stand-in shares (2026-11-23-polystrata-inkling2-mini-local118, 58.4K prompt needle + vision + tool calls all passed): 16 GB share 3058/3072 experts in VRAM, peak 14,498 MiB (1,374 MiB below gate), 178.3 tok/s short / 61.1 tok/s at 58.4K; 12 GB share 1977/3072 experts, peak 10,388 MiB, 138.7 / 47.0 tok/s; 8 GB share 896/3072 experts, peak 6,292 MiB (1,388 MiB below gate), cgroup peak 8.7 GiB / anon 8.4 GiB, 65.6 / 30.3 tok/s (server-class CPU stand-in upper bound; upstream RTX 4070 Laptop 8 GB measured 56 / 42 tok/s). Promoted by roadmap decision 66.\nWindows runs without --vram-pool (card_args keeps it on Linux). PSIW (2026-11-23, RTX 4070 Laptop 8 GB, Windows 11): with it the engine claims a 13,204 MiB pool from the process budget Windows reports, larger than the card, and every request longer than about 30 tokens gets \"no VRAM for a prompt's buffers\"; stack apply failed 3 times out of 3 on the 0.2.19-poly.1 and 0.2.20-poly.1 engines. Without it, on 0.2.19-poly.1: plain text of 54 to 31,022 tokens, Chinese, the CPU picture reader, a tool call and a needle in a 54K-token prompt all pass, card peak 6,966-7,001 MiB of 8,188. PolyStrata's main fixes the engine side (5b080f37b) for its next release.",
|
|
4695
4701
|
"quality": {
|
|
4696
4702
|
"score": 53,
|
|
4697
4703
|
"sources": [
|
|
@@ -4759,8 +4765,8 @@
|
|
|
4759
4765
|
"vision": true
|
|
4760
4766
|
}
|
|
4761
4767
|
],
|
|
4762
|
-
"engine": "strata-poly-0.2.20-poly.
|
|
4763
|
-
"venv": "strata-poly-serve-0.2.20-poly.
|
|
4768
|
+
"engine": "strata-poly-0.2.20-poly.7",
|
|
4769
|
+
"venv": "strata-poly-serve-0.2.20-poly.7.txt",
|
|
4764
4770
|
"venv_bytes": 41943040,
|
|
4765
4771
|
"alias": "inkling-2-mini-ud-q2_k_xl",
|
|
4766
4772
|
"contract": "chat",
|
|
@@ -4842,7 +4848,7 @@
|
|
|
4842
4848
|
],
|
|
4843
4849
|
"health_path": "/health",
|
|
4844
4850
|
"verify_timeout_s": 1800,
|
|
4845
|
-
"note": "DEPRECATED from --llm auto and Model Library recommendations (roadmap decision 70, 2026-11-27): at 2.80 BPW (IQ1_S in blk.0-6 including loop-entry blk.6, IQ2_XXS/T42 in loop layers, Unsloth KLD 0.0595 = 5.56x Q4), paired PolyStrata v0.2.20-poly.5 evaluation (2026-11-26, local-118 GPU0 stand-in) showed BFCL v4 MT-Hard collapsing from 36.0% (72/200) to 19.0% (38/200, -17.0 pp, 95% CI [-24.0, -10.0], McNemar p=5e-6) with 30 consecutive identical tool-call loop steps (Q4: 0), 1 force-terminated infinite loop, +40% empty turns (35 vs 25), C-Eval 520 -3.08 pp (73.85% vs 76.92%, p=0.0195), Chinese-to-English flips under card sampling, and further 8 GB CPU-offload regressions (30/36 diag, extra code truncation and wrong tool call). Kept as deprecated on PolyStrata v0.2.20-poly.
|
|
4851
|
+
"note": "DEPRECATED from --llm auto and Model Library recommendations (roadmap decision 70, 2026-11-27): at 2.80 BPW (IQ1_S in blk.0-6 including loop-entry blk.6, IQ2_XXS/T42 in loop layers, Unsloth KLD 0.0595 = 5.56x Q4), paired PolyStrata v0.2.20-poly.5 evaluation (2026-11-26, local-118 GPU0 stand-in) showed BFCL v4 MT-Hard collapsing from 36.0% (72/200) to 19.0% (38/200, -17.0 pp, 95% CI [-24.0, -10.0], McNemar p=5e-6) with 30 consecutive identical tool-call loop steps (Q4: 0), 1 force-terminated infinite loop, +40% empty turns (35 vs 25), C-Eval 520 -3.08 pp (73.85% vs 76.92%, p=0.0195), Chinese-to-English flips under card sampling, and further 8 GB CPU-offload regressions (30/36 diag, extra code truncation and wrong tool call). Kept as deprecated on PolyStrata v0.2.20-poly.7 (parallel: 2, --loopcd-hidden 0.2) for explicit --llm, approved-plan resume, and on-disk library management.\nHistorical calibration (SP219, 2026-11-23-polystrata-inkling2-mini-local118, local-118 GPU0 8 GB share inside a 14 GiB cgroup): 1428/3072 experts in VRAM, whole-card peak 6,294 MiB (1,386 MiB below gate), cgroup peak 6.8 GiB / anon 6.5 GiB, 112.8 tok/s short / 3,836 tok/s prefill / 45.5 tok/s decode after 58.4K prompt (needle hit, vision and tool calls passed). Originally added by roadmap decision 66.\nWindows runs without --vram-pool (card_args keeps it on Linux). PSIW (2026-11-23, RTX 4070 Laptop 8 GB, Windows 11, engine 0.2.19-poly.1): with it the engine claims a 9,092 MiB pool from the process budget Windows reports, larger than the card, stack apply fails and every request longer than about 30 tokens gets \"no VRAM for a prompt's buffers\". Without it, plain text of 54 to 31,022 tokens, Chinese, the CPU picture reader, a tool call and a needle in a 54K-token prompt all pass, card peak 6,992-7,033 MiB of 8,188. PolyStrata's main fixes the engine side (5b080f37b) for its next release.",
|
|
4846
4852
|
"quality": {
|
|
4847
4853
|
"score": 47,
|
|
4848
4854
|
"sources": [
|
|
@@ -272,6 +272,7 @@ def _launch(
|
|
|
272
272
|
parking_mib: int,
|
|
273
273
|
added_mib: int,
|
|
274
274
|
) -> dict[str, object]:
|
|
275
|
+
vram, floor = suite.gpu_bytes(r, reader)
|
|
275
276
|
return {
|
|
276
277
|
"window": r.get("context", 0),
|
|
277
278
|
"spilled": False,
|
|
@@ -279,8 +280,9 @@ def _launch(
|
|
|
279
280
|
"reasons": [r.get("note", "")],
|
|
280
281
|
"threads": int(values["threads"]),
|
|
281
282
|
"memory_estimate_bytes": r["memory_estimate_bytes"] + (added_mib << 20),
|
|
282
|
-
"vram_bytes":
|
|
283
|
-
|
|
283
|
+
"vram_bytes": vram,
|
|
284
|
+
# PolyStrata: vram_bytes is the expert cache's ceiling; this is the least it starts in.
|
|
285
|
+
**({"min_vram_free_bytes": floor} if floor else {}),
|
|
284
286
|
**({"preparation": _formatted(r["preparation"], values)} if r.get("preparation") else {}),
|
|
285
287
|
**({"conversation_cache_mib": parking_mib} if r.get("conversation_cache") else {}),
|
|
286
288
|
**adapter_for(r["runtime"]).launch_keys(profile),
|