mstar.model.components.mlp#
MLP and SwiGLU-style GatedMLP.
Used for transformer FFN blocks and for small projection MLPs (timestep embedders, Talker resize projections, etc.).
GatedMLP’s gate + up projections start as separate nn.Linear``s
that match the HF checkpoint layout. After load, calling
``consolidate_gate_up_weight() concatenates them into a single
gate_up_proj_weight buffer (one fused GEMM instead of two) and nulls
out the originals. The forward branches on whether consolidation has
happened.
Classes
|
SwiGLU-style gated MLP with the gate + up projections fused into a single |
|
SwiGLU-style gated MLP: |
|
Plain two-layer MLP: |
- class mstar.model.components.mlp.FusedGatedMLP(hidden_size, intermediate_size, activation='silu', bias=False)[source]#
Bases:
ModuleSwiGLU-style gated MLP with the gate + up projections fused into a single
FusedColumnLinear(one GEMM instead of two):down(act(gate) * up). UnlikeGatedMLP(separate Linears + post-loadconsolidate_gate_up_weight), this fuses from construction and loads the separategate_proj/up_projcheckpoint tensors straight into the fused parameter via the loader’s stacked-param rules (gate is shard0, up is shard1). Use for models that fuse but don’t need TP. :param hidden_size: input/output feature dim. :param intermediate_size: gate/up output and down input feature dim. :param activation: activation applied to the gate path. Either an HFstring (
silu/gelu/gelu_tanh) or a callable.- 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.
- class mstar.model.components.mlp.GatedMLP(hidden_size, intermediate_size, activation='silu', bias=False)[source]#
Bases:
ModuleSwiGLU-style gated MLP:
down(act(gate(x)) * up(x)).- Parameters:
- consolidate_gate_up_weight()[source]#
Fuse
gate_projandup_projweights into a singlegate_up_proj_weightbuffer and null out the originals. Idempotent; safe to call multiple times.- Return type:
None
- 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.mlp.MLP(input_size, intermediate_size, output_size=None, activation='silu', bias=True)[source]#
Bases:
ModulePlain two-layer MLP:
out(act(in(x))).Used for small projection MLPs that aren’t gated (Talker resize projection, bagel timestep embedder MLP, etc.). For SwiGLU-style transformer FFNs, use
GatedMLP.- 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.