patch_cuda_sm12x.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. """B12X into the sm12x auto-priority list (platforms/cuda.py).
  3. The sm12x branch of _get_backend_priorities only offers
  4. [TRITON_MLA, FLASHINFER_MLA_SPARSE_SM120]. Neither matches GLM-5.3-Flash:
  5. TRITON_MLA rejects sparse, and FLASHINFER_MLA_SPARSE_SM120 only supports
  6. head_size 576 (DeepSeek-V4 MLA), not GLM's 512. The B12X paged/sparse-MLA
  7. backend explicitly supports compute (12, 0) and (12, 1), so it is offered
  8. first. This matters for the MTP draft model: its vllm_config does NOT
  9. inherit the global --attention-backend, so its MLA layers go through
  10. auto-selection and die without this patch.
  11. """
  12. import importlib
  13. import sys
  14. P = "/usr/local/lib/python3.12/dist-packages/vllm/platforms/cuda.py"
  15. OLD = """ elif device_capability.major == 12:
  16. return [
  17. AttentionBackendEnum.TRITON_MLA,
  18. AttentionBackendEnum.FLASHINFER_MLA_SPARSE_SM120,
  19. ]"""
  20. NEW = """ elif device_capability.major == 12:
  21. return [
  22. AttentionBackendEnum.B12X,
  23. AttentionBackendEnum.TRITON_MLA,
  24. AttentionBackendEnum.FLASHINFER_MLA_SPARSE_SM120,
  25. ]"""
  26. s = open(P).read()
  27. if NEW in s:
  28. print("[patch] already applied")
  29. elif OLD in s:
  30. open(P, "w").write(s.replace(OLD, NEW, 1))
  31. print("[patch] applied: B12X first in sm12x MLA priorities")
  32. else:
  33. sys.exit("[patch] sm12x priority block not found (source drift)")