[Bug]: nllb / nllb_big crash on transformers >= 5.0 (Unknown task translation)

Author: 64kramsystemCreated May 23, 2026Updated Aug 23, 2026
Labelsbug

A fresh install via pip install -r requirements.txt resolves to transformers 5.x (5.9.0 currently). The NLLB translator then crashes on the first translation call because pipeline('translation', ...) was removed in 5.0.

Reproduction

On a clean clone:

bash
python3.11 -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt
# any image in ./input/, plus a config.toml with translator = "nllb_big"
python -m manga_translator local --config-file=config.toml -i ./input/

Crash:

File ".../manga_translator/translators/nllb.py", line 103, in _translate_sentence
    translator = pipeline('translation', ...)
File ".../transformers/pipelines/__init__.py", line 944, in pipeline
    normalized_task, targeted_task, task_options = check_task(task)
File ".../transformers/pipelines/base.py", line 1340, in check_task
    raise KeyError(f"Unknown task {task}, ...")
KeyError: "Unknown task translation, available tasks are ['any-to-any', 'audio-classification', ..., 'text-generation', 'text-to-audio', ...]"

Both nllb and nllb_big share _translate_sentence, so both are affected. Other offline translators (m2m100, mbart50, sugoi, jparacrawl) do not use pipeline('translation', ...) and are unaffected.

Fix

Drop the pipeline wrapper and use the documented NLLB inference path (tokenizer.src_lang + model.generate(forced_bos_token_id=...)). Works across transformers versions.

python
def _translate_sentence(self, from_lang: str, to_lang: str, query: str) -> str:
    if not self.is_loaded():
        return ''

    if from_lang == 'auto':
        detected_lang = langid.classify(query)[0]
        from_lang = self._map_detected_lang_to_translator(detected_lang)

    if from_lang is None:
        self.logger.warn(f'NLLB Translation Failed. Could not detect language (Or language not supported for text: {query})')
        return ''

    self.tokenizer.src_lang = from_lang
    inputs = self.tokenizer(query, return_tensors='pt').to(self.device)
    forced_bos = self.tokenizer.convert_tokens_to_ids(to_lang)
    output = self.model.generate(**inputs, forced_bos_token_id=forced_bos, max_length=512)
    return self.tokenizer.batch_decode(output, skip_special_tokens=True)[0]

Pinning transformers<5 in requirements.txt works as a stopgap but doesn't survive the next dependency bump. The patch above is the smaller diff.

Source: zyddnys/manga-image-translator