Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

fix(bench): preserve empty LoRA slot evidence

svonava86d04424761c
diff --git a/tools/benchmarks/runtime_lora/observer.py b/tools/benchmarks/runtime_lora/observer.py
index 3591a4093..545196f26 100644
--- a/tools/benchmarks/runtime_lora/observer.py
+++ b/tools/benchmarks/runtime_lora/observer.py
@@ -22,6 +22,15 @@ MARKER = "_sie_runtime_lora_benchmark"
TRACE_ENV = "SIE_RUNTIME_LORA_BATCH_TRACE"
+def slot_uid(uid: Any) -> str | None | dict[str, bool]:
+ if uid is None or isinstance(uid, str):
+ return uid
+ module = sys.modules.get("sglang.srt.lora.mem_pool")
+ if module is not None and uid is getattr(module, "EMPTY_SLOT", None):
+ return {"empty_slot": True}
+ raise ValueError("Unexpected value in the SGLang LoRA GPU slot map")
+
+
def append(path: str, row: dict[str, Any]) -> None:
data = (json.dumps(row, sort_keys=True) + "\n").encode()
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0o600)
@@ -44,7 +53,7 @@ def patch_scheduler(module: ModuleType, path: str) -> None:
def alias(uid: str | None) -> str | None:
return manager.lora_refs[uid].lora_name if uid is not None else None
- row = {
+ row: dict[str, Any] = {
"event": "forward",
"pid": os.getpid(),
"start_ns": time.time_ns(),
@@ -55,7 +64,7 @@ def patch_scheduler(module: ModuleType, path: str) -> None:
row["end_ns"] = time.time_ns()
pool = manager.memory_pool
row["gpu_slot_count"] = len(pool.buffer_id_to_uid)
- row["gpu_slot_uids"] = list(pool.buffer_id_to_uid)
+ row["gpu_slot_uids"] = [slot_uid(uid) for uid in pool.buffer_id_to_uid]
row["gpu_slots"] = [
{"uid": uid, "lora": alias(uid), "slot": slot} for uid, slot in pool.uid_to_buffer_id.items()
]
diff --git a/tools/benchmarks/runtime_lora/probe.py b/tools/benchmarks/runtime_lora/probe.py
index 18149716a..c37d09a60 100644
--- a/tools/benchmarks/runtime_lora/probe.py
+++ b/tools/benchmarks/runtime_lora/probe.py
@@ -506,6 +506,7 @@ async def run(args: argparse.Namespace) -> None:
summary["error"] = {"type": type(error).__name__, "message": str(error)}
raise
finally:
+ summary["assertions_passed"] = summary["passed"]
summary["shutdown_complete"] = False
(output / "evidence.json").write_text(json.dumps(summary, indent=2) + "\n")
server.should_exit = True
@@ -514,6 +515,7 @@ async def run(args: argparse.Namespace) -> None:
await task
summary["shutdown_complete"] = True
except BaseException as error:
+ summary["passed"] = False
summary["shutdown_error"] = {"type": type(error).__name__, "message": str(error)}
raise
finally:
diff --git a/tools/benchmarks/runtime_lora/tests/test_probe.py b/tools/benchmarks/runtime_lora/tests/test_probe.py
index 18e23ff5b..99cf5b1f2 100644
--- a/tools/benchmarks/runtime_lora/tests/test_probe.py
+++ b/tools/benchmarks/runtime_lora/tests/test_probe.py
@@ -132,7 +132,9 @@ def test_sdk_observer_captures_msgpack_selection_and_automatic_encode_retry(
client.close()
-def test_observer_records_actual_successful_batch_and_does_not_change_result(tmp_path: Path) -> None:
+def test_observer_records_actual_successful_batch_and_does_not_change_result(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
trace = tmp_path / "batches.jsonl"
result = object()
seen = []
@@ -178,6 +180,18 @@ def test_observer_records_actual_successful_batch_and_does_not_change_result(tmp
rows[0]["gpu_slots"][1]["slot"] = 1
rows[0]["requests"][1]["lora"] = "a"
assert mixed_batches(rows, 0, 2**64) == []
+ pool_module = ModuleType("sglang.srt.lora.mem_pool")
+ pool_module.EMPTY_SLOT = object()
+ monkeypatch.setitem(sys.modules, pool_module.__name__, pool_module)
+ pool = scheduler.tp_worker.model_runner.lora_manager.memory_pool
+ pool.buffer_id_to_uid = [None, pool_module.EMPTY_SLOT]
+ pool.uid_to_buffer_id = {None: 0}
+ batch.reqs = [SimpleNamespace(rid="base", lora_id=None)]
+ assert scheduler.run_batch(batch) is result
+ base_row = batch_rows(trace)[-1]
+ assert base_row["gpu_slot_uids"] == [None, {"empty_slot": True}]
+ assert base_row["gpu_slots"] == [{"lora": None, "slot": 0, "uid": None}]
+ assert mixed_batches([base_row], 0, 2**64) == []
def test_child_observer_defers_import_and_preserves_production_hook(tmp_path: Path) -> None: