Checklist
Motivation
On macOS, SGLang installs a mock triton module via _triton_stub.py so that code importing triton doesn't crash. However, with torch 2.9+, the stub is missing triton.compiler / triton.compiler.compiler sub-modules, causing bench_one_batch and server startup to fail.
Problem
The import chain that triggers the crash:
torchvision → torch._dynamo → torch._inductor.runtime.hints → import triton.compiler.compiler
Because the triton stub makes has_triton_package() return True (since triton exists in sys.modules), torch proceeds to import triton.compiler.compiler — which doesn't exist in the mock, causing ModuleNotFoundError.
ModuleNotFoundError: No module named 'triton.compiler'
The stub currently only registers:
triton
triton.backends
triton.backends.compiler
But not triton.compiler or triton.compiler.compiler, which torch 2.9+ expects.
Additional Issue
The _TritonFinder meta-path finder uses the deprecated find_module/load_module protocol, which doesn't work reliably in Python 3.12+. Should be updated to find_spec (PEP 451).
Suggested Fix
- Register
triton.compiler and triton.compiler.compiler as mock sub-modules in _triton_stub.py
- Update
_TritonFinder to use the modern find_spec API
Environment
- macOS (Apple Silicon M3 Pro)
- Python 3.12.11
- torch 2.9.1
- torchvision 0.24.0
- SGLang main branch (commit e8d46f1)
Checklist
Motivation
On macOS, SGLang installs a mock
tritonmodule via_triton_stub.pyso that code importing triton doesn't crash. However, with torch 2.9+, the stub is missingtriton.compiler/triton.compiler.compilersub-modules, causingbench_one_batchand server startup to fail.Problem
The import chain that triggers the crash:
Because the triton stub makes
has_triton_package()returnTrue(sincetritonexists insys.modules), torch proceeds to importtriton.compiler.compiler— which doesn't exist in the mock, causingModuleNotFoundError.The stub currently only registers:
tritontriton.backendstriton.backends.compilerBut not
triton.compilerortriton.compiler.compiler, which torch 2.9+ expects.Additional Issue
The
_TritonFindermeta-path finder uses the deprecatedfind_module/load_moduleprotocol, which doesn't work reliably in Python 3.12+. Should be updated tofind_spec(PEP 451).Suggested Fix
triton.compilerandtriton.compiler.compileras mock sub-modules in_triton_stub.py_TritonFinderto use the modernfind_specAPIEnvironment