fix: correct LoRA initialization and forward pass under tensor parallelism#150
Open
chen2021673 wants to merge 2 commits intomasterfrom
Open
fix: correct LoRA initialization and forward pass under tensor parallelism#150chen2021673 wants to merge 2 commits intomasterfrom
chen2021673 wants to merge 2 commits intomasterfrom
Conversation
…ence Inline base and LoRA matmuls, add locally, then issue a single AllGather/AllReduce instead of two separate collective ops. The prior two-collective approach caused floating-point divergence in DDP loss. Also fix LoadLoRAWeights to slice sharded tensors by tp_rank when the checkpoint shape differs from the partitioned model shape.
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
Broadcast lora_A init from TP rank 0
LoRAColumnParallelLinear::lora_A is replicated across TP ranks but was independently random-initialized on each rank. This relied on every rank having an identical RNG state — a fragile implicit assumption flagged as broken in init.cc. The fix: only TP rank 0 generates random values; all other ranks zero-initialize; then AllReduce(sum) propagates rank 0's values to the group. No-op when TP size == 1.
Fuse base+LoRA matmuls before collective
The previous forward pass ran the base module and LoRA branch independently, each triggering its own collective (AllGather for Column, AllReduce for Row). Running two separate collectives on floating-point results caused loss divergence due to non-associativity of floating-point addition across the reduction boundary. The fix inlines both matmuls locally, adds them before the collective, then issues a single collective op — matching the approach used in the base parallel linear layers.
Also includes a LoadLoRAWeights fix to correctly slice sharded tensors (e.g. lora_B in ColumnParallel) when loading checkpoints under TP.