File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
123132try :
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
128146except ImportError :
129- TRITON_AVAILABLE = False
147+ pass
130148
131149# ============================================================================
132150# Constants
You can’t perform that action at this time.
0 commit comments