fix: handle empty samples and add CUDA fallback#182
Open
mshzy wants to merge 1 commit into
Open
Conversation
- generator.generate(): return zero tensor when no audio samples generated - load_csm_1b(): auto-fallback to CPU when CUDA unavailable
ZackHodari
requested changes
Jun 2, 2026
Collaborator
ZackHodari
left a comment
There was a problem hiding this comment.
Nice fix
Small cleanup and a question about dtypes
| warnings.warn("CUDA not available, falling back to CPU") | ||
| model = Model.from_pretrained("sesame/csm-1b") | ||
| model.to(device=device, dtype=torch.bfloat16) | ||
| model.to(device=device, dtype=torch.bfloat16 if device == "cuda" else torch.float32) |
Collaborator
There was a problem hiding this comment.
bfloat16 should work on CPU, please share more details if you tested it and found it doesn't work
| def load_csm_1b(device: str = "cuda") -> Generator: | ||
| if device == "cuda" and not torch.cuda.is_available(): | ||
| device = "cpu" | ||
| import warnings |
Collaborator
There was a problem hiding this comment.
Move import to top level
|
|
||
| if not samples: | ||
| # No audio generated (e.g., empty prompt or immediate EOS) | ||
| return torch.zeros(1, device=self.device) |
Collaborator
There was a problem hiding this comment.
I'd prefer it returns a tensor with 0 samples, we shouldn't make up data
Suggested change
| return torch.zeros(1, device=self.device) | |
| return torch.zeros(0, device=self.device) |
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.
Fixes: 1) torch.stack crash when no samples generated, 2) load_csm_1b crash on CPU-only systems