perf: reduce GPU memory usage during inference#447
Open
haoyu-haoyu wants to merge 1 commit intoRosettaCommons:mainfrom
Open
perf: reduce GPU memory usage during inference#447haoyu-haoyu wants to merge 1 commit intoRosettaCommons:mainfrom
haoyu-haoyu wants to merge 1 commit intoRosettaCommons:mainfrom
Conversation
- Move trajectory data (px0, x_t, seq, plddt) to CPU immediately after each denoising step instead of accumulating on GPU. This frees GPU memory for the next forward pass, reducing peak memory usage proportional to the number of diffusion steps. - Remove two unused ComputeAllAtomCoords() instantiations in get_next_ca() and get_next_pose() that were created every timestep but never referenced, wasting memory and compute.
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.
Summary
Offload trajectory to CPU per step: Move
px0,x_t,seq,plddtto CPU immediately after each denoising step instead of accumulating all steps on GPU. Peak GPU memory is reduced fromO(T × L × 14 × 3)toO(L × 14 × 3)for trajectory storage.Remove unused
ComputeAllAtomCoords()instantiations:get_next_ca()andget_next_pose()ininference/utils.pycreated aComputeAllAtomCoords()module every timestep but never used it. Removed both instantiations and the now-unused import.Why this is safe
x_tandseq_tare produced fresh bysampler.sample_step()each iteration — the active computation tensors remain on GPU. Only the previous step's saved copies (for trajectory visualization) are moved to CPU. The finaltorch.stack()andtorch.flip()operate on CPU tensors, which is fine since they're only used for PDB writing.Impact
For a 200-residue, 50-step design, this reduces GPU memory for trajectory storage from ~50× to 1× the single-step footprint. This is especially important for longer proteins (>300 residues) that can OOM on 16GB GPUs.
Test plan
torch.cuda.max_memory_allocated()tests/test_diffusion.py