You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On Windows, inspect.py lives at paths like C:\Python311\Lib\inspect.py, so this guard never triggers. Lazy modules with optional dependencies (notably speechbrain.integrations.k2_fsa, which requires k2) can be imported unintentionally during normal model loading, causing hard ImportError crashes on Windows even when k2 is never used.
Replace the slash-specific endswith("/inspect.py") check with os.path.basename(importer_frame.filename) == "inspect.py".
os is already imported in this file; no new dependencies.
Independent confirmation, from a different and more consequential failure mode than #2798 (which only affected test collection).
This breaks import pyannote.audio outright in normal usage — not in a test suite. pyannote.audio's speaker-embedding loading path touches speechbrain's deprecation-redirect shims (speechbrain.k2_integration, .wordemb, .lobes.models.spacy/.flair) during torch's fake-kernel registration, and any shim whose target is a genuinely-missing optional package (k2, flair, spacy) raises ImportError, which propagates through inspect.getmodule's hasattr() check and kills whatever unrelated import triggered it.
Confirmed this PR's fix (os.path.basename(...) == "inspect.py") resolves it on Windows 10 / Python 3.13 / speechbrain 1.1.0, with real lazy exports, deprecation warnings, and genuine ImportErrors for explicitly-requested missing integrations all still behaving correctly.
One thing worth flagging for anyone hitting this in the meantime: pyannote.audio 4.0.7 looks like it fixes this (a quick import pyannote.audio succeeds), but it only reorders pyannote's own imports to dodge the trigger — import speechbrain; import pyannote.audio still fails on 4.0.7. Any code importing speechbrain earlier (ours did, via audio-loading libraries) hits this regardless of pyannote version.
Would be great to see this merged — it's a one-line fix for a guard whose intent (per the existing code comment about "PyTorch's op registering machinery") is already exactly right.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
On Windows, inspect.py lives at paths like
C:\Python311\Lib\inspect.py, so this guard never triggers. Lazy modules with optional dependencies (notablyspeechbrain.integrations.k2_fsa, which requiresk2) can be imported unintentionally during normal model loading, causing hardImportErrorcrashes on Windows even when k2 is never used.Replace the slash-specific
endswith("/inspect.py")check withos.path.basename(importer_frame.filename) == "inspect.py".osis already imported in this file; no new dependencies.Before submitting
PR review
Reviewer checklist