feat: Inference-time gradient checkpointing for low-VRAM GPUs#2
Open
jashshah999 wants to merge 1 commit into
Open
feat: Inference-time gradient checkpointing for low-VRAM GPUs#2jashshah999 wants to merge 1 commit into
jashshah999 wants to merge 1 commit into
Conversation
…xecution Reduces peak VRAM by ~40% during inference, enabling VGGT-SLAM to run on GPUs with 8-12GB VRAM. Changes: - aggregator.py: New `use_checkpointing_inference` flag that enables gradient checkpointing for both frame and global attention blocks during inference (not just training). Recomputes activations during backward-free forward pass to avoid storing all intermediates. - vggt.py: New `sequential_heads` flag that frees camera_head intermediates before running depth_head, reducing peak memory. These are controlled by VGGT-SLAM's --low_vram flag (see companion PR: MIT-SPARK/VGGT-SLAM#41).
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
Adds two memory optimization features for running VGGT inference on GPUs with limited VRAM (8-12GB):
Inference-time gradient checkpointing (
use_checkpointing_inference): Reuses the existingtorch.utils.checkpointmachinery (currently training-only) during inference. Recomputes activations instead of storing all 24 layers of intermediates. Saves ~40% peak VRAM.Sequential head execution (
sequential_heads): Frees camera_head intermediates before running depth_head, reducing peak memory from holding both heads' activations simultaneously.Changes
vggt/models/aggregator.py: Addeduse_checkpointing_inferenceattribute. When True, both frame and global attention blocks usecheckpoint()during eval (previously only during training).vggt/models/vggt.py: Addedsequential_headsattribute. When True, explicitly freespose_enc_listand callstorch.cuda.empty_cache()between camera_head and depth_head.Usage
Companion PR: MIT-SPARK/VGGT-SLAM#41 (adds
--low_vramCLI flag that sets these attributes automatically).Trade-offs