opentau.policies.pi05_mem.motion_module
Space-Time Self-Similarity (STSS) motion module.
Ported from RLDX-1 (rldx/model/modules/backbone/motion.py,
https://github.com/RLWRLD/RLDX-1), whose motion module in turn builds on the
SELFY space-time self-similarity formulation (Kwon et al., “Learning
Self-Similarity in Space and Time as Generalized Motion for Video Action
Recognition”, ICCV 2021).
Rather than optical flow or raw frame differences, the module captures temporal
dynamics by computing local space-time self-similarity: for every
spatio-temporal patch feature it correlates against its neighbors within a
(L, kh, kw) window across frames, producing a similarity volume that a small
3D-conv encoder turns into a motion feature. The result is a residual that
is added back onto the vision features:
v~(t) = v(t) + S_theta(STSS(v(t)))
In OpenTau this residual is injected at a single SigLIP encoder layer (see
SpaceTimeSiglipVideoEncoder in video_encoder.py).
Interface (matching the RLDX-1 reference so the math is easy to compare):
- forward(x, grid_sizes)
- x: (sum_i T_i*H_i*W_i, C) flattened patch features, token order
(b t h w)(batch-major, then time, then row-major patches).grid_sizes: (B, 3) int tensor; each row is
[T, H, W]for one video. returns: (sum_i T_i*H_i*W_i, C) residual, same layout asx.
- Differences from the RLDX-1 reference, all behind flags:
norm(default “groupnorm”): GroupNorm(1, C) — per-sample, no cross-rank stat sync, safe under FSDP/DeepSpeed/multi-rank (CLAUDE.md rule #5). Pass “batchnorm” for the RLDX-1-faithful BatchNorm3d, or “syncbn”.zero_init_residual(default True): zero-initializes the output projection (or the LayerScale) so the module starts as an exact no-op. A policy fine-tuned from a pre-existing pi05 checkpoint is therefore byte-identical at step 0 and the motion contribution warms up during training. RLDX-1 dropped this zero-init so motion contributes from step 1 — passzero_init_residual=Falseto match that.The gradient-monitoring print hook from the reference is omitted.
Classes
|
STSS motion module producing a residual update to vision features. |
|
One STSS block: LN -> in_proj -> transform -> extract -> integrate -> out_proj. |
|
Project the |
|
Fuse the |
|
Compute the local space-time self-similarity volume. |
- class opentau.policies.pi05_mem.motion_module.MotionModule(d_in: int, d_hid: int, d_out: int, window: tuple[int, int, int] = (5, 9, 9), ext_chnls: tuple[int, ...] = (256,), int_chnls: tuple[int, int, int] = (256, 256, 512), corr_func: str = 'cosine', n_encoders: int = 1, use_layerscale: bool = False, layerscale_init: float = 1e-05, norm: str = 'groupnorm', int_mode: str = 'lite', zero_init_residual: bool = True)[source]
Bases:
ModuleSTSS motion module producing a residual update to vision features.
- Parameters:
d_in – Input feature dimension (must equal the residual target dim).
d_hid – Internal correlation/feature dimension (
in_projtarget).d_out – Output dimension; set equal to
d_inso the residual adds back.window –
(L, kh, kw)space-time correlation window.int_chnls (ext_chnls /) – channel widths for the extraction / integration convs.
corr_func – “cosine” (default), “dotproduct”, or “dotproduct_softmax”.
n_encoders – number of stacked STSS encoders (their outputs are summed).
use_layerscale – gate the output with a learnable per-channel LayerScale instead of an
out_projlinear.layerscale_init – initial LayerScale value (used only with
use_layerscale).norm – “groupnorm” (default, distributed-safe) / “batchnorm” (RLDX-faithful) / “syncbn”.
int_mode – “lite” (single fuse conv) or the full 3x3 conv stack.
zero_init_residual – when True, zero-initialize the residual output so the module starts as an exact no-op (warm start from a pretrained checkpoint); the contribution ramps up during training.
- __init__(d_in: int, d_hid: int, d_out: int, window: tuple[int, int, int] = (5, 9, 9), ext_chnls: tuple[int, ...] = (256,), int_chnls: tuple[int, int, int] = (256, 256, 512), corr_func: str = 'cosine', n_encoders: int = 1, use_layerscale: bool = False, layerscale_init: float = 1e-05, norm: str = 'groupnorm', int_mode: str = 'lite', zero_init_residual: bool = True)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- class opentau.policies.pi05_mem.motion_module.STSSEncoder(d_in: int, d_hid: int, d_out: int, window: tuple[int, int, int] = (5, 9, 9), ext_chnls: tuple[int, ...] = (256,), int_chnls: tuple[int, int, int] = (256, 256, 512), corr_func: str = 'cosine', norm: str = 'groupnorm', int_mode: str = 'lite')[source]
Bases:
ModuleOne STSS block: LN -> in_proj -> transform -> extract -> integrate -> out_proj.
- __init__(d_in: int, d_hid: int, d_out: int, window: tuple[int, int, int] = (5, 9, 9), ext_chnls: tuple[int, ...] = (256,), int_chnls: tuple[int, int, int] = (256, 256, 512), corr_func: str = 'cosine', norm: str = 'groupnorm', int_mode: str = 'lite')[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: Tensor, grid_sizes: Tensor) Tensor[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 opentau.policies.pi05_mem.motion_module.STSSExtraction(window: tuple[int, int, int] = (5, 9, 9), chnls: tuple[int, ...] = (256,), norm: str = 'groupnorm')[source]
Bases:
ModuleProject the
kh*kwsimilarity channels of the STSS volume to features.- __init__(window: tuple[int, int, int] = (5, 9, 9), chnls: tuple[int, ...] = (256,), norm: str = 'groupnorm')[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: Tensor) Tensor[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 opentau.policies.pi05_mem.motion_module.STSSIntegration(d_in: int, window: tuple[int, int, int] = (5, 9, 9), chnls: tuple[int, int, int] = (64, 64, 64), norm: str = 'groupnorm', mode: str = 'lite')[source]
Bases:
ModuleFuse the
Ltemporal-window slices into a single motion feature map.- __init__(d_in: int, window: tuple[int, int, int] = (5, 9, 9), chnls: tuple[int, int, int] = (64, 64, 64), norm: str = 'groupnorm', mode: str = 'lite')[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: Tensor) Tensor[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 opentau.policies.pi05_mem.motion_module.STSSTransformation(window: tuple[int, int, int] = (5, 9, 9), corr_func: str = 'cosine')[source]
Bases:
ModuleCompute the local space-time self-similarity volume.
For each spatio-temporal patch feature, correlate it against the features of nearby frames within a
window[0]temporal span, then keep only a localwindow[1] x window[2]spatial neighborhood of the correlation.- __init__(window: tuple[int, int, int] = (5, 9, 9), corr_func: str = 'cosine')[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: Tensor, grid_sizes: Tensor) Tensor[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.