Skip to content

[BUG] Native-spin DPA4C graph path fails on zero-node graphs #5991

Description

@njzjz-bot

Summary

The portable native-spin DPA4C graph path crashes when the graph has zero nodes. The spin-free path and the compressed native-spin CPU path handle this empty-node case.

This reproduces on origin/master at 8cfd46e37448.

Reproduction

import torch

from deepmd.dpmodel.utils.neighbor_graph import NeighborGraph
from deepmd.pt_expt.descriptor.dpa4c import DescrptDPA4C

d = DescrptDPA4C(
    rcut=3.0,
    ntypes=2,
    channels=8,
    lmax=2,
    n_radial=4,
    precision="float32",
    use_spin=[True, False],
).eval()

g = NeighborGraph(
    n_node=torch.zeros(1, dtype=torch.int64),
    n_local=torch.zeros(1, dtype=torch.int64),
    edge_index=torch.empty((2, 0), dtype=torch.int64),
    edge_vec=torch.empty((0, 3), dtype=torch.float32),
    edge_mask=torch.empty((0,), dtype=torch.bool),
)
d.call_graph(
    g,
    torch.empty((0,), dtype=torch.int64),
    spin=torch.empty((0, 3), dtype=torch.float32),
)

Actual result:

deepmd/dpmodel/descriptor/dpa4c_nn/spin.py:328
RuntimeError: cannot reshape tensor of 0 elements into shape [0, -1]

Cause and expected behavior

The spin/geometric cross Gram is reshaped to (0, -1), for which PyTorch cannot infer the second dimension. The width is already known and can be stated explicitly as self.quadrupole_width * self.degree_channels[2].

The call should return an empty descriptor with shape (0, descriptor.get_dim_out()). A regression test should cover call_graph() on the same empty native-spin graph already covered by the compressed CPU reference.


Coding agent: Codex
Codex version: codex-cli 0.149.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions