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(models): restore SGLang KV capacity for Mistral embedders and GLM-OCR (#853)

Krisztian Gajdarbe5501ad84ba
diff --git a/packages/sie_server/README.md b/packages/sie_server/README.md
index 391ad2a1a..628ddf04d 100644
--- a/packages/sie_server/README.md
+++ b/packages/sie_server/README.md
@@ -1191,6 +1191,13 @@ reservation and evicts idle eligible models when it cannot fit. Resident-model
accounting reports the reservation; the pressure monitor continues to use
actual device usage, including every SGLang subprocess.
+The `max_seq_length` fallback holds one maximum-length sequence. Declare
+`kv_budget_tokens` when a profile keeps more tokens in flight than that. An
+automatically sized embedding profile must hold two full batches
+(`2 * max_batch_tokens`), which the model configuration tests enforce. A
+vision-extraction profile that runs many full pages at once can set an explicit
+fraction instead.
+
To dedicate most of a GPU to one model, explicitly set a fraction:
```yaml
diff --git a/packages/sie_server/models/Salesforce__SFR-Embedding-Mistral.yaml b/packages/sie_server/models/Salesforce__SFR-Embedding-Mistral.yaml
index e710f6ff7..72086293b 100644
--- a/packages/sie_server/models/Salesforce__SFR-Embedding-Mistral.yaml
+++ b/packages/sie_server/models/Salesforce__SFR-Embedding-Mistral.yaml
@@ -18,6 +18,14 @@ max_sequence_length: 4096
profiles:
default:
max_batch_tokens: 16384
+ # Without a budget the automatic KV pool is max_sequence_length (4096
+ # tokens), a quarter of one 16384-token batch, and the first batches
+ # stall past the encode read timeout. 32768 holds two full batches and
+ # matches the pool SFR-Embedding-2_R and Linq-Embed-Mistral derive from
+ # their 32768-token context on the same Mistral-7B geometry.
+ # Reservation in bf16: 13.9 GiB weights + 4.1 GiB KV (128 KiB per token)
+ # + 3 GiB headroom, about 21 GiB.
+ kv_budget_tokens: 32768
compute_precision: bfloat16
adapter_path: sie_server.adapters.sglang.embedding:SGLangEmbeddingAdapter
adapter_options:
diff --git a/packages/sie_server/models/intfloat__e5-mistral-7b-instruct.yaml b/packages/sie_server/models/intfloat__e5-mistral-7b-instruct.yaml
index 8d65b59a9..696a1acbf 100644
--- a/packages/sie_server/models/intfloat__e5-mistral-7b-instruct.yaml
+++ b/packages/sie_server/models/intfloat__e5-mistral-7b-instruct.yaml
@@ -18,6 +18,14 @@ max_sequence_length: 4096
profiles:
default:
max_batch_tokens: 16384
+ # Without a budget the automatic KV pool is max_sequence_length (4096
+ # tokens), a quarter of one 16384-token batch, and the first batches
+ # stall past the encode read timeout. 32768 holds two full batches and
+ # matches the pool SFR-Embedding-2_R and Linq-Embed-Mistral derive from
+ # their 32768-token context on the same Mistral-7B geometry.
+ # Reservation in bf16: 13.9 GiB weights + 4.1 GiB KV (128 KiB per token)
+ # + 3 GiB headroom, about 21 GiB.
+ kv_budget_tokens: 32768
compute_precision: bfloat16
adapter_path: sie_server.adapters.sglang.embedding:SGLangEmbeddingAdapter
adapter_options:
diff --git a/packages/sie_server/models/zai-org__GLM-OCR.yaml b/packages/sie_server/models/zai-org__GLM-OCR.yaml
index f3892e22e..091b03b0a 100644
--- a/packages/sie_server/models/zai-org__GLM-OCR.yaml
+++ b/packages/sie_server/models/zai-org__GLM-OCR.yaml
@@ -27,6 +27,9 @@ profiles:
adapter_path: sie_server.adapters.sglang_vision_extract.adapter:SGLangVisionExtractAdapter
adapter_options:
loadtime:
+ # 64 pages in flight, each up to 16384 tokens of page image and output,
+ # need far more KV than the automatic one-sequence pool of 16384.
+ mem_fraction_static: 0.85
served_model_name: zai-org/GLM-OCR
max_concurrent_requests: 64
# SGLang's default fast (torch) image processor. The slow PIL processor runs
diff --git a/packages/sie_server/tests/config/test_sglang_memory_profiles.py b/packages/sie_server/tests/config/test_sglang_memory_profiles.py
index 962f85d47..c3175e34a 100644
--- a/packages/sie_server/tests/config/test_sglang_memory_profiles.py
+++ b/packages/sie_server/tests/config/test_sglang_memory_profiles.py
@@ -23,6 +23,8 @@ L4_TOTAL_BYTES = 23034 * 1024**2
"Qwen__Qwen3-Embedding-8B",
"lightonai__LightOnOCR-2-1B",
"tencent__Hy-MT2-1.8B",
+ "intfloat__e5-mistral-7b-instruct",
+ "Salesforce__SFR-Embedding-Mistral",
],
)
def test_default_profiles_use_model_sized_memory(name):
@@ -58,6 +60,53 @@ def test_hy_mt2_pool_fits_an_l4_with_room_for_translation_batches(tmp_path, monk
assert budget.launch_args(0)[2:] == ["--max-total-tokens", "32768"]
+SGLANG_EMBEDDING_MODELS = sorted(
+ path.stem for path in MODELS.glob("*.yaml") if ":SGLangEmbeddingAdapter" in path.read_text()
+)
+
+
[email protected]("name", SGLANG_EMBEDDING_MODELS)
+def test_model_sized_embedding_pools_hold_two_full_batches(name):
+ config = load_model_config(MODELS / f"{name}.yaml")
+ for sie_id, variant in expand_profile_variants([config]).items():
+ profile = variant.resolve_profile("default")
+ if not profile.adapter_path.endswith(":SGLangEmbeddingAdapter") or "mem_fraction_static" in profile.loadtime:
+ continue
+ budget = load_adapter(variant, MODELS, device="cuda:0")._memory_budget
+ assert budget.token_capacity >= 2 * profile.max_batch_tokens, (
+ f"{sie_id}: KV pool of {budget.token_capacity} tokens is under two batches of "
+ f"{profile.max_batch_tokens}; declare kv_budget_tokens"
+ )
+
+
[email protected]("name", ["intfloat__e5-mistral-7b-instruct", "Salesforce__SFR-Embedding-Mistral"])
+def test_mistral_embedder_pool_fits_a_24gb_gpu(name, tmp_path, monkeypatch):
+ config = load_model_config(MODELS / f"{name}.yaml")
+ assert config.resolve_profile("default").kv_budget_tokens == 32768
+ (tmp_path / "config.json").write_text(
+ json.dumps({"num_hidden_layers": 32, "num_attention_heads": 32, "num_key_value_heads": 8, "hidden_size": 4096})
+ )
+ params = 7_110_660_096
+ header = json.dumps(
+ {"model.weight": {"dtype": "BF16", "shape": [params], "data_offsets": [0, params * 2]}}
+ ).encode()
+ (tmp_path / "model.safetensors").write_bytes(struct.pack("<Q", len(header)) + header)
+ budget = load_adapter(config, MODELS, device="cuda:0")._memory_budget
+ budget.model_name_or_path = str(tmp_path)
+
+ required = budget.required_bytes(device_type="cuda", device_total_bytes=L4_TOTAL_BYTES)
+ assert required == math.ceil(params * 2 * 1.05) + (32768 + 512) * 131072 + 3 * GIB
+ assert required < 21 * GIB
+ monkeypatch.setattr(_memory, "device_memory", lambda _: (L4_TOTAL_BYTES - GIB, L4_TOTAL_BYTES))
+ assert budget.launch_args(0)[2:] == ["--max-total-tokens", "32768"]
+
+
+def test_glm_ocr_launches_with_its_explicit_fraction():
+ config = load_model_config(MODELS / "zai-org__GLM-OCR.yaml")
+ budget = load_adapter(config, MODELS, device="cuda:0")._memory_budget
+ assert budget.launch_args(0) == ["--mem-fraction-static", "0.85"]
+
+
def test_guard_calibrated_profile_retains_explicit_override():
config = load_model_config(MODELS / "Qwen__Qwen3Guard-Gen-4B.yaml")
assert config.resolve_profile("default").kv_budget_tokens == 32768
@@ -79,7 +128,9 @@ def test_extending_profile_forwards_its_resolved_kv_budget():
assert adapter._memory_budget.kv_budget_tokens == 65536
[email protected]("name", ["Qwen__Qwen3.5-4B", "lightonai__LightOnOCR-3-4B", "Qwen__Qwen3-VL-8B-Instruct"])
+ "name", ["Qwen__Qwen3.5-4B", "lightonai__LightOnOCR-3-4B", "Qwen__Qwen3-VL-8B-Instruct", "zai-org__GLM-OCR"]
+)
def test_specialized_profiles_retain_calibrated_reservation(name):
config = load_model_config(MODELS / f"{name}.yaml")
assert config.resolve_profile("default").loadtime["mem_fraction_static"] == 0.85