Repository navigation
Description
Feature Summary
Make a LoRA usable on int8_tensorwise / convrot diffusion weights without the runtime path's extra compute buffer: either support --lora-apply-mode immediately for these weights, or make the at_runtime path cheap enough that the model still runs as one segment.
Detailed Description
Setup: RTX 5090 (32 GB), Windows CUDA12 build of master-1106-532d2c1, MiniMax-H3 Ref2VA at 1248x704, 124 frames, --cfg-scale 1.0.
- DiT:
minimax_h3_ref2va_pruned_int8_convrot.safetensors(Comfy-Org/MiniMax-H3), params 19998 MiB - LoRA:
minimax_h3_ref2v_turbo_4step_v0.1_comfyui_bf16.safetensorsvia--lora-model-dir+<lora:...:1>, 624 / 624 tensors applied - auto-fit:
--backend "diffusion=CUDA0,te=CUDA0,vae=CUDA0" --params-backend "te=cpu,vae=cpu", GPU budget 30479 MiB
| DiT | LoRA | segments | DiT compute buffer | per step (steady state) |
|---|---|---|---|---|
| INT8 convrot | none | 1 | 6383.54 MB | 10.5 s |
| INT8 convrot | turbo, at_runtime | 54 | 9988.18 MB | ~19 s |
GGUF Q4_K_M (leejet/MiniMax-H3-GGUF), --params-backend "te=cpu,vae=cpu" |
none | 1 | 8369.00 MB | 14.8 s |
GGUF Q4_K_M, --params-backend "te=cpu,vae=cpu" |
turbo, at_runtime | 1 | 10349.19 MB | 17.1 s |
With the LoRA on the INT8 file the log shows apply lora at runtime, the compute buffer grows by about 3.6 GB, and the DiT is cut into 54 segments. During sampling loading N/732 tensors from ... appears 83 times (once without the LoRA). The GGUF rows separate the two costs: with one segment in both cases the runtime LoRA adds about 2.3 s per step, so most of the 8.5 s added on the INT8 file comes from the graph cut. The picture is correct; only the speed changes.
--lora-apply-mode immediately does not help, because configure_weight_loading falls back:
https://github.com/leejet/stable-diffusion.cpp/blob/532d2c15c4/src/pipeline/diffusion_engine.cpp#L1058-L1063
[W] ComfyUI INT8/packed INT4 weights do not support the immediately LoRA apply mode; using at_runtime instead
Sampling was 109.8 s, still 54 segments.
For reference, ComfyUI runs the same DiT, LoRA, resolution and step count in 55-58 s wall time for the whole job on the same GPU.
Possible directions, whichever fits the design:
immediatelyfor int8 tensorwise / convrot: dequantize a row block, undo the rotation (W = W_rot R,Ris orthogonal and symmetric), addscale * B A, rotate, requantize per output row with a newweight_scale. Equivalently, rotate the LoRA delta once (ΔW R) and add it in the rotated domain before requantizing, so no un-rotation of the base is needed.- Keep at_runtime but shrink its footprint for these layers, so a model that fits without a LoRA still fits with one (the low-rank branch
X A^T B^Tneeds only rank-sized intermediates). - Let auto-fit account for the at_runtime LoRA buffer when it decides the plan, and say in the log that the LoRA is what forced the cut.
Alternatives you considered
--lora-apply-mode immediately: rejected for these weights, as above.- The GGUF DiT (
minimax_h3_ref2va_pruned-Q4_K_M.gguf, 10.9 GB):immediatelyis rejected with the same warning (packed INT4), and the base speed is lower than INT8 convrot (14.8 vs 10.5 s per step). With default auto-fit it is much slower still: the freed VRAM goes to keeping the text encoder params on the GPU (--params-backend "vae=disk"), and the DiT is cut into 54 segments even without a LoRA (sampling 694 s for 20 steps). The same seed also gives a different take, while the INT8 file matches ComfyUI closely (PSNR 33.4 dB against ComfyUI, 17.1 dB between INT8 and GGUF). - Merging the LoRA into the float checkpoint offline and re-exporting INT8 convrot: needs the unquantized DiT and a converter, per LoRA combination.
Additional context
Distilled few-step LoRAs are the normal way to run MiniMax-H3 locally, so this path is the common one rather than a corner case. I can test builds on the RTX 5090 against ComfyUI output for the same inputs.
Activity
wbruna commentedon Nov 20, 2026
Yep, looks like you are exceeding your ~30.5G available VRAM, by 1.5G or so.
Sorry: how could that possibly work?
at_runtimeruns the LoRA separate from the model, by definition; and that LoRA alone has 2GB of weights. If you are close to the VRAM limit for a given resolution and number of frames, of course loading it will get you past that limit.By the way: even if
immediatelywas supported for int8_convrot, it wouldn't be for free, because dequantizing and requantizing the weights for merging would demand a lot of processing.You could try a smaller LoRA: for instance, https://huggingface.co/drbaph/MiniMax-H3-Turbo-Lora-ComfyUI has a few around 300MB. Or a pre-merged checkpoint, like https://huggingface.co/PulpCut/MiniMax-H3-Ref2VA-Turbo-INT8-ConvRot .
shiwano commentedon Nov 21, 2026
Thanks for looking into this, and for the suggestions!
I tried the smaller LoRA.
minimax_h3_ref2v_turbo_4step_v0.1_comfyui_resized_avg_rank_21_bf16.safetensorsfrom that repo is a compressed version of the same LoRA (average rank ~21, 327 MB instead of 1.96 GB).Using
at_runtime:The compressed-LoRA row and the
immediatelynumbers below are from a Linux CUDA build (WSL2) of the same commit; the first two rows are the Windows numbers from the issue. On Linux, the no-LoRA baseline is 11.6 s/step and the original LoRA withat_runtimeis 18.7 s/step.Both LoRAs require the same 9988 MB compute buffer, adding ~3.6 GB of workspace regardless of rank and leaving less than 500 MiB of GPU headroom before loading the LoRA weights.
Looking at
get_out_diff(), the runtime path already uses separatelora_downandlora_upprojections, so I measured how the extra workspace scales. It scales with the number of frames rather than the LoRA's rank:at_runtimeThat is about 110 MB per latent frame (858 tokens), roughly the size of two FFN-width activations plus one hidden-width activation. So it looks like full-size
out_difftensors living next to the layer outputs, rather than anything rank-sized. Could those be added into the output in place, or freed earlier?You're also right that
immediatelyisn't free. I've implemented per-row INT8 merging, including convrot (rotating the LoRA delta into the stored basis, then requantizing the affected rows with updated scales). On this checkpoint, merging takes about 140 s.After merging, the DiT runs as a single segment at 11.5 s/step with a 6384 MB compute buffer, the same as without a LoRA.
sd-serverretains the merged weights, so only the first request pays the merge cost.For a single 4-step
sd-clirun, it's slower overall (278 s vs 160 s wall time). But for a long-running server, avoiding the 54-segment execution on every request seems like a useful trade-off.I'd be happy to open a PR with the implementation and benchmarks if this approach would be worth supporting.
I also tested the suggested pre-merged checkpoint. It runs in one segment at 10.4 s/step with a 6384 MB buffer. However, it produces a different output (22.8 dB PSNR vs ComfyUI, compared with 32.0 dB for my merge), which may be expected since it uses a different Turbo LoRA. It also doesn't cover arbitrary LoRAs.
wbruna commentedon Nov 23, 2026
Support was added in #2403 .