gb10_plugin_backend.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python3
  2. """Let VLLM_GLM53_CUDA_SPARSE_MLA choose between the two sm_121 MLA kernels.
  3. There are two solutions to the same GB10 problem and they collide silently.
  4. MiaAI-Lab's patcher gates vLLM's existing SM90 sparse-MLA path onto capability
  5. 12 by inserting it into the priority list ahead of SM120. LibertAI's plugin
  6. supplies its own kernel and, by its own design note, "deliberately overrides the
  7. existing FLASHINFER_MLA_SPARSE_SM120 enum slot ... so selection needs no
  8. plumbing". Selection takes the first supported entry, so SM90 always wins and
  9. the plugin sits unreachable in a slot nothing reaches.
  10. This makes the SM90 entry conditional on the plugin's own gate, so one image
  11. serves both: unset picks SM90 as before, set drops SM90 and the SM120 slot --
  12. now the plugin -- is selected. Runs after the MiaAI patcher and rewrites what it
  13. produced, so it fails loudly if that output ever changes shape.
  14. """
  15. from __future__ import annotations
  16. from pathlib import Path
  17. VLLM = Path("/usr/local/lib/python3.12/dist-packages/vllm")
  18. LOG = "[gb10-plugin]"
  19. OLD = """ elif device_capability.major == 12:
  20. return [
  21. AttentionBackendEnum.TRITON_MLA,
  22. AttentionBackendEnum.FLASHINFER_MLA_SPARSE_SM90,
  23. AttentionBackendEnum.FLASHINFER_MLA_SPARSE_SM120,
  24. ]"""
  25. NEW = """ elif device_capability.major == 12:
  26. import os as _os
  27. return [
  28. AttentionBackendEnum.TRITON_MLA,
  29. *(
  30. []
  31. if _os.environ.get("VLLM_GLM53_CUDA_SPARSE_MLA")
  32. else [AttentionBackendEnum.FLASHINFER_MLA_SPARSE_SM90]
  33. ),
  34. AttentionBackendEnum.FLASHINFER_MLA_SPARSE_SM120,
  35. ]"""
  36. def main() -> None:
  37. path = VLLM / "platforms/cuda.py"
  38. text = path.read_text()
  39. if text.count(NEW) == 1:
  40. print("%s skip (already in this image)" % LOG)
  41. return
  42. if text.count(OLD) != 1:
  43. raise SystemExit(
  44. "%s refuse: expected exactly one MiaAI capability-12 list, found %d"
  45. % (LOG, text.count(OLD))
  46. )
  47. path.write_text(text.replace(OLD, NEW, 1))
  48. print("%s SM90 is now conditional on VLLM_GLM53_CUDA_SPARSE_MLA" % LOG)
  49. if __name__ == "__main__":
  50. main()