Fix GPU memory leak in voice conditioning cache - #166
Closed
secretzer0 wants to merge 1 commit into
Closed
Conversation
Wrap generation in torch.inference_mode so cached conds do not retain autograd graphs (~200 MB per voice).
Author
|
Saw this is a duplicate of #164. |
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.
prepare_conditionalsruns insidegenerateon a cache miss without a grad guard, so each entry stored in_conds_cachecarries the autograd graph of the reference encoders. On CUDA that is roughly 200 MB per distinct voice, held for the life of the process.Measured on an RTX 4070 8 GB with the cu128 image: 6 voices, +1341 MB allocated (
embedding.grad_fnset); the same 6 undertorch.inference_mode, +1 MB. Around 20 distinct voices producedCUDA out of memory ... 7.39 GiB is allocated by PyTorch.Fix: wrap the generate call in
torch.inference_mode(). With this change, 26 new voices plus long text went from 4414 MB to 5256 MB and stayed flat.