deepmd.dpmodel.utils.neighbor_graph.pairs#
Pairs of edges sharing a center (dst) — the edge-pair axis.
Graph-native attention uses (ordered=True, include_self=True) = the full transformer neighbor-pair square per center; 3-body angles use (ordered=False,
include_self=False).
Two forms:
compact (
static_nnei=None): segment-based enumeration over the real edges only — sort edge ids by center, expand each center’s Cartesian square via cumsum offsets. DynamicP = sum(deg**2); memoryO(P)(same order as dense attention’sO(nloc * nnei**2)). The data-dependent sizes (nonzerooutput, tensor-repeatoutput) are registered as UNBACKED SymInt sizes viaxp_hint_dynamic_size(), so the form traces throughmake_fx/torch.exportand compiles under AOTI (torch >= 2.6 unbacked-symint support) — this is what makes the carry-all attention graph lower exportable to a.pt2. NumPy and JAX run it eagerly;jax.jitrequires the shape-static form.shape-static (
static_nneiset): assumes the center-major static layout (E = n_center * static_nnei, edgec * static_nnei + mbelongs to centerc— the layoutfrom_dense_quartet(compact=False)emits). Pure arange/reshape arithmetic,P = n_center * static_nnei**2with all pairs materialized and validity carried bypair_mask— no data-dependent ops at all, so it traces with only BACKED symbolic shapes (bit-parity with the dense layout; used by the dense-quartet adapter).
A global (E, E) same-center boolean is deliberately NOT used: with E ~ N * nnei it costs O(N**2 * nnei**2) memory.
Functions#
| Enumerate pairs of edges sharing a center. |
| |
|
Module Contents#
- deepmd.dpmodel.utils.neighbor_graph.pairs.center_edge_pairs(dst: deepmd.dpmodel.array_api.Array, edge_mask: deepmd.dpmodel.array_api.Array, n_total: int, *, include_self: bool = True, ordered: bool = True, static_nnei: int | None = None) tuple[deepmd.dpmodel.array_api.Array, deepmd.dpmodel.array_api.Array, deepmd.dpmodel.array_api.Array][source]#
Enumerate pairs of edges sharing a center.
- Parameters:
- dst
Array (E,) int64 center of each edge (
edge_index[1]).- edge_mask
Array (E,) bool, real (True) vs padding (False) edges.
- n_total
int Number of centers (bounds
dst).- include_selfbool
Keep the
m == ndiagonal (transformer self-attention needs it).- orderedbool
Keep both
(m, n)and(n, m)(attention: yes,q_m . k_nis not symmetric).Falsekeeps onlyn >= m(withinclude_self=False:n > m— the angle set).- static_nnei
int|None None-> compact eager form. Set -> shape-static form assuming the center-major layoutE = n_center * static_nnei.
- dst
- Returns:
- query_edge
Array (P,) int64 edge index of the query (
m).- key_edge
Array (P,) int64 edge index of the key (
n).- pair_mask
Array (P,) bool; False where either edge is padding or the pair is filtered by the
include_self/orderedpolicy (shape-static form; the compact form drops such pairs and returns all-True).
- query_edge
- deepmd.dpmodel.utils.neighbor_graph.pairs._pairs_shape_static(xp: Any, dev: Any, dst: deepmd.dpmodel.array_api.Array, edge_mask: deepmd.dpmodel.array_api.Array, nn: int, include_self: bool, ordered: bool) tuple[deepmd.dpmodel.array_api.Array, deepmd.dpmodel.array_api.Array, deepmd.dpmodel.array_api.Array][source]#
- deepmd.dpmodel.utils.neighbor_graph.pairs._pairs_compact(xp: Any, dev: Any, dst: deepmd.dpmodel.array_api.Array, edge_mask: deepmd.dpmodel.array_api.Array, n_total: int, include_self: bool, ordered: bool) tuple[deepmd.dpmodel.array_api.Array, deepmd.dpmodel.array_api.Array, deepmd.dpmodel.array_api.Array][source]#