perf: keep the LoGeR input batch on the host - #35
Open
HuguesSib wants to merge 1 commit into
Open
Conversation
Pi3.forward already moves each sliding window to the model's device, so preloading the whole resized sequence onto the GPU held VRAM for frames that were not being decoded. Dropping the preload saves 1.6 MiB of VRAM per frame at the default 504x280 processing size. Measured on an RTX 3090 over 600 frames: peak allocated 12561 -> 11587 MiB, inference 59.5 -> 58.8 s, and a checksum over depth, poses, points and confidence is unchanged. The MPS fallback's batch_t.cpu() is now a no-op and is removed; moving the model is what that path needs.
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 #19. Thanks @Matt-Tav for the report and the diagnosis, which was correct.
Why
process_sequencepreloaded the entire resized sequence onto the GPU:That was never needed.
Pi3.forwardslices the sequence into sliding windows and moves each one to the model's device itself:image_meanis a registered buffer, so it tracksmodel.to(device)and the window always lands on the right device. Only the window being decoded ever had to be resident. The rest of the sequence just held VRAM.No submodule bump is required. The per-window
.to()is already present at our pin (13d78a0). The upstream commit linked in the issue (7685b7a) touches onlydemo_viser.py, and applies the same one-line change to LoGeR's own demo script.What
.to(self._device)on the input batch.batch_t = batch_t.cpu()from the MPS fallback. Moving the model is what that path needs; the batch is already on the host.test_loger_hands_the_model_a_host_resident_batch, which recordsTensor.tocalls on the 5-D batch and asserts the model receives it on CPU. Verified to fail if the preload is restored.Measurements
RTX 3090, 600 frames at the default 504x280,
window_size=32,overlap_size=3.bbf026eb0989914cbbf026eb0989914cThe 974 MiB saving is exactly the batch tensor (600 x 504 x 280 x 3 x 4 B = 969 MiB), so it scales linearly at 1.6 MiB/frame. A 1500-frame run saves about 2.4 GiB.
The checksum covers
depth_maps,poses_w_c,local_points,world_pointsandconfidence. It is unchanged, so this shifts no numeric output and the changelog entry sits under Fixed rather than Changed.Inference time is unchanged, confirming the report's observation that the per-window host-to-device copy is fully hidden behind compute.
On
.pin_memory()The issue also suggested pinning the batch. I left it out. The transfer at
pi3.py:671is synchronous (nonon_blocking=True), so pinning cannot overlap it with compute, and the timing above shows nothing to recover. Page-locking a multi-GB host tensor is also a poor trade on the low-RAM field machines this tool targets. Worth revisiting only alongside an asyncnon_blocking=Truecopy.What this does not fix
The input batch is only about 12% of the per-frame VRAM cost. Peak allocated decomposes as:
The third term is the real cap on sequence length.
_merge_windowed_predictionskeeps every window'spoints,local_pointsandconfon the device until the merge at the end. Offloading each window's predictions to the host as it completes is the larger win, and is a separate change. Filing that as a follow-up issue.🤖 Generated with Claude Code