fix: correct LoRA initialization and forward pass under tensor parallelism#150
Open
chen2021673 wants to merge 4 commits into
Open
fix: correct LoRA initialization and forward pass under tensor parallelism#150chen2021673 wants to merge 4 commits into
chen2021673 wants to merge 4 commits into
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.
Replace BroadCast's allocate-then-return signature with an in-place form (void return) that takes pre-grouped tensors per local device. Lets root ranks broadcast directly out of the source tensor with no self-copy and no extra allocation. Add ScatterFromRank as the multi-process counterpart to Scatter for the same reason. Use both in LoRA*ParallelLinear so TP rank-0 init no longer pays a tp_size-fold communication or scratch cost.
8459156 to
f918ae3
Compare
Remove the device-grouped tensor layout requirement from BroadCast and ScatterFromRank — derive each tensor's group rank from its own device instead. LoadLoRAWeights now infers TP rank from the destination tensor's device with strict shape/divisibility checks, rather than relying on global tp_rank.
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
Fix LoRA loss divergence under tensor/data parallel training by aligning LoRA initialization, forward collective ordering, and test-time weight loading.
Changes
LoRAColumnParallelLinear: compute base shard + LoRA shard first, then run one gather when needed.LoRARowParallelLinear: compute base shard + LoRA shard first, then run one reduce/reduce-scatter when needed.lora_Afrom TP rank 0.lora_Aon TP rank 0 and scatter shards by TP rank.ProcessGroup::BroadCastandScatterFromRankhelpers for TP-aware initialization.Motivation
Previously, LoRA and base linear paths could perform separate TP collectives. That changed the floating-point reduction/gather ordering and made LoRA runs diverge across TP/DDP configurations. Replicated and sharded LoRA initialization also needed to be rank-consistent so every TP rank starts from the same logical LoRA weights.