fix: --device autodetect the available backend - #418
Open
rizzler13 wants to merge 1 commit into
Open
Conversation
nouraellm
reviewed
Jul 15, 2026
nouraellm
left a comment
There was a problem hiding this comment.
LGTM! The only thing I'd verify is that the existing default dtype (torch.bfloat16) behaves correctly when the auto-selected device is mps or cpu. Otherwise I don't see any issues with the change.
Author
|
Just double checked this on my machine to be sure, |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #396
Changes added:
Adds a small
_get_default_device()helper to each of the 3 CLI entry points that auto-detects the best available backend:torch.cuda.is_available()→"cuda"torch.backends.mps.is_available()→"mps"(Apple Silicon via Metal)"cpu"Files changed:
moshi/moshi/server.py— added_get_default_device(), updated--devicedefault, guardedtorch.cuda.synchronize()moshi/moshi/run_inference.py— added_get_default_device(), updated--devicedefaultmoshi/moshi/run_tts.py— added_get_default_device(), updated--devicedefaultExplicit
--device cudastill works exactly as before. The only behavioral change is the default when--deviceis omitted.Note:
seed_all()is duplicated identically inserver.pyandrun_inference.py. It's already correctly guarded (if torch.cuda.is_available()) so it's not part of the crash path, I left it untouched to keep this PR focused. Happy to consolidate it in a follow up if that'd be useful.