fix: avoid torchaudio shadowing in backend probe#1254
fix: avoid torchaudio shadowing in backend probe#1254uzunenes wants to merge 3 commits intofishaudio:mainfrom
Conversation
|
Just a quick update: I tested this with the latest Docker image (server-cuda), and the same UnboundLocalError is still present. Applying this exact fix resolves the issue completely, allowing the server to start and load the models without any problems. |
JiwaniZakir
left a comment
There was a problem hiding this comment.
The fix correctly addresses the shadowing issue — import torchaudio.io._load_audio_fileobj would bind torchaudio in the local namespace, potentially shadowing an earlier import, whereas importlib.import_module(...) avoids that side effect entirely.
One minor point: in both files, import importlib is placed inside the try block, which implies it could be the source of an ImportError — but importlib is a stdlib module and will never fail to import. Moving import importlib outside the try block (or to the top of the file with other imports) would more accurately communicate that only the importlib.import_module(...) call is the guarded operation.
Additionally, ModuleNotFoundError is a subclass of ImportError, so except (ImportError, ModuleNotFoundError) in both locations is redundant — except ImportError alone is sufficient and cleaner.
|
Thanks for the review @JiwaniZakir . I moved |
|
The fix is correct — using a bare |
This fixes a runtime
UnboundLocalErrorcaused by local shadowing oftorchaudiowhile probing the audio backend.
Reproduced with:
fishaudio/fish-speech:server-cuda@sha256:458725b7bffa3e8def159ec90c5a2d8b73e1d8a83c7b110e5affc271032ef71eThe issue comes from this pattern inside local scope:
That can break earlier access to
torchaudioin the same scope with:This PR replaces it with: