mstar.model.waypoint.components.layers#
Stateless layer primitives for the Waypoint-1.5 DiT.
Port of world_engine/src/model/nn.py plus the three conditioning modules
from world_engine/src/model/world_model.py. Parameter names track
checkpoint keys (fc1/fc2, bias_in, cond_proj, mlp), not
mstar’s usual components.mlp.MLP spelling, so this doesn’t reuse it.
Functions
|
Per-frame adaLN output gate: |
|
Per-frame adaLN modulation: |
|
Quantize an fp32 derived table the way |
Run fp32 GEMMs as IEEE fp32, whatever the process-wide |
|
|
Unweighted RMS norm over the last dim (reference |
Classes
|
adaLN with the scale/shift projection folded in: one Linear produces |
|
Per-layer WAN-style conditioning head: the noise embedding becomes the block's six adaLN modulation tensors (scale/shift/gate for attention, then the same three for the MLP). |
|
Controller state -> one conditioning vector per frame. |
|
Per-device replicas of small derived fp32 tables (RoPE frequencies, Fourier frequencies), held outside the module tree so they stay out of |
|
Two-layer SiLU MLP, both projections bias-free. |
|
Fuses a per-frame conditioning vector into that frame's tokens. |
|
sigma -> Fourier features -> MLP, the DiT's only noise-level input. |
- class mstar.model.waypoint.components.layers.AdaLN(dim)[source]#
Bases:
ModuleadaLN with the scale/shift projection folded in: one Linear produces
[scale | shift]fromsilu(cond).The DiT’s output head only; blocks get their six modulation tensors from
CondHead.condis per-frame[B, N, D], expanded over its tokens.- Parameters:
dim (int)
- forward(x, cond)[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.waypoint.components.layers.CondHead(config)[source]#
Bases:
ModulePer-layer WAN-style conditioning head: the noise embedding becomes the block’s six adaLN modulation tensors (scale/shift/gate for attention, then the same three for the MLP).
bias_inis genuinely per-layer; the sixcond_projLinears are physically shared across all 24 blocks viaWaypointDiT.retie_cond_proj(must run afterto_empty– see its docstring).- Parameters:
config (WaypointConfig)
- build_cache(conds)[source]#
Precompute the six modulation tensors for every scheduled sigma.
condsis[S, 1, D]– one embedding perscheduler_sigmasentry, each built at M=1 exactly asforwardreceives it, so a cached row is bit-identical to the live_projectit replaces. Switchesforwardto a gather; idempotent enough to rebuild.- Parameters:
conds (Tensor)
- Return type:
None
- forward(cond, cond_idx)[source]#
cond[B, N, D],cond_idxthescheduler_sigmasslot -> six[B, N, D]tensors(s0, b0, g0, s1, b1, g1).After
build_cachethe six come from the cache rowcond_idxandcondis unused
- n_cond = 6#
- class mstar.model.waypoint.components.layers.ControllerInputEmbedding(config)[source]#
Bases:
ModuleController state -> one conditioning vector per frame.
The concat order is
(mouse, button, scroll)– 2 + n_buttons + 1 = 259 here – and it is a checkpoint fact. A permuted order does not raise: the widths still sum to 259 and every downstream shape checks out, it just reads mouse velocity out of button columns. Callers pass the three positionally.- Parameters:
config (WaypointConfig)
- class mstar.model.waypoint.components.layers.DeviceTableCache(*tables)[source]#
Bases:
objectPer-device replicas of small derived fp32 tables (RoPE frequencies, Fourier frequencies), held outside the module tree so they stay out of
state_dict/to_empty’s reach and fp32 forever.Callers MUST build the CPU tables with an explicit
device="cpu":__init__runs underwith torch.device("meta"), where an ambient-devicetorch.arangeproduces a data-less meta tensor.- Parameters:
tables (Tensor)
- class mstar.model.waypoint.components.layers.MLP(dim_in, dim_middle, dim_out)[source]#
Bases:
ModuleTwo-layer SiLU MLP, both projections bias-free.
bias=Falseis a checkpoint fact: the reference’sMLPFusioncallsF.linear(h, self.mlp.fc2.weight)with no bias argument, which is only correct because there is no bias to pass.- 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.waypoint.components.layers.MLPFusion(config)[source]#
Bases:
ModuleFuses a per-frame conditioning vector into that frame’s tokens.
Parameter tree is
MLP(2*D, D, D)overcat([x, cond])– one[D, 2D]mlp.fc1for the loader to fill. Compute splits that matrix instead (chunk(2, dim=1)) socondbroadcasts over the T tokens of its frame, compute-time only – stored split parameters would undo the loader’s concat intomlp.fc1.- Parameters:
config (WaypointConfig)
- class mstar.model.waypoint.components.layers.NoiseConditioner(dim, fourier_dim=512, base=10_000.0, *, reference_compat=False, cached_sigmas=())[source]#
Bases:
Modulesigma -> Fourier features -> MLP, the DiT’s only noise-level input.
fp32 island:
FP32_MODULE_PATHSpinsself.mlpback to fp32 after the serving bf16 cast, and the body runs underautocast(enabled=False)on a.float()sigma and, eagerly, underfp32_matmul_highest(a batched call rounds through TF32 at'high', and cuBLAS 13 on a B200 rounds even the served[1, 512] @ [512, 8192]GEMV). Compiled regions read the rowsWaypointDiTbuilds eagerly instead of running the island.* 1000scales [0, 1] into the Fourier basis’s rotating range;* 2**0.5restores unit variance after the sin/cos concat.- Parameters:
- mstar.model.waypoint.components.layers.ada_gate(x, gate)[source]#
Per-frame adaLN output gate:
x * gate, same shapes asada_rmsnorm. No1 +here – the gate multiplies the sublayer output before the residual add, so a zero gate contributes nothing.
- mstar.model.waypoint.components.layers.ada_rmsnorm(x, scale, bias)[source]#
Per-frame adaLN modulation:
rms_norm(x) * (1 + scale) + bias.xis[B, N*T, D];scaleandbiasare[B, N, D], one modulation vector per frame. The unflatten is what makes those vectors broadcast over their own frame’s tokens.
- mstar.model.waypoint.components.layers.bf16_roundtrip(table)[source]#
Quantize an fp32 derived table the way
NoCastModule._applydoes. Only reachable underWaypointConfig.reference_compat.