mstar.model.waypoint.components#
Waypoint-1.5-1B component modules.
The DiT is a native port of world_engine/src/model/world_model.py.
apply_inference_patches runs unconditionally in the reference, so the
patched model is the shipped one – but the port does not follow it
uniformly: it takes the patched fused QKV and keeps the unpatched
packed MLPFusion.fc1, since that patch splits a weight the checkpoint
stores packed. The two forms are algebraically identical.
Nothing here owns the world state. The ring KV cache and the FlexAttention
kernel are engine resources (engine/resources/kv/ring/,
engine/resources/attn/flex.py) bound onto WaypointDiT and its 24
WaypointAttention layers at load by NodeSubmodule.bind_node_resources.
That keeps the rings out of the module tree, where to_empty(device),
state_dict() and the weight loader would each have a buffer of ours to
leave holding garbage.
taehv.py is the exception: a streaming AE session is per-request Python
state, held in PerRequestState by the two VAE nodes and dropped with the
request. Its taehv imports are deferred, so this package imports without
the upstream package installed.
- class mstar.model.waypoint.components.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.ChunkedStreamingTAEHV(ae_model, auto_aspect_ratio=True, device=None, dtype=torch.bfloat16, height=None, width=None)[source]#
Bases:
objectOne streaming session: this request’s frames, in order.
The order-dependent state lives here;
ae_modelis shared and never mutated, so a fresh instance is the reference’sreset(). Not annn.Module: the module tree would givestate_dict(),to()and the weight loader a second path to the same parameters.- Parameters:
- decode(latent)[source]#
One latent
[B, C, h, w]->[t_upscale, H, W, 3]uint8.Single-use and order-dependent: the temporal memory advances per call, so a latent decoded twice, out of turn or not at all shifts every frame after it, silently. The first call primes that memory with
frames_to_trimextra feeds, which is why the prime walk decodes.
- class mstar.model.waypoint.components.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.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.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.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.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.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:
- class mstar.model.waypoint.components.OrthoRoPE(config=None)[source]#
Bases:
ModuleStateless module wrapper around
apply_ortho_rope(), constructed per attention layer to match the reference’s call site.configis stored for that parity and otherwise unused.- Parameters:
config (WaypointConfig | None)
- forward(x, rope_angles)[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.OrthoRoPEAngles(config)[source]#
Bases:
ModuleBuilds the shared
(cos, sin)angle tables for one forward, once under the DiT rather than once per block.- Parameters:
config (WaypointConfig)
- class mstar.model.waypoint.components.WaypointAttention(config, layer_idx)[source]#
Bases:
ModuleOne layer of causal frame attention over the ring KV cache.
xis[B, N*T, D](N frames of T tokens, flattened; N is 1 for every served call) and the head layout inside is[B, H, N*T, d_head], 32 query heads over 16 KV heads.- Parameters:
config (WaypointConfig)
layer_idx (int)
- bind_resources(resources)[source]#
Resolve the two resources this layer calls.
NodeSubmodule.bind_node_resourceswalksself.modules(), so one bind on the submodule reaches all 24 layers..get: a layer may be bound on a node that owns only some of them.- Parameters:
resources (dict)
- Return type:
None
- forward(x, frame_pos, rope_angles, v1, *, commit)[source]#
x[B, N*T, D]->(out [B, N*T, D], v1 [B, H_kv, N*T, d_head]).frame_posis the[B]int64 ring clock;v1isNoneat layer 0 and layer 0’s pre-lerp V thereafter. Both stay arguments rather than cursors the KV resource keeps: a cursor that drifts from the caller does not raise, it rewrites history.
- class mstar.model.waypoint.components.WaypointDiT(config)[source]#
Bases:
ModuleConv2d patchify -> 24 blocks -> adaLN head -> unpatchify, plus the 4+1 per-frame driver.
Built on the meta device and materialized by
weight_loaderin a fixed order:with torch.device("meta"): dit = WaypointDiT(config) dit.cast_serving_dtypes() # bf16 + fp32 islands, on meta dit.to_empty(device=device) # un-ties cond_proj dit.retie_cond_proj() # MUST follow to_empty load_weights_into(dit, ...)
The KV ring is derived state owned by an engine resource, bound after materialization – not part of this module.
- Parameters:
config (WaypointConfig)
- append_frame(latent, frame_pos, *, mouse, button, scroll)[source]#
Prime the world state from a real (VAE-encoded) frame: the committing pass alone, one forward.
latentis already the settled x0, so there is nothing to solve and nothing to clone. Returned unchanged for the caller to decode.
- cast_serving_dtypes()[source]#
bf16 everywhere, then the fp32 islands back to fp32.
Called on the meta module before
to_empty(device)so storage is allocated directly in the serving dtype..to(dtype)on meta preserves thecond_projaliasing (to_emptydoes not), so no retie is needed here.- Return type:
- compile_regions(**compile_kwargs)[source]#
Compile the denoise and cache passes, one region each. Idempotent.
materialize_runtime_tablesmust run first: the derived token grid, RoPE tables and conditioner LUT live outside the module tree, and a first touch inside afullgraph=Trueregion is at best a specialization and at worst a graph break.- Return type:
- forward(x, sigma, frame_pos, *, mouse, button, scroll, commit, cond_idx)[source]#
One pass over one latent frame; returns the rectified-flow velocity.
x[B, N, C, H, W](N == 1),sigma[B, N],frame_pos[B]int64 ring clock. Returns[B, N, C, H, W].commitsays whether this pass keeps its K/V (False for the four denoise passes, True for the fifth);cond_idxselects the cached modulation row and must matchsigma.
- generate_frame(noise, frame_pos, *, mouse, button, scroll)[source]#
Denoise one frame from
noise[B, N, C, H, W]and commit it.Five forwards: 4 frozen + 1 committing, all sharing one
frame_pos. The caller owns the ring clock and advances it once per committed frame.
- materialize_runtime_tables(device)[source]#
Create every derived table after weight loading and before compile.
- Parameters:
- Return type:
- retie_cond_proj()[source]#
Alias blocks 1..23’s six
cond_projmatrices onto block 0’s.Public, and separate from
__init__, becauseto_empty(device)destroys the tying (Module._applyhas no cross-module memo, so each block would get 24 independent copies).bias_inis deliberately NOT tied – it is genuinely per-layer.- Return type:
- class mstar.model.waypoint.components.WaypointDiTBlock(config, layer_idx)[source]#
Bases:
ModuleOne DiT block: adaLN-modulated causal frame attention, optional controller fusion, adaLN-modulated MLP.
The six modulation tensors come from this block’s
cond_head, whosebias_inis per-layer and whosecond_projmatrices alias block 0’s.- Parameters:
config (WaypointConfig)
layer_idx (int)
- forward(x, frame_pos, rope_angles, cond, ctrl_emb, v1, *, commit, cond_idx)[source]#
x[B, N*T, D],cond/ctrl_emb[B, N, D](per frame) ->(x, v1).v1is layer 0’s pre-lerp V, threaded down the stack;cond_idxis thescheduler_sigmasslot for the cond_head cache. Onlyf_posreaches this far – RoPE angles are built once at the root.
- class mstar.model.waypoint.components.WaypointPosIds(f_pos, t_pos, y_pos, x_pos)[source]#
Bases:
NamedTupleThe four position streams for one frame, per row of the step batch.
f_posis the[B]int64 ring clock (the KV resource’supserttakes it);t_posis the[B, T]RoPE time coordinatef_pos * ts_mult;y_pos/x_posare[B, T]token-grid coordinates,row = i // widthandcol = i % width.
- mstar.model.waypoint.components.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.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.apply_ortho_rope(x, rope_angles)[source]#
Rotate
x[B, H, T, d_head]by the(cos, sin)tables.The output is a permutation of the interleaved layout (
unfoldin,catout); it cancels insideq @ k.T, and is kept so that stored K/Q compare bit-for-bit with the reference. fp32 island:xis upcast for the rotation and cast back after.
- mstar.model.waypoint.components.load_taehv(ae_uri, cache_dir=None)[source]#
Load the shared weights module from a resolved local checkpoint.
Hub resolution belongs to
checkpoint.resolve_taehv_checkpoint, so only the required file is downloaded.cache_diris accepted for compatibility with existing callers but is unused here.
- mstar.model.waypoint.components.rms_norm(x)[source]#
Unweighted RMS norm over the last dim (reference
nn.rms_norm).No learned gain: every use site either gets its scale from adaLN or wants a bare normalization (Q/K norm, the two
MLPFusioninputs).
Modules
Waypoint self-attention: fused QKV, value residual, OrthoRoPE, ring cache. |
|
The Waypoint-1.5 DiT: 24 blocks, the 4+1 pass driver, and the world clock. |
|
Stateless layer primitives for the Waypoint-1.5 DiT. |
|
OrthoRoPE: Waypoint's orthogonal (x, y, t) rotary position embedding. |
|