Repository navigation
Conversation
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 #635.
Why this change
When SAM3 resolves overlaps between object masks, its zero-background path converts yes/no masks into larger numeric tensors. The tracking callers then convert the result back to boolean. This uses extra memory for an output that only needs to say which pixels belong to each object.
This PR removes that avoidable memory overhead by keeping the masks boolean, while preserving the selected pixels used by existing tracking callers.
What changes
A small fast path in
Sam3TrackerPredictorandSam3VideoTrackingMultiplexDemoreturns a boolean mask after the existing winner selection when the input is boolean and the background is0or0.0. Floating masks and nonzero backgrounds retain their current behavior. Inputs are not modified.Validation
The final regression file passed 260 cases on CPU and 260 on CUDA, with zero skips, using PyTorch 2.7.1+cu128 on an RTX 4070 Ti SUPER. Earlier Colab isolated-method checks also passed. These checks cover both helpers, confirm the same binary results as the existing path, and exercise fallback behavior.
In synthetic eager T4 benchmarks (PyTorch 2.11.0+cu130) with 16 masks at 1080p, peak helper allocation fell about 59% for background
0and 36% for0.0. Median helper time fell about 53-54% and 34-36%, respectively.These results cover eager helpers; full-model/video performance, total device VRAM savings, and compiled behavior remain unmeasured. The test and tracker file pass formatting. The repository-wide formatting check reports the same pre-existing failures on pristine upstream main; upstream CI remains pending.
Run the regression test from the patched checkout in a provisioned SAM3 environment:
Specify the file explicitly because default discovery targets
tests/, while this test is undertest/. CUDA requires an available GPU; skipped cases do not establish GPU validation.