Skip to content

Commit 7999789

Browse files
committed
Add pg_collection when init PackedPerExpertLinear
Signed-off-by: Hollow Man <hollowman@opensuse.org>
1 parent 79e3bdf commit 7999789

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎src/megatron/bridge/peft/utils.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2634,13 +2634,15 @@ def __init__(
26342634
init_method: Optional[Callable] = None,
26352635
dtype: Optional[torch.dtype] = None,
26362636
device: Optional[torch.device] = None,
2637+
pg_collection: ProcessGroupCollection | None = None,
26372638
):
26382639
super().__init__()
26392640
if not hasattr(torch, "_grouped_mm"):
26402641
raise RuntimeError("PackedPerExpertLinear requires torch._grouped_mm (torch >= 2.9).")
26412642
self.num_local_experts = num_local_experts
26422643
self.in_features = in_features
26432644
self.out_features = out_features
2645+
self.pg_collection = pg_collection
26442646
weight = torch.empty(num_local_experts, out_features, in_features, dtype=dtype, device=device)
26452647
if init_method is not None:
26462648
for e in range(num_local_experts):
@@ -2670,7 +2672,11 @@ def sharded_state_dict(
26702672
key = f"{prefix}weight"
26712673
return {
26722674
key: _make_grouped_expert_sharded_tensor(
2673-
self.weight.data, key, tp_axis=None, sharded_offsets=sharded_offsets
2675+
self.weight.data,
2676+
key,
2677+
tp_axis=None,
2678+
sharded_offsets=sharded_offsets,
2679+
pg_collection=self.pg_collection,
26742680
)
26752681
}
26762682

@@ -2770,6 +2776,7 @@ def __init__(
27702776
init_method=row_init,
27712777
device=params_device,
27722778
dtype=params_dtype,
2779+
pg_collection=self.pg_collection,
27732780
)
27742781
else:
27752782
# Per-expert A (intermediate → rank); shared B (rank → hidden).
@@ -2780,6 +2787,7 @@ def __init__(
27802787
init_method=column_init,
27812788
device=params_device,
27822789
dtype=params_dtype,
2790+
pg_collection=self.pg_collection,
27832791
)
27842792
self.linear_out = RowParallelLinear(
27852793
dim,

0 commit comments

Comments
 (0)