Repository navigation
Studio: merge LoRA and LoKR adapters into ComfyUI-quantized weights - #16874
Conversation
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. |
|
The backend CPU shards do not install The |
…cated; stub host RAM in merge tests [skip ci]
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
…ent merge [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
A ComfyUI-quantized single file (fp8 or int8 ConvRot) loaded with adapters bakes them before the compile, and they then run as layers on every step. A LoRA adds two small GEMMs per adapted Linear. A full-rank LoKR adds about a quarter of the Linear's own GEMM in bf16, which costs more than the fp8 GEMM it sits next to. ComfyUI patches the adapters into the weights instead (dequantize, add the delta, requantize), so they cost nothing per step there.
Seconds per step, RTX 6000 Ada, 1024², community adapters from #16711's set, lower is better:
qkv)The remaining MOSS-Image gap is the base model's own int8 step (0.54 against 0.44 without adapters too).
Change
New
diffusion_lora_quant_merge.py, called where a resident quantized load bakes its adapters:scale * B @ Afor a LoRA,kron(w1, w2)with its row slice for a LoKR), and the result is quantized back into the layer's ownFloat8Tensor/Int8Tensor(or plain float) tensors: a per-row scale recomputed for the merged weight, and seeded stochastic rounding, as ComfyUI rounds a patched weight. Round-to-nearest dropped every delta below half a step: the MOSS-Image LoKR's effect fell from 19.6 to 16.5 per pixel.Kept on the current adapter-layer path: offloaded loads (the host copy, not the card's, is the source there), adapters that also touch a text encoder, DoRA / LoRA-bias layers, anything but a plain or ConvRot Linear with a registered weight, other weight formats, and a host without room for the backups in its usable RAM (cgroup limits included).
UNSLOTH_DIFFUSION_LORA_QUANT_MERGE=0turns it off.At
maxspeed, diffusers' QKV fusion is skipped on a merged load: its fusedto_qkvis a copy that a weight change would not reach. Studio's own fused paths (Z-Image, MOSS-Image, int8) are views of the projections and follow it.A weight change that fails (an out-of-memory during the re-merge) leaves the base weights and records the adapters at weight 0, so the next request merges again. A load that ended up offloaded refuses weight changes with a reload message, as a streamed graph already does.
Verification
/images/generatewith no reload, for the Krea 2 LoKR, the Krea 2 LoRA, the MOSS-Image LoKR and the MOSS-Image 4-step LoRA: weight 0 equals the model without the adapter exactly (mean |diff| 0.0; with the adapter layers at weight 0 it was 1.6 to 11 per pixel), the repeated weight reproduces the image exactly (0.0), and the adapter effect matches the layer path (Krea 2 LoKR 37.2, Krea 2 LoRA 38.5, MOSS-Image LoKR 19.9 per pixel).pytest -n 8, 19,100+ tests): the only failures are the same 27 that fail on main with the same command (environment-dependent PyAV and attention-kernel tests, and tests that only fail when xdist puts them in one worker).test_diffusion_lora_quant_merge.py: merged weight againstbase + deltafor int8 ConvRot, fp8 and dense; weight 0 restores the original codes and a weight merges to the same codes twice; the qdata / scale tensors are written in place; a fusedqkvrow slice; a PEFT LoRA at its alpha / r; adapters outside the denoiser, an unsupported format and the kill switch keep the adapter layers.maxspeed never fuses QKV over merged weights (fails without its guard).test_merged_quant_file_adapters_change_weight_in_place_with_no_recompile: a compiled model follows a weight change, switching the adapter off and back on with one compile and no graph reset. It fails without the routing in_adjust_baked_loras.