patch_dsv41_effort.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python3
  2. """Patch the Aiden 1.7.1 image's DSV4.1 chat encoder for the 1017 protocol.
  3. The image (aidendle94/sparkrun-sglang-dsv41-gb10:production-1.7.1, built
  4. 2026-09-29) carries the OLD reasoning-effort tier mapping:
  5. REASONING_EFFORT_MAPPINGS = {
  6. "low": 25, "high": 50, "xhigh": 75, "max": 100,
  7. }
  8. while the DeepSeek-V4.1-Flash-1017 reference encoder (encoding/encoding.py)
  9. shifted the ladder and dropped the xhigh tier:
  10. {"low": 50, "high": 75, "max": 100} (default stays "high")
  11. With the old map, explicit tier requests under-reason by one tier (API
  12. "high" renders `Reasoning Effort: 50` where 1017 means 75). The server
  13. default is pinned to max(100) via SGLANG_DSV41_REASONING_EFFORT, so this
  14. patch only affects requests that name a tier explicitly.
  15. Idempotent: running twice is a no-op. Refuses to touch a file that matches
  16. neither anchor (unknown encoder revision).
  17. """
  18. import sys
  19. from pathlib import Path
  20. FILES = [
  21. Path("/sgl-workspace/sglang/python/sglang/srt/entrypoints/openai/encoding_dsv41.py"),
  22. Path("/usr/local/lib/python3.12/dist-packages/sglang/srt/entrypoints/openai/encoding_dsv41.py"),
  23. ]
  24. OLD = ''' "low": 25,
  25. "high": 50,
  26. "xhigh": 75,
  27. "max": 100,
  28. }'''
  29. NEW = ''' "low": 50,
  30. "high": 75,
  31. "max": 100,
  32. }'''
  33. def main() -> int:
  34. target = next((f for f in FILES if f.exists()), None)
  35. if target is None:
  36. print("dsv41-effort-patch: encoder file not found — nothing to patch")
  37. return 1
  38. text = target.read_text()
  39. if NEW in text and OLD not in text:
  40. print("dsv41-effort-patch: already patched (low 50 / high 75 / max 100)")
  41. return 0
  42. if OLD not in text:
  43. print(
  44. "dsv41-effort-patch: anchor not found — encoder revision differs, "
  45. "refusing to patch blindly"
  46. )
  47. return 1
  48. target.write_text(text.replace(OLD, NEW, 1))
  49. check = target.read_text()
  50. if NEW in check and OLD not in check:
  51. print("dsv41-effort-patch: applied (low 50 / high 75 / max 100, xhigh dropped)")
  52. return 0
  53. print("dsv41-effort-patch: patch verification failed")
  54. return 1
  55. if __name__ == "__main__":
  56. sys.exit(main())