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(sglang): preserve startup-only LoRA capacity

svonavaae6064cb802d
diff --git a/packages/sie_server/README.md b/packages/sie_server/README.md
index 433f5c279..c8a932c1f 100644
--- a/packages/sie_server/README.md
+++ b/packages/sie_server/README.md
@@ -1157,7 +1157,6 @@ auto-retries; see `packages/sie_sdk/README.md` for client-side controls.
| `SIE_MAX_BATCH_WAIT_MS` | `15.0` | Initial value for the adaptive first-request batch timeout. At runtime the PI batching controller steers it between `SIE_ADAPTIVE_BATCHING__MIN_WAIT_MS` and `SIE_ADAPTIVE_BATCHING__MAX_WAIT_MS`, so it is a starting point rather than a fixed wait. |
| `SIE_MAX_CONCURRENT_REQUESTS` | `512` | Per-worker queue size; admission control returns `QUEUE_FULL` above this. |
| `SIE_MAX_LORAS_PER_MODEL` | `10` | Maximum concurrent LoRA adapters per base model. A request loads or selects only the adapters its selected profile declares. `options.lora` or `options.lora_id` naming any other is rejected with HTTP 400: `INVALID_INPUT` from this server, and `INVALID_REQUEST` from the gateway (code `unknown_lora_adapter` where it answers in the OpenAI error envelope). |
-
| `SIE_MAX_ITEM_TEXT_BYTES` | `2097152` (2 MiB) | Most bytes of UTF-8 one encode, score, or extract item may carry in its `text` and `metadata` together. A larger item is rejected with `INVALID_INPUT` (HTTP 400) before it is tokenized. Generation prompts are not items and are not affected. |
SGLang generation and embedding profiles can defer declared LoRAs until a
@@ -1188,13 +1187,17 @@ options when changing only a child's preload selection.
Deferred adapters require the maximum rank and target modules at engine launch
because SGLang allocates its LoRA buffers then. LoRA profiles require an explicit
-memory fraction. The resolved `max_loras_per_model` engine setting (normally
-`SIE_MAX_LORAS_PER_MODEL`) bounds resident adapters, including pinned preloads
+memory fraction. For profiles with deferred adapters, the resolved
+`max_loras_per_model` engine setting (normally `SIE_MAX_LORAS_PER_MODEL`)
+bounds resident adapters, including pinned preloads
and in-flight loads; `max_loras_per_batch` and the preload count cannot exceed
it. When full, SIE drains and evicts the least-recently-used unpinned adapter. An
adapter being loaded or drained retains its slot, and all-pinned/full capacity
returns a retry response. Unconfirmed attach rollback or unload retains the
slot and requires a model reload rather than risking unbounded residency.
+Startup-only profiles retain every declared adapter: their effective capacity
+is at least the pinned source count and `max_loras_per_batch`, even when the
+configured runtime limit is lower.
Generation and chat requests select a selected-profile declared name with
`lora_adapter` (a served alias or its declared source id);
diff --git a/packages/sie_server/src/sie_server/adapters/sglang/_lora.py b/packages/sie_server/src/sie_server/adapters/sglang/_lora.py
index 07c76f856..27e387ece 100644
--- a/packages/sie_server/src/sie_server/adapters/sglang/_lora.py
+++ b/packages/sie_server/src/sie_server/adapters/sglang/_lora.py
@@ -150,11 +150,16 @@ class SGLangLoraManager:
self.revisions = revisions or {}
self.preloaded = frozenset(self.aliases[name] for name in (self.aliases if preload is None else preload))
self.deferred = set(self.aliases.values()) - self.preloaded
- self.max_loaded = max_loaded if max_loaded is not None else int(os.environ.get("SIE_MAX_LORAS_PER_MODEL", "10"))
- if isinstance(self.max_loaded, bool) or not isinstance(self.max_loaded, int) or self.max_loaded < 1:
+ configured = max_loaded if max_loaded is not None else int(os.environ.get("SIE_MAX_LORAS_PER_MODEL", "10"))
+ if isinstance(configured, bool) or not isinstance(configured, int) or configured < 1:
raise ValueError("SIE_MAX_LORAS_PER_MODEL must be positive")
if isinstance(max_per_batch, bool) or not isinstance(max_per_batch, int) or max_per_batch < 1:
raise ValueError("max_loras_per_batch must be a positive integer")
+ # Startup-only profiles historically load every declared adapter. The
+ # runtime residency limit must not reject their pinned set or batch size.
+ self.max_loaded = (
+ max(configured, len(self.preloaded), max_per_batch) if self.aliases and not self.deferred else configured
+ )
if self.aliases and (max_per_batch > self.max_loaded or len(self.preloaded) > self.max_loaded):
raise ValueError("LoRA batch capacity and preload count must not exceed SIE_MAX_LORAS_PER_MODEL")
if self.deferred and len(self.preloaded) == self.max_loaded:
diff --git a/packages/sie_server/tests/adapters/test_sglang_lora.py b/packages/sie_server/tests/adapters/test_sglang_lora.py
index 2c7ed3bc0..eb916b9fa 100644
--- a/packages/sie_server/tests/adapters/test_sglang_lora.py
+++ b/packages/sie_server/tests/adapters/test_sglang_lora.py
@@ -18,7 +18,7 @@ from sie_server.adapters.sglang.generation import SGLangGenerationAdapter
def manager(**kwargs):
return SGLangLoraManager(
- {"a": "org/a", "b": "org/b"},
+ kwargs.pop("paths", {"a": "org/a", "b": "org/b"}),
preload=kwargs.pop("preload", []),
revisions={"org/a": "a" * 40},
max_rank=8,
@@ -56,6 +56,50 @@ def test_omitted_selector_preloads_and_pins_existing_sources(monkeypatch):
loras.unload("a")
[email protected]("explicit_preload", [False, True])
+ ("count", "max_per_batch", "configured", "expected"),
+ [(12, 2, None, 12), (2, 16, 3, 16), (2, 2, 1, 2)],
+)
+def test_startup_only_capacity_preserves_all_pinned_sources_and_batch_size(
+ monkeypatch, explicit_preload, count, max_per_batch, configured, expected
+):
+ monkeypatch.setenv("SIE_MAX_LORAS_PER_MODEL", "10")
+ paths = {f"adapter{i}": f"org/adapter{i}" for i in range(count)}
+ loras = manager(
+ paths=paths,
+ preload=list(paths) if explicit_preload else None,
+ max_loaded=configured,
+ max_per_batch=max_per_batch,
+ )
+ monkeypatch.setattr(loras, "fetch", lambda source: "/cache/" + source.rsplit("/", 1)[1])
+ args = loras.launch_args()
+ assert args[args.index("--max-loaded-loras") + 1] == str(expected)
+ assert args[args.index("--max-loras-per-batch") + 1] == str(max_per_batch)
+ assert set(args[args.index("--lora-paths") + 1 :]) == {f"{alias}=/cache/{alias}" for alias in paths}
+ config = loras.runtime_config()
+ assert config.max_loaded == expected
+ assert config.preloaded == config.pinned == frozenset(paths.values())
+
+
[email protected]("preload", [[], ["a"]])
+def test_deferred_capacity_remains_configured_even_with_more_declared_sources(preload):
+ paths = {"a": "org/a", "b": "org/b", "c": "org/c", "d": "org/d"}
+ loras = manager(paths=paths, preload=preload, max_loaded=3)
+ assert loras.runtime_config().max_loaded == 3
+ with pytest.raises(ValueError, match="must not exceed"):
+ manager(paths=paths, preload=preload, max_loaded=3, max_per_batch=4)
+ with pytest.raises(ValueError, match="must not exceed"):
+ manager(paths=paths, preload=["a", "b", "c"], max_loaded=2)
+
+
[email protected]("field", ["max_loaded", "max_per_batch"])
[email protected]("invalid", [True, 0, -1, 1.5, "3"])
+def test_startup_only_capacity_does_not_mask_invalid_limits(field, invalid):
+ with pytest.raises(ValueError, match="positive"):
+ manager(preload=None, **{field: invalid})
+
+
def test_undeclared_source_never_fetches_or_calls_engine(monkeypatch):
fetch = Mock()
post = Mock()