fix(models): avoid batch-wide float target masks on CUDA - #1437
Open
JESUSROYETH wants to merge 1 commit into
Open
fix(models): avoid batch-wide float target masks on CUDA#1437JESUSROYETH wants to merge 1 commit into
JESUSROYETH wants to merge 1 commit into
Conversation
JESUSROYETH
requested review from
Borda,
SkalskiP,
isaacrob and
probicheaux
as code owners
September 5, 2026 23:56
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1437 +/- ##
=======================================
Coverage 87% 87%
=======================================
Files 114 114
Lines 15099 15108 +9
=======================================
+ Hits 13062 13071 +9
Misses 2037 2037 🚀 New features to boost your workflow:
|
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.
CUDA mask-label sampling currently concatenates the matched masks across the batch, then converts the full tensor to float32. In the workload below, SegSmall at batch 20 ran out of memory at that conversion on an L4.
Changes
The fix samples one image at a time with the same native nearest-neighbour sampler, then concatenates the sampled labels. In the loss's no-grad path, each image's full float temporary can be released before sampling the next. CPU and unsupported CUDA inputs keep the existing path; no new option or change to the loss formulas.
Performance
I measured this with
RFDETRSegSmall/RFDETRSegMedium, PyTorch 2.9.1+cu129, on a COCO val2017 subset (512 training / 16 validation images), one epoch, seed 51, two workers, default multi-scale and EMA. Times cover the public.train()call end to end, including validation and checkpoints, and repeated values are medians.Batch 20 failed twice before the change and completed twice after. The original also failed with
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True. Timing ranges overlap at batch 4 (52.59–53.86 / 52.25–53.14 s) and batch 8 (44.98–46.01 / 44.96–45.23 s), so this is a memory/capacity fix, not a speedup claim .. it doesn't establish the maximum supported batch size either.Validation
The criterion suite passed 60 tests (44 CPU and 16 CUDA, one XLA skip), plus 3 doctests. Pre-commit is clean, strict mypy included. I checked the sampled labels for byte-identity in 20 real-training sampler calls across Kornia/torchvision, with baseline-self and active-route checks. Full-training baseline repeats already give different final weights on their own, so byte parity here is about the sampled labels, not the final model. DDP and compiled training were not benchmarked.