Apply the allocator gc-gate fix to SD21/SDXL#27
Merged
Conversation
…R gc The torch allocated/reserved ratio gate (0.95) is chronically exceeded under backend:native (measured 0.957 steady state), firing the R gc callback on nearly every CUDA allocation: ~2,200 gcs x 62 ms per Z-Image generation. start_torch() reads the gate options only once at torch init, so the loaders now push thresholds into the live allocator directly: ratio gate off, absolute allocated_rate 0.65 as the garbage-accumulation gate, footprint-based reserved_rate as the net. Measured 1024x1024 on the RTX 5060 Ti 16 GB: Z-Image-Turbo 143 -> 24 s, klein 48 -> 13 s, FLUX.1 121 -> 55 s
load_pipeline() now routes through .flux_gc_gates() when any component is on CUDA. Measured at 50 steps (native modules, decoder on CPU, RTX 5060 Ti 16 GB), warm generation: SDXL 1024x1024: 234 -> 100 s (R gc 209 -> 75 s) SD 2.1 768x768: 101 -> 26 s (R gc 88 -> 15 s) The reduced gc cadence lets the garbage sawtooth ride higher (SD21 peak 5.4 -> 13.3 GB alloc), so smaller cards may need different gate sizing.
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.
Recreation of #25, which GitHub auto-closed when its stacked base
(feature/zimage, #24) was squash-merged and deleted.
load_pipeline()now routes through the same allocator gc-gate fix asthe FLUX/Z-Image pipelines whenever any component sits on CUDA. The
legacy SD path had the identical pathology: the torch allocated/reserved
ratio gate is chronically exceeded under backend:native, so R gc fired
on nearly every CUDA allocation.
Measured at 50 steps, warm generation (native modules, decoder on CPU,
RTX 5060 Ti 16 GB):
Notes:
collections (SD21 peak 5.4 -> 13.3 GB alloc on the 16 GB card). The
gate constants are tuned for 16 GB; smaller cards may need different
sizing — measurement tracked in Measure the allocator gc-gate fix on an 8 GB card #26.
and can OOM on 16 GB regardless of gates (decoder was on CPU for
these measurements). Pre-existing, not changed here.
Full suite 692/692.
🤖 Generated with Claude Code