mstar.model.vjepa2.components.ac_predictor#
V-JEPA 2 action-conditioned predictor (for V-JEPA 2-AC).
Port of VisionTransformerPredictorAC and supporting blocks from
vjepa2/src/models/ac_predictor.py + vjepa2/src/models/utils/modules.py.
The HuggingFace Transformers port does NOT include the AC variant, so this
file stays close to the upstream naming to preserve checkpoint-key parity
with the upstream vjepa2-ac-vitg weights.
Key differences from the masked predictor:
Fused
qkvLinear (dim -> dim*3) per layer (upstream layout).Action + state + (optional) extrinsics tokens are interleaved into the spatial sequence per timestep:
[a, s, x_0, ..., x_{H*W-1}](+eifuse_extrinsics). Action tokens rotate only along the depth axis.Causal attention across frames via
build_action_block_causal_attention_mask.Uses
F.scaled_dot_product_attention(SDPA) — the attention mask is always present, so the eager fallback is unreachable.
Functions
Build a |
Classes
|
|
|
|
|
Action-conditioned V-JEPA 2 predictor. |
- class mstar.model.vjepa2.components.ac_predictor.ACBlock(dim, num_heads, mlp_ratio, qkv_bias, layer_norm_eps, grid_size)[source]#
Bases:
Module- Parameters:
- forward(x, attn_mask, t, h, w, action_tokens, t_0=0, label=None, d_pos=None, h_pos=None, w_pos=None, time_pos=None)[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.vjepa2.components.ac_predictor.ACRoPEAttention(dim, num_heads, qkv_bias=True, grid_size=16)[source]#
Bases:
Module- forward(x, attn_mask, t, h, w, action_tokens, t_0=0, label=None, d_pos=None, h_pos=None, w_pos=None, time_pos=None)[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.
- forward_cached(x, d_pos, h_pos, w_pos, time_pos, action_tokens)[source]#
Single-frame cached attention with pre-computed position tensors.
All position tensors are expected to already be on the correct device. Callers must compute them via _compute_positions (or the model-level _compute_rope_positions) and may store them in static GPU buffers updated via .copy_() so the surrounding CUDA graph sees the new values.
Parity with the regular forward was partially validated in test/modular/vjepa2/test_ac_rope_parity.py and more thoroughly in test/modular/vjepa2/test_ac_kv_cache_parity.py.
- class mstar.model.vjepa2.components.ac_predictor.VisionTransformerPredictorAC(config)[source]#
Bases:
ModuleAction-conditioned V-JEPA 2 predictor.
Forward signature matches the upstream class so parity tests can pass outputs directly. Expects encoder context embeddings plus per-timestep action / state (and optional extrinsics) tensors.
- Parameters:
config (VJepa2ACPredictorConfig)
- property attn_mask: Tensor | None#
Back-compat accessor used by tests. Builds the mask on CPU if it hasn’t been built yet.
- forward(x, actions, states, extrinsics=None, t_0=0, label=None)[source]#
- Parameters:
- Returns:
Predicted embeddings,
[B, N_ctxt, embed_dim].- Return type:
- make_block_loop_fn(label, static_pos_bufs, cond_tokens)[source]#
Return a closure capturing the block loop for PiecewiseCudaGraphRunner.
The returned
fn(x) -> xreads position tensors fromstatic_pos_bufs(which the runner updates via.copy_()before each replay) and attends underlabel, whose plan the runner drives outside the graph before each replay.The stream advance is NOT done inside this closure — the runner commits the step after
graph.replay(), outside the captured region.