Skip to content

Commit 89cbd97

Browse files
committed
moe export in nemotron h
Signed-off-by: jenchen13 <[email protected]>
1 parent f8a9353 commit 89cbd97

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

modelopt/torch/export/plugins/mcore_nemotron.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
"""Custom mapping from Nemotron Hugging Face models to Megatron Core models."""
1818

1919
from .mcore_custom import (
20+
COL_ETP,
2021
COL_TP,
22+
ROW_ETP,
2123
REPLICATE,
2224
ROW_TP,
2325
CustomModuleMapping,
2426
NameRemapping,
2527
QKVMerging,
2628
QKVSlicing,
29+
GatedMLPSlicing,
30+
GatedMLPMerging,
2731
)
2832

2933
# Example on adding a new CausalLM.
@@ -39,6 +43,10 @@
3943
"linear_fc2": NameRemapping("model.layers.{}.mlp.down_proj."),
4044
"final_layernorm": NameRemapping("model.norm."),
4145
"output_layer": NameRemapping("lm_head."),
46+
# MoE
47+
"router": NameRemapping("model.layers.{}.mlp.gate."),
48+
"local_experts.linear_fc1": GatedMLPSlicing("model.layers.{}.mlp.experts.{}."),
49+
"local_experts.linear_fc2": NameRemapping("model.layers.{}.mlp.experts.{}.down_proj."),
4250
}
4351

4452

@@ -63,6 +71,12 @@
6371
"pre_mlp_layernorm": NameRemapping("backbone.layers.{}.norm.", REPLICATE),
6472
"linear_fc1": NameRemapping("backbone.layers.{}.mixer.up_proj.", COL_TP),
6573
"linear_fc2": NameRemapping("backbone.layers.{}.mixer.down_proj.", ROW_TP),
74+
# MoE
75+
"router": NameRemapping("model.layers.{}.mlp.gate.", REPLICATE),
76+
"local_experts.linear_fc1": GatedMLPMerging("model.layers.{}.mlp.experts.{}.", COL_ETP),
77+
"local_experts.linear_fc2": NameRemapping("model.layers.{}.mlp.experts.{}.down_proj.", ROW_ETP),
78+
79+
6680
}
6781

6882

0 commit comments

Comments
 (0)