opentau.policies.layers
Reusable parametric layers shared across VLA policies.
PerGroupLinear is a drop-in replacement for nn.Linear that keeps an
independent (weight, bias) per group and selects one row per sample with a
(B,) long index — the same per-sample group axis the stacked
Normalize/Unnormalize stat buffers use (see opentau.policies.normalize).
Its state_dict key names match nn.Linear exactly (<name>.weight /
<name>.bias) but carry a leading group axis, so the legacy single-group
promotion shim (unsqueeze(0)-style, see
PreTrainedPolicy._promote_legacy_norm_buffers_in_state_dict) applies to it.
Classes
|
|
- class opentau.policies.layers.PerGroupLinear(in_features: int, out_features: int, num_groups: int, bias: bool = True)[source]
Bases:
Modulenn.Linearwith one independent(weight, bias)per group.- Parameters:
in_features – Size of each input sample.
out_features – Size of each output sample.
num_groups – Number of independent linear maps.
1makes this numerically identical to a plainnn.Linear— the forward takes anF.linearfast path with the un-cast parameters, so its dtype / autocast behavior matches a plainnn.Linearbit-for-bit.bias – If
True(default), adds a per-group learnable bias.
- Shape:
weight:
(num_groups, out_features, in_features)bias:
(num_groups, out_features)
These are an
nn.Linearparameter with a leading group axis, which is why the state_dict keys stay identical tonn.Linear(just one rank higher). A legacynn.Linearcheckpoint promotes into anum_groups=1PerGroupLinearby prepending that axis.- Forward:
forward(x, group_index=None)wherexis(B, *, in_features)andgroup_indexis a(B,)long tensor in[0, num_groups).group_index=Noneroutes every sample to group0(the single-group default; used by direct-call unit tests and any caller that has not threaded an index).
- __init__(in_features: int, out_features: int, num_groups: int, bias: bool = True)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- extra_repr() str[source]
Return the extra representation of the module.
To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.
- forward(x: Tensor, group_index: Tensor | None = None) 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.