Issue Type
AI Agent Information
Summary
Qwen3ModelTest::test_generate_compile_model_forward_fullgraph fails on MUSA MTT S5000 because torch.compile() with the Triton backend requires libcuda.so, even when compiling for a non-CUDA device. The test attempts to compile a qwen3 model on the flagos device, but PyTorch's Triton compiler tries to load CUDA libraries unconditionally, causing an import error.
Environment
Click to expand environment details
- Platform: MUSA (MTT S5000, 8 devices)
- Python: 3.10.20
- PyTorch: 2.10.0+cpu
- torch_fl: commit
2e64a8da6d9d6e81edcfff258f114ce0979fcb19
- Transformers: 5.16.1
Runtime config:
export TORCH_DEVICE_BACKEND_AUTOLOAD=0
export TRANSFORMERS_TEST_DEVICE_SPEC=hf_device_spec.py
export HF_HUB_OFFLINE=1
export TRANSFORMERS_OFFLINE=1
Reproduction
Run the single test in a fresh process (confirmed reproducible 3/3 runs):
python3 -m pytest \
"tests/models/qwen3/test_modeling_qwen3.py::Qwen3ModelTest::test_generate_compile_model_forward_fullgraph" \
-q
Minimal standalone reproducer:
import torch
import torch_fl # registers the flagos device
model = torch.nn.Linear(10, 10).to("flagos")
compiled_model = torch.compile(model, fullgraph=True)
x = torch.randn(1, 10, device="flagos")
# This will fail during compilation
output = compiled_model(x)
Expected vs Actual Behavior
Expected:
torch.compile() should work on the flagos device without requiring CUDA libraries, either by:
- Using a device-agnostic compilation backend
- Detecting the target device and skipping CUDA-specific initialization
- Providing a fallback compilation path for non-CUDA devices
Actual:
E OSError: libcuda.so.1: cannot open shared object file: No such file or directory
Full error chain:
torch/_inductor/triton_heuristics.py
-> import triton
-> triton.runtime.driver
-> ctypes.CDLL("libcuda.so.1")
[fails: libcuda.so.1 not found on MUSA-only system]
Root Cause Analysis
PyTorch's torch.compile() uses the Triton compiler as its default backend. Triton's CUDA driver module unconditionally attempts to load libcuda.so.1 at import time, regardless of the target device. This fails on systems that only have MUSA (or other non-CUDA) accelerators installed.
Why this happens:
torch.compile(model) invokes TorchInductor
- TorchInductor imports Triton for kernel generation
- Triton's
runtime/driver.py loads CUDA driver libraries unconditionally
- No CUDA libraries exist on a MUSA-only system → ImportError/OSError
Upstream context:
This is a known limitation in PyTorch + Triton. The Triton compiler was designed primarily for CUDA and does not have a complete device-agnostic abstraction. Recent PyTorch versions are working toward better backend extensibility, but as of PyTorch 2.10, Triton still assumes CUDA availability.
Proposed Solution
Option 1: Skip torch.compile tests on non-CUDA devices (workaround)
@pytest.mark.skipif(
torch.device("flagos").type != "cuda",
reason="torch.compile requires CUDA Triton backend"
)
def test_generate_compile_model_forward_fullgraph(self):
...
Option 2: Provide a MUSA Triton backend (proper fix)
- Implement a Triton backend for MUSA that generates MUSA kernels instead of CUDA PTX
- Register it with PyTorch's compilation backend registry
- This requires significant engineering effort and deep Triton internals knowledge
Option 3: Use eager mode as fallback
try:
compiled_model = torch.compile(model)
except (ImportError, OSError):
compiled_model = model # fallback to eager
Recommendation:
- Short-term: Skip
torch.compile tests on flagos (Option 1)
- Long-term: Implement MUSA Triton backend if compilation performance is critical (Option 2)
Verification Plan
Context & Investigation
Investigation completed:
- Isolated this test from the full qwen3 suite (297 tests) and verified it fails deterministically.
- Confirmed the error trace leads to Triton's CUDA driver import, not a torch_fl bug.
- Checked PyTorch documentation:
torch.compile() currently requires CUDA for Triton backend.
- Searched for existing issues about torch.compile / Triton / non-CUDA devices — no open duplicate found.
- This is a feature gap rather than a torch_fl bug: PyTorch does not support
torch.compile() on PrivateUse1 devices without a custom Triton backend.
Related Code Locations
- PyTorch:
torch/_inductor/compile_fx.py — compilation entry point
- PyTorch:
torch/_inductor/codegen/triton.py — Triton code generation
- Triton:
triton/runtime/driver.py — CUDA driver loading (external dependency)
- torch_fl: would need to implement
TritonMUSABackend if pursuing Option 2
Affected Tests
This root cause affects both:
test_generate_compile_model_forward_fullgraph
test_generate_compilation (likely the same error, needs verification)
Checklist - AI Agents MUST Complete All
Issue Type
AI Agent Information
Summary
Qwen3ModelTest::test_generate_compile_model_forward_fullgraphfails on MUSA MTT S5000 becausetorch.compile()with the Triton backend requireslibcuda.so, even when compiling for a non-CUDA device. The test attempts to compile a qwen3 model on theflagosdevice, but PyTorch's Triton compiler tries to load CUDA libraries unconditionally, causing an import error.Environment
Click to expand environment details
2e64a8da6d9d6e81edcfff258f114ce0979fcb19Runtime config:
Reproduction
Run the single test in a fresh process (confirmed reproducible 3/3 runs):
python3 -m pytest \ "tests/models/qwen3/test_modeling_qwen3.py::Qwen3ModelTest::test_generate_compile_model_forward_fullgraph" \ -qMinimal standalone reproducer:
Expected vs Actual Behavior
Expected:
torch.compile()should work on theflagosdevice without requiring CUDA libraries, either by:Actual:
Full error chain:
Root Cause Analysis
PyTorch's
torch.compile()uses the Triton compiler as its default backend. Triton's CUDA driver module unconditionally attempts to loadlibcuda.so.1at import time, regardless of the target device. This fails on systems that only have MUSA (or other non-CUDA) accelerators installed.Why this happens:
torch.compile(model)invokes TorchInductorruntime/driver.pyloads CUDA driver libraries unconditionallyUpstream context:
This is a known limitation in PyTorch + Triton. The Triton compiler was designed primarily for CUDA and does not have a complete device-agnostic abstraction. Recent PyTorch versions are working toward better backend extensibility, but as of PyTorch 2.10, Triton still assumes CUDA availability.
Proposed Solution
Option 1: Skip torch.compile tests on non-CUDA devices (workaround)
Option 2: Provide a MUSA Triton backend (proper fix)
Option 3: Use eager mode as fallback
Recommendation:
torch.compiletests on flagos (Option 1)Verification Plan
test_generate_compile_model_forward_fullgraphand confirm expected behaviorContext & Investigation
Investigation completed:
torch.compile()currently requires CUDA for Triton backend.torch.compile()on PrivateUse1 devices without a custom Triton backend.Related Code Locations
torch/_inductor/compile_fx.py— compilation entry pointtorch/_inductor/codegen/triton.py— Triton code generationtriton/runtime/driver.py— CUDA driver loading (external dependency)TritonMUSABackendif pursuing Option 2Affected Tests
This root cause affects both:
test_generate_compile_model_forward_fullgraphtest_generate_compilation(likely the same error, needs verification)Checklist - AI Agents MUST Complete All