openai/whisper · error · RuntimeError

triton import failed; try `pip install --pre triton`

Error message

triton import failed; try `pip install --pre triton`

What it means

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.

Source

Thrown at whisper/triton_ops.py:10

from functools import lru_cache

import numpy as np
import torch

try:
    import triton
    import triton.language as tl
except ImportError:
    raise RuntimeError("triton import failed; try `pip install --pre triton`")


@triton.jit
def dtw_kernel(
    cost, trace, x, x_stride, cost_stride, trace_stride, N, M, BLOCK_SIZE: tl.constexpr
):
    offsets = tl.arange(0, BLOCK_SIZE)
    mask = offsets < M

    for k in range(1, N + M + 1):  # k = i + j
        tl.debug_barrier()

        p0 = cost + (k - 1) * cost_stride
        p1 = cost + k * cost_stride
        p2 = cost + k * cost_stride + 1

        c0 = tl.load(p0 + offsets, mask=mask)
        c1 = tl.load(p1 + offsets, mask=mask)

View on GitHub (pinned to 5f86d1d863)

Solutions

  1. 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)
  2. Install triton: pip install --pre triton (Linux with a compatible CUDA toolkit)
  3. On CPU-only environments, gate the import behind torch.cuda.is_available()

Example fix

# before
from whisper.triton_ops import dtw_kernel  # RuntimeError without triton

# after
if torch.cuda.is_available():
    from whisper.triton_ops import dtw_kernel
else:
    dtw_kernel = None  # CPU fallback path
Defensive patterns

Strategy: type-guard

Validate before calling

import importlib.util, torch

def triton_available() -> bool:
    return importlib.util.find_spec("triton") is not None and torch.cuda.is_available()

Type guard

def can_use_triton_ops() -> bool:
    try:
        import triton  # noqa
        import torch
        return torch.cuda.is_available()
    except ImportError:
        return False

Try / catch

try:
    from whisper.triton_ops import dtw_kernel
except (RuntimeError, ImportError):
    dtw_kernel = None  # CPU / non-triton fallback path

Prevention

When it happens

Trigger: 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.

Common situations: 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.


AI-assisted analysis of openai/whisper@5f86d1d863 (2026-08-14). Data as JSON: /api/errors/28a62fc0f6a73ba2. Report an issue: GitHub.