Skip to content

[Feature] LoRA on INT8 convrot weights: at_runtime pushes MiniMax-H3 over 32 GB VRAM and into a 54-segment graph cut (~2x slower per step) #2392

Open

Description

@shiwano

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.safetensors via --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:

  1. immediately for int8 tensorwise / convrot: dequantize a row block, undo the rotation (W = W_rot R, R is orthogonal and symmetric), add scale * B A, rotate, requantize per output row with a new weight_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.
  2. 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^T needs only rank-sized intermediates).
  3. 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): immediately is 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

  1. added
    enhancement
    on Nov 20, 2026
  2. wbruna commented on Nov 20, 2026

    @wbruna
    Contributor
    params 19998 MiB
    DiT compute buffer 9988.18 MB
    LoRA size 1.96 GB

    Yep, looks like you are exceeding your ~30.5G available VRAM, by 1.5G or so.

    or make the at_runtime path cheap enough that the model still runs as one segment.

    Sorry: how could that possibly work? at_runtime runs 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 immediately was supported for int8_convrot, it wouldn't be for free, because dequantizing and requantizing the weights for merging would demand a lot of processing.

    Distilled few-step LoRAs are the normal way to run MiniMax-H3 locally

    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 .

  3. shiwano commented on Nov 21, 2026

    @shiwano
    Author

    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.safetensors from that repo is a compressed version of the same LoRA (average rank ~21, 327 MB instead of 1.96 GB).

    Using at_runtime:

    LoRA LoRA size DiT compute buffer Segments Per step
    None — 6383.54 MB 1 10.5 s
    Turbo, original 1.96 GB 9988.18 MB 54 ~19 s
    Turbo, compressed 327 MB 9988.18 MB 54 15.8 s

    The compressed-LoRA row and the immediately numbers 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 with at_runtime is 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 separate lora_down and lora_up projections, so I measured how the extra workspace scales. It scales with the number of frames rather than the LoRA's rank:

    Latent frames No LoRA at_runtime Extra
    12 2484 MB 3311 MB 826 MB
    22 3979 MB 5941 MB 1962 MB
    37 (124 video frames) 6384 MB 9988 MB 3604 MB

    That 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_diff tensors 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 immediately isn'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-server retains the merged weights, so only the first request pays the merge cost.

    For a single 4-step sd-cli run, 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.

  4. wbruna commented on Nov 23, 2026

    @wbruna
    Contributor

    on int8_tensorwise / convrot diffusion weights without the runtime path's extra compute buffer: either support --lora-apply-mode immediately for these weights

    Support was added in #2403 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions