Skip to content

Handle transposed fp8 weights in LoRA fusion - #293

Draft
masahiroteraoka wants to merge 1 commit into
Lightricks:mainfrom
masahiroteraoka:fix/fp8-lora-offload
Draft

Handle transposed fp8 weights in LoRA fusion#293
masahiroteraoka wants to merge 1 commit into
Lightricks:mainfrom
masahiroteraoka:fix/fp8-lora-offload

Conversation

@masahiroteraoka

Copy link
Copy Markdown

PR: Handle transposed fp8 weights during scaled-mm LoRA fusion

Summary

_fp8_scaled_mm_fuse in packages/ltx-core/src/ltx_core/quantization/fp8_scaled_mm.py assumes that pre-quantized fp8 weights are stored in the standard (out, in) layout. Some fp8 checkpoints store linear weights in transposed (in, out) layout for scaled matrix multiplication.

When LoRA fusion is applied, the LoRA delta is produced in standard (out, in) layout. If the checkpoint weight is transposed, the existing dequantization path tries to add tensors with incompatible shapes and raises a shape mismatch error.

Fix

Make scaled-mm fp8 LoRA fusion shape-aware:

  • If weight.shape == deltas.shape, dequantize the weight as-is.
  • If weight.t().shape == deltas.shape, transpose before dequantizing.
  • If neither shape matches, raise a clear ValueError that includes both shapes.

This keeps the existing standard-layout path unchanged while allowing transposed fp8 checkpoint weights to fuse with LoRA deltas correctly.

Compatibility

  • Standard (out, in) fp8 checkpoints keep the same behavior.
  • Transposed (in, out) fp8 checkpoints are now handled before adding the LoRA delta.
  • The fused result is still re-quantized through the existing quantize_weight_to_fp8_per_tensor path.
  • Non-scaled fp8 and bf16 LoRA fusion rules are not changed.

Testing

  • python -m py_compile packages/ltx-core/src/ltx_core/quantization/fp8_scaled_mm.py
  • Local CPU-level inspection of the shape branches with standard and transposed toy tensors.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant