Repository navigation
fix(lora): mark NPU grouped LoRA expert adapters as expert parameters - #231
Merged
Merged
Conversation
NpuGroupedLoraLinear builds one weight/bias per local expert but never set the topology metadata Megatron uses to classify expert parameters, so Megatron's parameter/gradient buffer treated these per-expert adapters as ordinary dense parameters and reduced them over the dense groups. Set allreduce = False on the per-expert weights and biases when is_expert is true; dense adapters keep the default. Expert data parallel still synchronizes replicas of the same expert. Signed-off-by: li-lizhe <147392333@qq.com>
Collaborator
|
Could you please run |
Signed-off-by: li-lizhe <147392333@qq.com>
Contributor
Author
|
Thanks! I ran the pinned hooks' tools locally (flake8, isort 8.0.1, yapf 0.43.0, plus the pre-commit-hooks checks incl. trailing whitespace / EOF / line endings). The only failure was |
addsubmuldiv
approved these changes
Oct 13, 2026
Open
3 of 8 tasks
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
NpuGroupedLoraLinearregisters oneweight{i}(and optionalbias{i}) per local expert, but those parameters never received the topology metadata Megatron uses to tell expert parameters apart from ordinary dense ones. Megatron's parameter/gradient buffer classifies an expert parameter withso without
allreduce = Falsethese per-expert adapters were indistinguishable from dense parameters and could be reduced over the dense TP/DP groups instead of the expert groups.This PR sets
allreduce = Falseon the per-expert weights and biases whenis_expertis true. Dense adapters (is_expert=False) keep the default so their reduction is unchanged, and expert data parallel still synchronizes replicas of the same expert.Verification
Environment: Ascend 910B4 (device 0),
torch 2.15.0.dev20260917+cpu,torch_npu 2.15.0.dev20260917+gitec69335, Python 3.12.npu-smireported910B4 OKduring the run.megatron-core/transformer_engine/peftare not installed on that host, so the realNpuGroupedLoraLinear.__init__was executed with the file taken verbatim from this branch and only those third-party imports stubbed, with realtorch_npu, and the resulting parameters inspected the same way Megatron's buffer inspects them.Upstream
main(before), 4 experts,is_expert=True,use_cpu_initialization=True:This branch (after), 4 experts,
is_expert=True:This branch (after), dense adapter,
is_expert=False:A regression test is added in
tests/test_npu_grouped_lora_expert_params.py.Not tested
torchrunrun (HCCL/EDP group assignment is therefore not observed).Refs #229