{"record":{"id":"28a62fc0f6a73ba2","repo":"openai/whisper","slug":"triton-import-failed-try-pip-install-pre-trito","errorCode":null,"errorMessage":"triton import failed; try `pip install --pre triton`","messagePattern":"triton import failed; try `pip install --pre triton`","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"whisper/triton_ops.py","lineNumber":10,"sourceCode":"from functools import lru_cache\n\nimport numpy as np\nimport torch\n\ntry:\n    import triton\n    import triton.language as tl\nexcept ImportError:\n    raise RuntimeError(\"triton import failed; try `pip install --pre triton`\")\n\n\n@triton.jit\ndef dtw_kernel(\n    cost, trace, x, x_stride, cost_stride, trace_stride, N, M, BLOCK_SIZE: tl.constexpr\n):\n    offsets = tl.arange(0, BLOCK_SIZE)\n    mask = offsets < M\n\n    for k in range(1, N + M + 1):  # k = i + j\n        tl.debug_barrier()\n\n        p0 = cost + (k - 1) * cost_stride\n        p1 = cost + k * cost_stride\n        p2 = cost + k * cost_stride + 1\n\n        c0 = tl.load(p0 + offsets, mask=mask)\n        c1 = tl.load(p1 + offsets, mask=mask)","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/openai/whisper/blob/5f86d1d86363843179951550570367b37c5d6f78/whisper/triton_ops.py#L1-L28","documentation":"whisper/triton_ops.py hard-fails at import time if the triton package is missing: the module defines @triton.jit kernels (for DTW/alignment speedups), so importing it without triton installed raises RuntimeError suggesting 'pip install --pre triton'. The error occurs at module import, before any kernel runs.","triggerScenarios":"import whisper.triton_ops (or code that imports it eagerly) in an environment without triton — typically CPU-only or macOS/Windows setups, since triton is Linux+CUDA-oriented; also importing dtw_alignment helpers on a machine where the triton extra was never installed.","commonSituations":"Deploying the same codebase to CPU inference boxes; macOS/Windows dev machines; Docker images that installed openai-whisper without the triton dependency; only the CUDA path needs this module.","solutions":["If you do not need the triton DTW speedup, avoid importing whisper.triton_ops (whisper itself does not import it eagerly — check your own imports)","Install triton: pip install --pre triton (Linux with a compatible CUDA toolkit)","On CPU-only environments, gate the import behind torch.cuda.is_available()"],"exampleFix":"# before\nfrom whisper.triton_ops import dtw_kernel  # RuntimeError without triton\n\n# after\nif torch.cuda.is_available():\n    from whisper.triton_ops import dtw_kernel\nelse:\n    dtw_kernel = None  # CPU fallback path","handlingStrategy":"type-guard","validationCode":"import importlib.util, torch\n\ndef triton_available() -> bool:\n    return importlib.util.find_spec(\"triton\") is not None and torch.cuda.is_available()","typeGuard":"def can_use_triton_ops() -> bool:\n    try:\n        import triton  # noqa\n        import torch\n        return torch.cuda.is_available()\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    from whisper.triton_ops import dtw_kernel\nexcept (RuntimeError, ImportError):\n    dtw_kernel = None  # CPU / non-triton fallback path","preventionTips":["Import whisper.triton_ops lazily and only on CUDA/Linux environments","Add triton to the dependency set of GPU images explicitly and test import in CI"],"tags":["dependencies","triton","cuda","import-error","environment"],"backgroundTag":null,"analyzedSha":"5f86d1d86363843179951550570367b37c5d6f78","analyzedAt":"2026-08-14T18:53:59.547Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}