Просмотр исходного кода

dsv41-flash-1017-4x-sglang: [mods] patch aligning the 1.7.1 image's DSV4.1 encoder with the 1017 reference protocol — REASONING_EFFORT_MAPPINGS 25/50/75 → 50/75/100 (xhigh dropped); idempotent anchor-based patcher mounted per node; upstream has no fix yet (Aiden still 1.7.1, eugr repo unchanged, sglang upstream silent)

Alexander Korolev 5 дней назад
Родитель
Сommit
fc1fdcaa50

+ 69 - 0
recipes/dsv41-flash-1017-4x-sglang/patch_dsv41_effort.py

@@ -0,0 +1,69 @@
+#!/usr/bin/env python3
+"""Patch the Aiden 1.7.1 image's DSV4.1 chat encoder for the 1017 protocol.
+
+The image (aidendle94/sparkrun-sglang-dsv41-gb10:production-1.7.1, built
+2026-09-29) carries the OLD reasoning-effort tier mapping:
+
+    REASONING_EFFORT_MAPPINGS = {
+        "low": 25, "high": 50, "xhigh": 75, "max": 100,
+    }
+
+while the DeepSeek-V4.1-Flash-1017 reference encoder (encoding/encoding.py)
+shifted the ladder and dropped the xhigh tier:
+
+    {"low": 50, "high": 75, "max": 100}   (default stays "high")
+
+With the old map, explicit tier requests under-reason by one tier (API
+"high" renders `Reasoning Effort: 50` where 1017 means 75). The server
+default is pinned to max(100) via SGLANG_DSV41_REASONING_EFFORT, so this
+patch only affects requests that name a tier explicitly.
+
+Idempotent: running twice is a no-op. Refuses to touch a file that matches
+neither anchor (unknown encoder revision).
+"""
+
+import sys
+from pathlib import Path
+
+FILES = [
+    Path("/sgl-workspace/sglang/python/sglang/srt/entrypoints/openai/encoding_dsv41.py"),
+    Path("/usr/local/lib/python3.12/dist-packages/sglang/srt/entrypoints/openai/encoding_dsv41.py"),
+]
+
+OLD = '''    "low": 25,
+    "high": 50,
+    "xhigh": 75,
+    "max": 100,
+}'''
+NEW = '''    "low": 50,
+    "high": 75,
+    "max": 100,
+}'''
+
+
+def main() -> int:
+    target = next((f for f in FILES if f.exists()), None)
+    if target is None:
+        print("dsv41-effort-patch: encoder file not found — nothing to patch")
+        return 1
+    text = target.read_text()
+    if NEW in text and OLD not in text:
+        print("dsv41-effort-patch: already patched (low 50 / high 75 / max 100)")
+        return 0
+    if OLD not in text:
+        print(
+            "dsv41-effort-patch: anchor not found — encoder revision differs, "
+            "refusing to patch blindly"
+        )
+        return 1
+    target.write_text(text.replace(OLD, NEW, 1))
+    check = target.read_text()
+    if NEW in check and OLD not in check:
+        print("dsv41-effort-patch: applied (low 50 / high 75 / max 100, xhigh dropped)")
+        return 0
+    print("dsv41-effort-patch: patch verification failed")
+    return 1
+
+
+if __name__ == "__main__":
+    sys.exit(main())

+ 16 - 0
recipes/dsv41-flash-1017-4x-sglang/recipe.toml

@@ -38,6 +38,16 @@ shm_size = "32gb"
 # engine with the launcher's full flag list in "$@".
 entrypoint = ["sh", "/aiden4x-launch.sh"]
 
+# Mods run inside the container BEFORE the wrapper execs the engine. This one
+# aligns the image's DSV4.1 chat encoder with the 1017 reference protocol
+# (reasoning-effort tier ladder moved: 25/50/75 → 50/75/100, xhigh dropped).
+# The patcher is mounted read-only below and is idempotent; it refuses to
+# patch an encoder whose anchor does not match.
+[mods]
+commands = [
+  "python3 /patch_dsv41_effort.py",
+]
+
 args = [
     "--trust-remote-code",
     "--served-model-name", "deepseek-v4.1-flash",
@@ -79,6 +89,12 @@ host = "/home/kilork/aiden4x-launch.sh"
 container = "/aiden4x-launch.sh"
 read_only = true
 
+# The effort-mapping patcher (see [mods] above) — one copy per node.
+[[extra_mounts]]
+host = "/home/kilork/patch_dsv41_effort.py"
+container = "/patch_dsv41_effort.py"
+read_only = true
+
 # Node-local sparse copy of the Engram tables (staging P2.5, sparse-copy —
 # the aiden overlay's engram-local.json contract). Built/verified per serve by
 # the [[staging]] block; the wrapper-computed SPARK_ENGRAM_ROWS and the