Skip to content

Commit bcccbdd

Browse files
committed
fix: HybridMuon on CPU only machine
1 parent d537ce3 commit bcccbdd

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

deepmd/pt/optimizer/hybrid_muon.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,31 @@
120120
# Triton availability detection
121121
# ============================================================================
122122

123+
# Two-stage probe:
124+
# 1. ``import triton`` succeeds (package is installed).
125+
# 2. ``triton.runtime.driver.active`` resolves to a usable backend driver.
126+
#
127+
# Stage 2 is required because ``@triton.autotune(...)`` eagerly calls
128+
# ``driver.active.get_benchmarker()`` inside ``Autotuner.__init__``; on
129+
# CPU-only / driver-less hosts this raises ``RuntimeError: 0 active drivers``
130+
# at *module import time*, breaking non-training entry points.
131+
TRITON_AVAILABLE = False
123132
try:
124133
import triton
125134
import triton.language as tl
126135

127-
TRITON_AVAILABLE = True
136+
try:
137+
# Touching ``driver.active`` forces the lazy proxy to initialize the
138+
# backend driver. ``get_current_target`` is the lightest public call
139+
# that exercises the same path as ``Autotuner.__init__``.
140+
triton.runtime.driver.active.get_current_target()
141+
TRITON_AVAILABLE = True
142+
except Exception:
143+
# No usable runtime driver (no CUDA/ROCm/XPU, or a mis-configured
144+
# one): fall back to the pure-PyTorch Newton-Schulz path.
145+
TRITON_AVAILABLE = False
128146
except ImportError:
129-
TRITON_AVAILABLE = False
147+
pass
130148

131149
# ============================================================================
132150
# Constants

0 commit comments

Comments
 (0)