Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[BUG] Charge/spin-conditioned DPA4 breaks ragged multi-frame graph batches

未关闭
#5,992 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python, pytorch

调研方向

从 deepmd/pt_expt/descriptor/dpa4.py 开始,跟踪 call_graph()、_run_graph() 和 _apply_charge_spin_embedding();将它们的处理方式与 DPA4C 和 frame_id_from_n_node() 进行比较。使用 ragged reproduction 添加 descriptor 级和 model 级覆盖,并将 ragged batch 与单个 frame 的独立调用进行比较,以验证在 node 数量不相等时条件仍保持对齐。

由索引模型根据 Issue 内容生成。

描述

bug
Summary

Charge/spin-conditioned DPA4 assumes every frame in a flat graph batch has the same node count. It crashes for a genuinely ragged batch and can attach frame conditions to the wrong nodes for other unequal-count batches.

NeighborGraph defines a flat node axis with N = sum(n_node), and the public EnergyModel.forward_ragged() accepts arbitrary per-frame n_node together with (nf, 2) charge_spin. This reproduces on origin/master at 8cfd46e37448.

Reproduction
import torch

from deepmd.dpmodel.utils.neighbor_graph import NeighborGraph
from deepmd.pt_expt.descriptor.dpa4 import DescrptDPA4

d = DescrptDPA4(
    ntypes=1,
    sel=2,
    rcut=3.0,
    channels=4,
    n_radial=2,
    lmax=0,
    kmax=0,
    n_blocks=0,
    use_env_seed=False,
    random_gamma=False,
    add_chg_spin_ebd=True,
    precision="float64",
    seed=1,
).eval()

graph = NeighborGraph(
    n_node=torch.tensor([1, 2], dtype=torch.int64),
    edge_index=torch.zeros((2, 2), dtype=torch.int64),
    edge_vec=torch.zeros((2, 3), dtype=torch.float64),
    edge_mask=torch.zeros((2,), dtype=torch.bool),
)

d.call_graph(
    graph,
    torch.zeros((3,), dtype=torch.int64),
    charge_spin=torch.tensor([[0.0, 1.0], [1.0, 2.0]], dtype=torch.float64),
)

Actual result:

deepmd/dpmodel/descriptor/dpa4.py:1972
RuntimeError: shape '[3, 4]' is invalid for input of size 8
Cause

call_graph() reduces the graph to scalar nf; _run_graph() then passes nloc=n_out_nodes // nf; _apply_charge_spin_embedding() broadcasts every frame condition to that uniform width and reshapes it onto the flat node axis.

For n_node=[1, 2], this creates only two condition rows for three nodes. If the total happens to be divisible by nf, unequal frame counts can instead silently assign conditions to the wrong nodes.

Suggested fix

Gather the per-frame condition with frame_id_from_n_node(graph.n_node, n_total=atype.shape[0]), as DPA4C does, and compare a ragged batch against independent single-frame calls in descriptor- and model-level tests.

Related to the currently unreachable production ragged builders tracked in #5938, but this is a separate consumer correctness failure in the public ragged API.


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

主要语言
Python
星标
2k
派生
651
平均合并
4 天 21 小时
30 天内合并 PR
14

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

deepmodeling/deepmd-kit 的其他 Issue

查看 deepmodeling/deepmd-kit 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。