Parcourir la source

dsv41-flash-1017-4x-sglang: bake the 1017 encoder patch into a thin wrapper image (docker-images/dsv41-sglang-1017, glm52 pattern: FROM aiden production-1.7.1 by digest + patch at build) — replaces the [mods]+manual-scp approach; recipe points at dsv41-sglang-1017:local

Alexander Korolev il y a 5 jours
Parent
commit
aa4d33f1f2

+ 15 - 0
docker-images/dsv41-sglang-1017/Dockerfile

@@ -0,0 +1,15 @@
+# syntax=docker/dockerfile:1.7
+# DSV4.1-1017 SGLang image — Aiden's production-1.7.1 with the 1017 protocol
+# patch baked at build time (the glm52 pattern: engine-code patches belong in
+# the image, never in per-node hand copies or runtime file surgery).
+#
+# The patch aligns the DSV4.1 chat encoder's reasoning-effort tier ladder with
+# the DeepSeek-V4.1-Flash-1017 reference encoder (25/50/75 -> 50/75/100, xhigh
+# dropped); see patch_dsv41_effort.py — it is idempotent and refuses to patch
+# an encoder whose anchor does not match.
+
+ARG BASE_IMAGE
+FROM ${BASE_IMAGE}
+
+COPY patch_dsv41_effort.py /tmp/patch_dsv41_effort.py
+RUN python3 /tmp/patch_dsv41_effort.py && rm /tmp/patch_dsv41_effort.py

+ 29 - 0
docker-images/dsv41-sglang-1017/build.sh

@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+# Build the dsv41-flash B12X wrapper (thin FROM over the sm121-built base).
+#
+# Uses the classic docker builder (not buildx docker-container): the base
+# image dsv41-flash:local is local-only (never pushed to a registry), and
+# the container-driver builder cannot resolve local FROM references.
+#
+# Generic driver: forwards every KEY=VAL pin in versions.env as a
+# --build-arg to the Dockerfile (no hardcoded variable list). The sm121
+# launcher writes a merged versions.env here when a recipe carries
+# [build.versions] overrides (recipe wins over the image defaults).
+set -euo pipefail
+cd "$(dirname "$0")"
+TAG="${TAG:-dsv41-sglang-1017:local}"
+
+ARGS=()
+while IFS= read -r line; do
+    # Skip blank lines and comments (# ...).
+    case "$line" in
+        ''|\#*) continue ;;
+    esac
+    key="${line%%=*}"
+    val="${line#*=}"
+    [ -n "$key" ] && ARGS+=(--build-arg "${key}=${val}")
+done < versions.env
+
+echo "=== Building ${TAG} ==="
+docker build "${ARGS[@]}" --progress=plain -t "${TAG}" -f Dockerfile . 2>&1
+echo "=== Done: ${TAG} ==="

+ 69 - 0
docker-images/dsv41-sglang-1017/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())

+ 9 - 0
docker-images/dsv41-sglang-1017/versions.env

@@ -0,0 +1,9 @@
+# versions.env - build input for the DSV4.1-1017 SGLang image.
+# Thin FROM wrapper over Aiden's prebuilt SGLang production image, baking in
+# the 1017 protocol patch (the reasoning-effort tier ladder moved in the
+# DeepSeek-V4.1-Flash-1017 reference encoder: 25/50/75 -> 50/75/100, xhigh
+# dropped). The patch is applied at BUILD time (the glm52 pattern) so no
+# runtime file surgery is needed.
+#
+# Aiden's latest DSV4.1 SGLang image (2026-09-29); arm64 digest from Docker Hub.
+BASE_IMAGE=aidendle94/sparkrun-sglang-dsv41-gb10@sha256:f617afd8289e4be8f268ce7f6f07beaaff6b8c691fb27d2c3ab9d784d15c8143

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

@@ -24,7 +24,8 @@
 
 engine = "sglang"
 name = "DeepSeek-V4.1-Flash-1017 (SGLang 4x, Aiden production-1.7.1)"
-docker_image = "aidendle94/sparkrun-sglang-dsv41-gb10@sha256:f617afd8289e4be8f268ce7f6f07beaaff6b8c691fb27d2c3ab9d784d15c8143"
+docker_image = "dsv41-sglang-1017:local"
+docker_image_dir = "dsv41-sglang-1017"
 model = "deepseek-ai/DeepSeek-V4.1-Flash-1017"
 parent_model = "deepseek-ai/DeepSeek-V4.1-Flash"
 port = 30000
@@ -38,16 +39,6 @@ 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",
@@ -89,11 +80,6 @@ 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