CTC Decoder suit requires flashlight-text package (fix)

from torchaudio.models.decoder import ctc_decoder raises RuntimeError: CTC Decoder suit requires flashlight-text package and optionally KenLM. Please install them. (after No module named 'flashlight'). We reproduced it, fixed it on Python 3.11, and got the source build working on Python 3.13.

1. The error

A tiny lexicon-free decode (no acoustic model needed; four fake frames):

import torch, torchaudio
from torchaudio.models.decoder import ctc_decoder
tokens = ["-", "|", "h", "i"]
decoder = ctc_decoder(lexicon=None, tokens=tokens, blank_token="-", sil_token="|", unk_word="<unk>")
# fake acoustic model output: frames favour h, h, i, blank
emissions = torch.log_softmax(torch.tensor([[[0, 0, 5, 0], [0, 0, 5, 0], [0, 0, 0, 5], [5, 0, 0, 0]]], dtype=torch.float32), dim=-1)
best = decoder(emissions)[0][0]
print(torchaudio.__version__, decoder.idxs_to_tokens(best.tokens))

torchaudio 2.9.0, fresh venv (2.8.0 gives the same error):

Traceback (most recent call last):
  ...
ModuleNotFoundError: No module named 'flashlight'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  ...
RuntimeError: CTC Decoder suit requires flashlight-text package and optionally KenLM. Please install them.

The decoder lives in torchaudio but its engine is the separate flashlight-text package, which torchaudio does not install for you.

2. Fix: pip install flashlight-text

pip install flashlight-text

On Python 3.11 that installed a prebuilt wheel (0.0.7) and the same script ran:

2.9.0+cpu ['|', 'h', 'i', '|']

KenLM is only needed for decoding with an n-gram language model; the PyPI wheel already includes it (from flashlight.lib.text.decoder import KenLM worked).

3. Python 3.13: no wheel, so it builds from source

flashlight-text 0.0.7 publishes wheels for CPython 3.6 to 3.12 only. On 3.13 pip falls back to the sdist, and the build failed three ways in a row for us:

RuntimeError: CMake must be installed to build the following extensions: flashlight.lib.text.decoder, flashlight.lib.text.dictionary

After pip install cmake:

RuntimeError: ('KenLM is not installed or failed to import. ', ... 'set the environment ', 'variable USE_KENLM=0.')

With USE_KENLM=0, CMake 4 (what pip install cmake gives now) refused the old pybind11 it downloads:

Compatibility with CMake < 3.5 has been removed from CMake.

(A Python without development headers, like a distro python3.13 without python3.13-dev, first fails with Could NOT find Python3 (missing: Python3_INCLUDE_DIRS Development.Module).) This built in 18 seconds with g++ installed:

pip install cmake
USE_KENLM=0 CMAKE_POLICY_VERSION_MINIMUM=3.5 pip install flashlight-text

Then the script above on Python 3.13.17 with torch/torchaudio 2.9.0 CPU (a NumPy-missing warning cut):

2.9.0+cpu ['|', 'h', 'i', '|']

USE_KENLM=0 means no n-gram LM in that build: importing KenLM from it raised ImportError: Installed Flashlight Text Python bindings were built without KenLM support. If you need one, use Python 3.12 or older and the wheel instead.

Related: torchaudio.utils has no attribute download_asset · No module named torchaudio.io · No module named torchaudio.backend

Frequently asked questions

Do I need KenLM for torchaudio ctc_decoder?

Only to decode with an n-gram language model (lm=...). Lexicon-free decoding without an LM ran with the plain flashlight-text wheel, and also with a USE_KENLM=0 source build.

Why does pip install flashlight-text fail on Python 3.13?

flashlight-text 0.0.7 has wheels for CPython 3.6-3.12 only, so 3.13 builds the sdist. We needed CMake, Python headers, USE_KENLM=0 (or KenLM installed) and CMAKE_POLICY_VERSION_MINIMUM=3.5 for CMake 4.

Written with AI assistance. Measured on 2026-10-24 on Linux with CPython 3.11.17 and 3.13.17, torch/torchaudio 2.8.0 and 2.9.0, flashlight-text 0.0.7 (wheel on 3.11, built from sdist on 3.13 with g++ and CMake 4.4). Output pasted unedited except shortened paths and cut tracebacks. PlainTables is our extension; torchaudio and flashlight-text are free.