Repository navigation
Studio diffusion: keep reference headroom on multi-GPU FLUX.2 klein splits so edits are not refused - #14858
Conversation
…xt-to-image tier seed The dense default / max tier seed (#14720) was measured on text-to-image. measured_request_extra_mib sizes a Klein reference request from the flat estimate, and on one card the resident DiT groups stream back to pay for it. A companion or layer split keeps no such groups, yet the split was priced from the seed, so it packed the primary with weights a reference request could not get back. On two T4s a two-image edit at 1024x1024 was refused where the flat placement tiled the decode and ran. Mark a seeded plan whose family carries unpriced references (measured_omits_references) and price the multi-GPU split from the flat or calibrated headroom for it, as before the seed. One-card placement still uses the seed, the eager tier is unchanged, and text-to-image-only families keep the seeded split.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 86c4227e46
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| measured_headroom = ( | ||
| None | ||
| if plan.estimates.get("measured_omits_references") | ||
| else plan.estimates.get("measured_runtime_headroom_mib") |
There was a problem hiding this comment.
Keep learned headroom above the flat fallback
When a FLUX.2 Klein configuration has a persisted learned peak above the flat runtime estimate, measured_image_runtime_mib stores that larger value in measured_runtime_headroom_mib, but this branch discards it solely because references are unpriced and substitutes the smaller flat estimate. The resulting companion or layer split can pack in more weights than the observed peak permits and OOM; the reference fallback should use the maximum of the measured and flat headroom rather than replacing the measured value.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch. The reference fallback now takes the larger of the measured headroom and the flat (or calibrated) estimate, so a learned peak above the flat estimate still prices the split. Added a test that checks the split is priced at max(measured, flat) for a learned peak both above and below the flat estimate.
…llback split The multi-GPU reference fallback replaced the measured headroom with the flat estimate. A learned peak above the flat estimate is stored as the measured headroom, so the split could then be priced below a peak this machine already recorded. Take the larger of the two instead. [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
# Conflicts: # studio/backend/core/inference/diffusion.py # studio/backend/core/inference/diffusion_multigpu.py [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
#14720 seeds dense fp16 denoisers (T4, V100, Turing) on the default and max tiers from a text-to-image measurement, and #14866 seeds FLUX.2 Klein from its measured phase table. A FLUX.2 Klein reference request is not covered by either seed. Its source image joins the denoiser's sequence without being priced, so
measured_request_extra_mibsizes the request from the flat estimate. On one card the resident DiT groups stream back to pay for that, which is fine.A multi-GPU companion split or layer split has no resident groups to stream back, and
hook_resident_denoiseronly hooks torchao denoisers. The split was still priced from the seed. That packs the primary with weights a reference request cannot get back, and the request guard then refuses the edit:The refusal is not needed. Measured on real FLUX.2-klein-4B (bf16, B200, diffusers, 1024x1024), the reference images add at most about 1.5 GiB to the peak. The latent-only peak is 621 MiB for text-to-image, 1583 MiB with one reference, 1652 MiB with two and 2168 MiB with three. With the untiled decode included, the peak is 2477 to 2487 MiB in every case.
Fix
refine_plan_from_loaded_weightsrecordsmeasured_omits_referencesunder the same condition that makesmeasured_request_extra_mibsize a reference request from the flat estimate: the family's references go unpriced, the tier is default / max, and the plan was placed from a dense tier seed (dense denoiser) or a phase seed (torchao denoiser).refine_plan_for_multigpuprices the companion and layer split from the larger of the measured headroom and the calibrated / flat headroom for such a plan.DiffusionBackendsetspipe._unsloth_unpriced_referencesfrom the family through_references_unpriced. That covers FLUX.2 Klein, and excludes FLUX.3 and families withreference_resolutions._calibrated_activationreuses the same helper for its reference rule.What does not change:
Tests
tests/test_diffusion_multigpu_reference_headroom.py(CPU, fake cards). 5 of its 9 tests fail on main and all pass here:Across all 279
tests/test_diffusion*.pyfiles (CPU,-n 4): 17145 passed here and 17136 on main (the 9 new tests). The same 47 tests fail on both sides (identical IDs), for exampletest_diffusion_multigpu.py::test_execution_device_reports_the_primary_of_a_split_pipeline; none of them touch this change.Real 2x T4 (Kaggle, one kernel)
FLUX.2-klein-4B (fp16), default tier, automatic multi-GPU placement, a two-image reference edit at 1024x1024 (source + one reference, both 1024x1024), 4 steps. Base is main, head is this branch, both in the same kernel.
Text-to-image at 1024x1024 on this PR's placement: 2.42 s/step (first render, including the CUDA graph captures), peak 1967 / 8197 MiB.
Not covered