mstar.model.components.distributed.mlp#
TP-aware SwiGLU MLPs (parallel counterparts of
mstar.model.components.GatedMLP).
ParallelGatedMLP fuses the gate/up projections into a single
MergedColumnParallelLinear (sharded along the intermediate dim) with a
RowParallelLinear down projection that all-reduces the partial sums.
The checkpoint stores gate_proj.weight and up_proj.weight
separately; the model’s weight loader calls
self.gate_up_proj.weight.weight_loader(loaded_weight,
loaded_shard_id=0) for gate and loaded_shard_id=1 for up.
ParallelGatedMLPUnfused keeps gate/up as separate
ColumnParallelLinear projections so state_dict() keys match a
checkpoint’s one-to-one — for loaders that stream weights by name with no
stacked-parameter rules.
Classes
|
SwiGLU-style gated MLP partitioned across TP ranks. |
|
SwiGLU MLP with separate (unfused) gate/up column shards. |
- class mstar.model.components.distributed.mlp.ParallelGatedMLP(hidden_size, intermediate_size, comm_group=None, activation='silu', bias=False)[source]#
Bases:
ModuleSwiGLU-style gated MLP partitioned across TP ranks.
- Parameters:
comm_group (CommGroup | None) – TP comm group for this MLP’s parallel linears.
hidden_size (int) – model hidden dim (full, not per-partition).
intermediate_size (int) – SwiGLU intermediate dim (full).
activation (str | Callable) – HF activation name (
silu,gelu,gelu_tanh).bias (bool) – whether the linears have a bias term.
- forward(x)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.components.distributed.mlp.ParallelGatedMLPUnfused(hidden_size, intermediate_size, comm_group=None, activation='silu', bias=False)[source]#
Bases:
ModuleSwiGLU MLP with separate (unfused) gate/up column shards.
Same math and sharding as
ParallelGatedMLP, withgate_projandup_projkept as separateColumnParallelLinearprojections so the parameter names match a checkpoint’sgate_proj.weight/up_proj.weightone-to-one (plain name-matched loading, no stacked-parameter loader rules). A trivial comm group (world size 1) makes the projections plain linears.- Parameters:
- forward(x)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.