Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/test_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,32 @@ def test_network_error_warns_about_cache_only_flag(self, mocker):
warning_text = " ".join(str(a) for a in mock_logger.warning.call_args[0])
assert "--model_cache_only" in warning_text

def test_non_network_error_is_surfaced(self, mocker):
"""A non-network failure must keep its own cause in the raised message.

A partially downloaded cache raises OSError about a missing
preprocessor_config.json. Reporting that as "model could not be found"
sends people looking for a model that exists and loads fine on retry.
"""
import torchaudio

import whispermlx.alignment as alignment_module
from whispermlx.alignment import load_align_model

mocker.patch.object(torchaudio.pipelines, "__all__", [])
mocker.patch(
"whispermlx.alignment.Wav2Vec2Processor.from_pretrained",
side_effect=OSError("Can't load feature extractor for 'some/model'"),
)
mock_logger = mocker.patch.object(alignment_module, "logger")

with pytest.raises(ValueError, match="Can't load feature extractor"):
load_align_model("ru", "cpu")

error_text = " ".join(str(a) for a in mock_logger.error.call_args[0])
assert "OSError" in error_text
assert "not necessarily a missing model" in error_text

def test_explicit_model_name_skips_default_lookup(self, mocker):
"""Explicit model_name should bypass default language mapping."""
import torchaudio
Expand Down
14 changes: 10 additions & 4 deletions whispermlx/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,18 @@ def load_align_model(
"re-run with --model_cache_only to load from local cache."
)
else:
print(e)
print(
"Error loading model from huggingface, check https://huggingface.co/models for finetuned wav2vec2.0 models"
logger.error(
f"Failed to load align_model {model_name!r}: {type(e).__name__}: {e}\n"
"If the repo name is correct, this is not necessarily a missing model — "
"an interrupted download, a gated repo or a cache permission problem "
"raises here too. See https://huggingface.co/models for finetuned "
"wav2vec2.0 models."
)
raise ValueError(
f'The chosen align_model "{model_name}" could not be found in huggingface (https://huggingface.co/models) or torchaudio (https://pytorch.org/audio/stable/pipelines.html#id14)'
f'Could not load align_model "{model_name}" '
f"({type(e).__name__}: {e}). If the name is correct, check that the model is "
"reachable on huggingface (https://huggingface.co/models) or is a torchaudio "
"pipeline (https://pytorch.org/audio/stable/pipelines.html#id14)."
) from e
pipeline_type = "huggingface"
align_model = align_model.to(device)
Expand Down