diff --git a/tests/test_alignment.py b/tests/test_alignment.py index 82ba04f88..de0611c3f 100644 --- a/tests/test_alignment.py +++ b/tests/test_alignment.py @@ -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 diff --git a/whispermlx/alignment.py b/whispermlx/alignment.py index b847f8af1..d39131120 100644 --- a/whispermlx/alignment.py +++ b/whispermlx/alignment.py @@ -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)