Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Load Whisper in FastModel without auto_model (#13080)

Daniel Hane8ce61de724a
diff --git a/tests/test_repo_code_vlm_processor.py b/tests/test_repo_code_vlm_processor.py
index e29d82cd147..7d771a11e1f 100644
--- a/tests/test_repo_code_vlm_processor.py
+++ b/tests/test_repo_code_vlm_processor.py
@@ -95,6 +95,7 @@ def _select(
transformers, "AutoModelForVision2Seq", transformers.AutoModelForImageTextToText
),
"AutoModelForImageTextToText": transformers.AutoModelForImageTextToText,
+ "AutoModelForSpeechSeq2Seq": transformers.AutoModelForSpeechSeq2Seq,
"_multimodal_auto_classes": lambda: (),
"AutoProcessor": fake_processor,
"AutoTokenizer": fake_tokenizer,
diff --git a/tests/test_seq2seq_auto_class.py b/tests/test_seq2seq_auto_class.py
index 9b711acda9a..20ef5d27fc6 100644
--- a/tests/test_seq2seq_auto_class.py
+++ b/tests/test_seq2seq_auto_class.py
@@ -89,3 +89,18 @@ def test_get_batch_samples_dispatch():
assert dispatch(trainer, iter([]), 1) == want
finally:
_utils._unsloth_get_batch_samples = original
+
+
[email protected]("name", ["WhisperConfig", "MoonshineConfig", "Speech2TextConfig"])
+def test_speech_seq2seq_configs_resolve_without_auto_model(name):
+ # FastModel.from_pretrained(whisper_lora) without auto_model used to ask AutoModelForImageTextToText (#2726).
+ from unsloth.models.loader import _resolve_speech_seq2seq_auto_model
+ assert (
+ _resolve_speech_seq2seq_auto_model(_config(name)) is transformers.AutoModelForSpeechSeq2Seq
+ )
+
+
[email protected]("name", ["LlamaConfig", "Gemma3Config", "T5Config"])
+def test_non_speech_configs_do_not_resolve_to_speech_seq2seq(name):
+ from unsloth.models.loader import _resolve_speech_seq2seq_auto_model
+ assert _resolve_speech_seq2seq_auto_model(_config(name)) is None
diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py
index a8c35c91d5a..3f571f4ebf2 100644
--- a/unsloth/models/loader.py
+++ b/unsloth/models/loader.py
@@ -654,6 +654,25 @@ def _resolve_omni_auto_model(
return None
+def _resolve_speech_seq2seq_auto_model(
+ model_config,
+ trust_remote_code = None,
+ **hub_kwargs,
+):
+ """AutoModelForSpeechSeq2Seq when it maps this config (Whisper, Moonshine), else None."""
+ import transformers
+
+ auto_class = getattr(transformers, "AutoModelForSpeechSeq2Seq", None)
+ try:
+ if auto_class is not None and resolve_model_class(
+ auto_class, model_config, trust_remote_code = trust_remote_code, **hub_kwargs
+ ):
+ return auto_class
+ except Exception:
+ pass
+ return None
+
+
def _get_user_task_config_attrs(user_config):
if user_config is None:
return {}
@@ -2650,6 +2669,7 @@ class FastModel(FastBaseModel):
if resolve_model_class(auto_model, model_config, **_probe_hub_kwargs) is None:
auto_model = (
_resolve_omni_auto_model(model_config, **_probe_hub_kwargs)
+ or _resolve_speech_seq2seq_auto_model(model_config, **_probe_hub_kwargs)
or auto_model
)
else:
diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py
index 308642bcee5..a67076ee64a 100644
--- a/unsloth/models/vision.py
+++ b/unsloth/models/vision.py
@@ -15,6 +15,7 @@ from transformers import (
AutoProcessor,
AutoTokenizer,
AutoModelForCausalLM,
+ AutoModelForSpeechSeq2Seq,
)
try:
@@ -53,8 +54,8 @@ def _multimodal_auto_classes():
# Looked up, not referenced: which names exist varies (4.51.3 has both, 5.5.0
# dropped AutoModelForVision2Seq), so only the alias above is always bound.
classes = [AutoModelForVision2Seq]
- # AutoModelForSpeechSeq2Seq is deliberately absent: Whisper already reaches
- # AutoProcessor through is_whisper, so adding it would move a cell for nothing.
+ # AutoModelForSpeechSeq2Seq is deliberately absent: it would move Granite Speech in
+ # _is_text_seq2seq_config on transformers 4.57; from_pretrained adds its processor itself.
for name in (
"AutoModelForImageTextToText",
"AutoModelForTextToWaveform",
@@ -2901,6 +2902,8 @@ class FastBaseModel:
# Audio and omni classes need a processor but are NOT image models, so they
# must not widen is_vlm, which arms the image-processor repair path below.
needs_processor = is_vlm or auto_model in _multimodal_auto_classes()
+ # FastModel routes Whisper here without auto_model (#2726); audio features need the processor.
+ needs_processor = needs_processor or auto_model is AutoModelForSpeechSeq2Seq
# A repo-code VLM may register only AutoModel / AutoModelForCausalLM (DeepSeek-OCR, Nemotron-VL), so auto_model is not a VLM class though the config is a vision model. Keep is_vlm for processor selection, but treat it as a VLM on the vLLM path so a vision_config model is never silently loaded as text-only.
is_vlm_config = (
is_vlm