[peft] fix: fall back for unaligned dense multi-LoRA grouped MM - #32
Conversation
Signed-off-by: Ethan (Yusheng) Su <yushengsu.thu@gmail.com>
|
/ok to test e93ef87 |
Rename _GROUPED_MM_ALIGNMENT_BYTES to _PYTORCH_GROUPED_MM_ALIGNMENT_BYTES and document, together with _GROUPED_MM_SUPPORTED_DTYPES, that both mirror PyTorch ATen's GroupedMMUtils.h CUDA layout contract rather than being tunables, plus the asymmetric failure modes (too strict -> safe fallback, too loose -> loud host-side TORCH_CHECK). Tests: reuse the constant instead of a second alignment literal; add a GPU boundary canary proving a 16-but-not-32-byte-aligned BF16 input is admitted by _can_use_grouped_mm and accepted by torch._grouped_mm itself (allocator-natural tensors are 256B-aligned and could never catch the contract tightening); add a seeded 50-case equivalence check for the device/host _narrow_token_counts_to_window twins. Signed-off-by: Ethan (Yusheng) Su <yushengsu.thu@gmail.com>
|
Follow-up 9872e0f applies the agreed polish: the alignment constant is now |
Summary
MultiLoRALinearprojection on PyTorch grouped-MM's 16-byte address, stride, dtype, and output-layout requirementsF.linearonly for unsafe A or B projections while preserving the existing TP/SP collective placement and the aligned grouped-MM fast pathRoot cause
With TP8 and a physical max LoRA rank of 16, the column-parallel A projection has a local BF16 rank of 2. The TP gather's backward produces a contiguous
[tokens, 2]gradient with a 4-byte leading stride, while PyTorch grouped-MM requires non-unit strides and operand addresses to be 16-byte aligned. The failure therefore occurs inside grouped-MM backward before the optimizer runs:The selector uses the physical local weight shape and current tensor layout, not the adapter's logical rank. Unsafe inputs use the mathematically equivalent per-slot linear path for both projections. Every slot is still evaluated, including empty slots, so Megatron gradient hooks observe present zero gradients.
Validation
Validated on NVIDIA H200 with PyTorch
2.11.0+cu130:origin/bridgereproduced the 16-byte stride exceptionfallback=1, grouped_mm=1, proving the unaligned local A uses fallback while the gathered, aligned B keeps the fast pathfallback=0, grouped_mm=284 passedacross:tests/unit_tests/peft/test_multi_lora_layers.pytests/unit_tests/peft/test_multi_lora.pytests/unit_tests/peft/test_multi_lora_moe.pyuv run --no-project pre-commit run --all-filespassedScope
This PR fixes the dense
MultiLoRALinearpath.MultiLoRAGroupedExpertLinearis unchanged; its physical rank alignment remains a separate concern. The validation covers the exact TP8 dense layer and collective path, but it is not a fresh full 744B GLM-5.2 end-to-end rerun at max-rank 16.PyTorch grouped-MM references: