spin_wait.py 1.2 KB

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python3
  2. """Cut the shm_broadcast reader's busy-wait from 1 s to 2 ms.
  3. vLLM's MessageQueue readers spin for `busy_loop_s` after each read before they
  4. start sleeping. At the default of 1 s every TP rank spins almost continuously,
  5. and on GB10 that spin is not free: CPU and GPU share one thermal and power
  6. budget, so it cost ~20 C and measurable decode. 0.002 keeps the fast path for
  7. back-to-back steps; always-blocking (0) measured WORSE. After
  8. https://artifacts.nacyot.com/vllm-spin-wait-gb10-en/.
  9. Replaces the whole-file mount of shm_broadcast.py the old deployment used.
  10. Same contract as the other patchers: one anchor, exactly once, or the build
  11. fails.
  12. """
  13. from pathlib import Path
  14. PATH = Path("/usr/local/lib/python3.12/dist-packages/vllm/distributed/device_communicators/shm_broadcast.py")
  15. OLD = " busy_loop_s: float = 1,\n"
  16. NEW = " busy_loop_s: float = 0.002,\n"
  17. text = PATH.read_text()
  18. if text.count(NEW) == 1 and text.count(OLD) == 0:
  19. print("[spin-wait] already 0.002")
  20. else:
  21. assert text.count(OLD) == 1, f"[spin-wait] anchor matched {text.count(OLD)} times; stock tree changed"
  22. PATH.write_text(text.replace(OLD, NEW))
  23. print("[spin-wait] busy_loop_s default 1 -> 0.002")