deepmd.pt.model.descriptor.sezm_nn.embedding#
Embedding layers for the SeZM descriptor.
This module defines the type embedding, geometric initial embedding, and environment-seed embedding used to initialize SeZM node features.
Classes#
Minimal SeZM type embedding with Adam-routed parameter naming. | |
Geometric initial embedding that adds zonal (m=0) rotated features. | |
Environment matrix initial embedding for l=0 features. | |
Frame-level charge and spin embedding for scalar type features. |
Module Contents#
- class deepmd.pt.model.descriptor.sezm_nn.embedding.SeZMTypeEmbedding(*, ntypes: int, embed_dim: int, dtype: torch.dtype, seed: int | list[int] | None = None, trainable: bool, padding: bool = True)[source]#
Bases:
torch.nn.ModuleMinimal SeZM type embedding with Adam-routed parameter naming.
- Parameters:
- ntypes
Number of atom types.
- embed_dim
Embedding dimension.
- dtype
Parameter dtype.
- seed
Random seed for initialization.
- trainable
Whether parameters are trainable.
- padding
Whether to append one all-zero padding row.
Notes
The parameter is named with
adam_prefix so HybridMuon routes it to Adam.- forward(atype: torch.Tensor) torch.Tensor[source]#
Gather type embeddings.
- Parameters:
- atype
Atom types with shape (…,). Valid type range is [0, ntypes-1].
- Returns:
torch.TensorType embeddings with shape (…, embed_dim).
- class deepmd.pt.model.descriptor.sezm_nn.embedding.GeometricInitialEmbedding(*, lmax: int, channels: int, dtype: torch.dtype)[source]#
Bases:
torch.nn.ModuleGeometric initial embedding that adds zonal (m=0) rotated features.
This module rotates pre-computed radial features for each degree l >= 1 using the zonal (m=0) column of the cached inverse Wigner-D blocks (local->global). The l=0 component is not computed here since it comes from type embedding.
- Parameters:
- lmax
Maximum degree, should match
l_schedule[0].- channels
Number of channels per (l, m) coefficient.
- dtype
Parameter dtype.
- forward(*, n_nodes: int, edge_cache: deepmd.pt.model.descriptor.sezm_nn.edge_cache.EdgeFeatureCache, radial_feat: torch.Tensor) torch.Tensor[source]#
- Parameters:
- n_nodes
Number of nodes (nf*nloc).
- edge_cache
Per-edge cache containing geometry, weights, and Wigner-D blocks.
- radial_feat
Per-edge radial features with shape (E, lmax, C) for l=1..lmax.
- Returns:
torch.TensorInitial features to add with shape (N, D, C). l=0 is guaranteed zero.
- class deepmd.pt.model.descriptor.sezm_nn.embedding.EnvironmentInitialEmbedding(*, ntypes: int, n_radial: int, channels: int, embed_dim: int = 64, axis_dim: int = 8, type_dim: int = 16, hidden_dim: int = 64, mlp_bias: bool = False, activation_function: str = 'silu', eps: float = 1e-07, dtype: torch.dtype, trainable: bool, seed: int | list[int] | None = None)[source]#
Bases:
torch.nn.ModuleEnvironment matrix initial embedding for l=0 features.
Computes an initial embedding based on the 4D environment matrix:
[s, s * rx, s * ry, s * rz]
Combined with independent type embeddings (individual type embedding), providing physical inductive bias for l=0 features.
The computation follows the environment matrix approach where:
1. Build `r_tilde = [s, s*r_hat]` where `s = edge_env / r` and `r_hat = edge_vec / r` 2. G network: `g = G(rbf_proj(edge_rbf), type_src, type_dst)` produces per-edge features - Uses independent `env_type_embed` instead of projecting from main type embedding - Uses `rbf_proj` to project edge_rbf to `rbf_out_dim` 3. env_agg: aggregate outer product `r_tilde ⊗ g` by destination node 4. D matrix: `D = env_agg^T @ env_agg[:, :, :axis_dim]` 5. Output: projection of flattened D matrix into FiLM logits
- Parameters:
- ntypes
int Number of atom types.
- n_radial
int Number of radial basis functions.
- channels
int Output channel dimension per FiLM branch (final output is 2*channels).
- embed_dim
int G network output dimension (filter width).
- axis_dim
int D matrix axis dimension (must be < embed_dim).
- type_dim
int Dimension for independent type embeddings in env_seed.
- hidden_dim
int Hidden layer size for G network.
- mlp_biasbool
Whether to enable bias terms in env-seed MLP layers (rbf_proj_layer1/2 and g_layer1/2).
- activation_function
str Activation function for G network hidden layer.
- eps
float Small epsilon for numerical stability.
- dtype
torch.dtype Parameter dtype.
- trainablebool
Whether parameters are trainable.
- seed
int|list[int] |None Random seed for reproducibility.
- ntypes
- forward(*, edge_cache: deepmd.pt.model.descriptor.sezm_nn.edge_cache.EdgeFeatureCache, atype_flat: torch.Tensor, n_nodes: int) torch.Tensor[source]#
Compute environment FiLM logits for l=0 conditioning.
- Parameters:
- edge_cache
EdgeFeatureCache Edge cache containing src, dst, edge_vec, edge_rbf, edge_env.
- atype_flat
torch.Tensor Flattened atom types with shape (N,), where N = nf * nloc.
- n_nodes
int Number of nodes (N = nf * nloc).
- edge_cache
- Returns:
torch.TensorFiLM logits with shape (N, 2*channels).
- class deepmd.pt.model.descriptor.sezm_nn.embedding.ChargeSpinEmbedding(*, embed_dim: int, activation_function: str, dtype: torch.dtype, seed: int | list[int] | None = None, trainable: bool)[source]#
Bases:
torch.nn.ModuleFrame-level charge and spin embedding for scalar type features.
- Parameters:
- embed_dim
Embedding dimension.
- activation_function
Activation function used by the mixing layer.
- dtype
Parameter dtype.
- seed
Random seed for initialization.
- trainable
Whether parameters are trainable.
- forward(charge_spin: torch.Tensor) torch.Tensor[source]#
Embed frame-level charge and spin.
- Parameters:
- charge_spin
Frame charge and spin values with shape (nf, 2).
- Returns:
torch.TensorMixed condition embedding with shape (nf, embed_dim).