lgatr.nets.lgatr.LGATr
- class lgatr.nets.lgatr.LGATr(num_blocks, in_mv_channels, out_mv_channels, hidden_mv_channels, in_s_channels, out_s_channels, hidden_s_channels, attention, mlp, primitives=None, reinsert_mv_channels=None, reinsert_s_channels=None, dropout_prob=None, norm_elementwise_affine=True, checkpoint_blocks=False, naive_amp=False)[source]
Bases:
ModuleL-GATr network.
Combines
num_blocksLGATrBlockmodules (geometric self-attention, geometric MLP, residual connections, normalization) with initial and final equivariant linear layers.Inputs have shape
(..., items, in_mv_channels, 16); outputs have shape(..., items, out_mv_channels, 16); hidden representations have shape(..., items, hidden_mv_channels, 16)(and similar for the optional scalar stream).- Parameters:
num_blocks (
int) – Number of transformer blocks.in_mv_channels (
int) – Number of input multivector channels.out_mv_channels (
int) – Number of output multivector channels.hidden_mv_channels (
int) – Number of hidden multivector channels.in_s_channels (
int) – Number of scalar input channels. Use 0 for no scalar inputs.out_s_channels (
int) – Number of scalar output channels. Use 0 for no scalar outputs.hidden_s_channels (
int) – Number of scalar hidden channels.attention (
SelfAttentionConfig|Mapping) – Self-attention configuration (seeSelfAttentionConfig).mlp (
MLPConfig|Mapping) – MLP configuration (seeMLPConfig).primitives (
PrimitivesConfig|Mapping|None) – LGATr primitives configuration. Accepts aPrimitivesConfiginstance, a dict, orNone(uses defaults).reinsert_mv_channels (
tuple[int,...] |None) – If not None, specifies multivector channels that will be reinserted in every attention layer.reinsert_s_channels (
tuple[int,...] |None) – If not None, specifies scalar channels that will be reinserted in every attention layer.dropout_prob (
float|None) – Dropout probability.norm_elementwise_affine (
bool) – Whether the blockEquiLayerNorminstances learn an affine gain.checkpoint_blocks (
bool) – Whether to use gradient checkpointing for the blocks. Saves memory at the cost of speed.naive_amp (
bool) – Whether to bypass the fp32 precision islands so the whole forward runs in the surrounding autocast dtype (e.g. bf16). WhenFalse(default), under autocast the multivector stream and metric contractions stay fp32 while the scalar GEMMs run in bf16.
- forward(multivectors, scalars=None, **attn_kwargs)[source]
Forward pass.
- Parameters:
multivectors (
Tensor) – Input multivectors of shape(..., items, in_mv_channels, 16).scalars (
Tensor|None) – Optional input scalars of shape(..., items, in_s_channels).**attn_kwargs – Optional keyword arguments forwarded to attention.
- Return type:
tuple[Tensor,Tensor|None]- Returns:
outputs_mv – Output multivectors of shape
(..., items, out_mv_channels, 16).outputs_s – Output scalars of shape
(..., items, out_s_channels), or None ifout_s_channels == 0.