patch_b12x_sm12x_priorities.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash
  2. # The sm12x auto-priority list in platforms/cuda.py only offers
  3. # [TRITON_MLA, FLASHINFER_MLA_SPARSE_SM120] — neither matches GLM-5.3's
  4. # head-512 MLA (SM120 flashinfer only supports head 576). The MTP draft
  5. # model's vllm_config does NOT inherit the global --attention-backend, so
  6. # its MLA layers auto-select and die. The B12X paged/sparse-MLA backend
  7. # (which the main model uses via the global flag) supports (12,0)/(12,1),
  8. # so offer it first.
  9. set -euo pipefail
  10. P=/usr/local/lib/python3.12/dist-packages/vllm/platforms/cuda.py
  11. python3 - <<'PY'
  12. p = "/usr/local/lib/python3.12/dist-packages/vllm/platforms/cuda.py"
  13. s = open(p).read()
  14. old = """ elif device_capability.major == 12:
  15. return [
  16. AttentionBackendEnum.TRITON_MLA,
  17. AttentionBackendEnum.FLASHINFER_MLA_SPARSE_SM120,
  18. ]"""
  19. new = """ elif device_capability.major == 12:
  20. return [
  21. AttentionBackendEnum.B12X,
  22. AttentionBackendEnum.TRITON_MLA,
  23. AttentionBackendEnum.FLASHINFER_MLA_SPARSE_SM120,
  24. ]"""
  25. if "AttentionBackendEnum.B12X,\n AttentionBackendEnum.TRITON_MLA" in s:
  26. print("[b12x-sm12x] already patched")
  27. else:
  28. assert old in s, "sm12x priority block not found (source drift)"
  29. open(p, "w").write(s.replace(old, new, 1))
  30. print("[b12x-sm12x] patched: B12X first in sm12x MLA priorities")
  31. import importlib, vllm.platforms.cuda
  32. importlib.reload(vllm.platforms.cuda)
  33. print("[b12x-sm12x] OK")
  34. PY
  35. find /usr/local/lib/python3.12/dist-packages/vllm -name "__pycache__" -type d -prune -exec rm -rf {} + 2>/dev/null || true