Repository navigation
Conversation
…ut and scale the rank-sized intermediate
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.
Summary
With
lora_modeseparate(and for the projections thatconsumerdoes not fuse), every LoRA linear runsadd_lora(output, x) = (output + apply_lora(x)).to(output.dtype)withapply_lora(x) = lora_strength * lora_scale * ((x @ A^T) @ B^T). Besides the two small GEMMs this makes three extra passes over the [tokens, out] tensor: the up projection writes a new tensor, the scale multiply reads and writes it, and the add reads it together with the base output and writes the sum. For the fused FFN input projection of MiniMax-H3 (out = 28672) at 37.9k tokens each pass moves 2-6 GB.apply_loramultiplieslora_strength * lora_scaleinto the [tokens, rank] intermediate instead of the [tokens, out] product (same arithmetic, one rounding;consumermode benefits throughproject_parts).add_loraaccumulates the up projection into the base output withaddmm_(the GEMM's beta = 1 epilogue) when the output is a 2-D tensor with unit stride in the LoRA dtype; otherwise it keeps the previous expression. All call sites pass a fresh GEMM result, so accumulating in place is safe. Base GEMMs (including quantized ones) are not touched, and the scale stays a device tensor (no host sync).Results
AMD Radeon AI PRO R9700 (gfx1201), ROCm 7.2.4, torch 2.10.0. LightX2V main 83a424a. MiniMax-H3 DiT shapes, M = 37869 tokens (768x1344x124), rank 128; mean of 10 calls after 3 warmup calls.
End to end (MiniMax-H3 t2av, 768x1344x124, 4-step LoRA, block offload, same GPU, sequential runs):
fp8-tritonDiT,lora_mode: separatefp8-tritonDiT, dynamic LoRAfp8-tritonDiT,lora_mode: consumerNumerics: against an FP32 reference the LoRA linear error goes from 2.40e-3 to 2.34e-3 (one rounding less); the outputs differ from the previous ones by 1.5e-3. As with any rounding change, 4-step sampling then diverges in fine detail (video PSNR 20.5 dB against the previous output; a same-config rerun gives 47 dB and FP8 vs BF16 gives 20.4 dB), with no visible degradation.
NVIDIA
GeForce RTX 5090 (sm_120), torch 2.11.0+cu130, Triton 3.6.0; same shapes and method.
The same linears without LoRA stay within 1% of their previous times, and the outputs differ from the previous ones by 1.5e-3, as on gfx1201.