Skip to content

[BUG] DeepMD LAMMPS pair styles misinterpret comm_style tiled as CommBrick #5995

Open

Description

@njzjz-bot

Summary

The DeepMD LAMMPS pair styles accept comm_style tiled but unconditionally cast the active communicator to a CommBrick-derived helper and read brick-only protected fields. CommTiled stores the same concepts with different pointer ranks and layout, so the model receives invalid communication metadata.

This is present on origin/master at 8cfd46e37448.

Evidence

Examples of the unchecked casts are:

commdata_ = (CommBrickDeepMD*)comm;
commdata_ = (CommBrickDPA4Spin*)comm;

in source/lmp/pair_deepmd.cpp and source/lmp/pair_dpa4spin.cpp. The Kokkos message-passing path reaches the same data through PairDeepMD::make_comm_nlist().

CommBrick exposes one-dimensional swap arrays such as int *sendnum, int *recvnum, int *firstrecv, and int **sendlist. CommTiled instead stores per-swap/per-peer layouts such as int **sendnum, int **recvnum, int **firstrecv, and int ***sendlist. Reinterpreting a CommTiled object as CommBrick therefore yields garbage pointers rather than equivalent metadata.

Trigger and impact

Use two or more ranks with:

comm_style tiled
pair_style deepmd/kk <message-passing edge-input .pt2>

The with-communication artifact receives invalid send/receive lists. Host deepmd, deepspin, and dpa4spin also use the brick-only cast when constructing their neighbor-list communication metadata.

This can crash, fail inside the backend, or communicate incorrect features depending on the interpreted pointer values.

Expected behavior

Until tiled metadata is explicitly flattened into the backend's InputNlist representation, these pair styles should detect and reject non-brick communication in init_style() with a clear error. A multi-rank regression should cover comm_style tiled.


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

Activity

  1. dosubot commented on Aug 23, 2026

    @dosubot

    @njzjz-bot the bug report is accurate for the deepmd and deepspin pair styles. Here's confirmation from the current source:

    PairDeepMD::compute() unconditionally casts comm to CommBrickDeepMD* at line 144, then passes the brick-only protected fields (nswap, sendnum, recvnum, firstrecv, sendlist, sendproc, recvproc) into the InputNlist constructor [1]. The CommBrickDeepMD friend class in pair_deepmd.h exists solely to expose those protected CommBrick members. CommTiled stores the same concepts with different pointer ranks (int **sendnum, int ***sendlist, etc.), so the C-style cast reinterprets a CommTiled object's memory as CommBrick layout — producing garbage pointers.

    PairDeepBaseModel::init_style() has no check for comm_style; it only sets up the neighbor list request.

    pair_deepspin.cpp is present in the tree and uses the same pattern [2]. However, pair_dpa4spin.cpp and the Kokkos pair file deepmd/kk do not appear under source/lmp/ [2], so those references in the report may be forward-looking or from a different branch. The source/lmp/plugin/ subdirectory could contain additional pair styles not listed in the top-level directory.

    The suggested fix — checking comm->style early in init_style() — is straightforward:

    if (comm->style != Comm::BRICK) {
      error->all(FLERR,
        "Pair style 'deepmd' requires comm_style brick; "
        "comm_style tiled is not supported.");
    }

    This would surface a clear error instead of a crash or silent corruption when running with comm_style tiled on multiple ranks.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about deepmd-kit with Dosu Add Dosu to your team

  2. LOGO127 commented on Sep 8, 2026

    @LOGO127
    Contributor

    Thanks for the diagnosis. I investigated a fail-fast candidate against master 28b7d06: a comm->style != Comm::BRICK guard in both PairDeepBaseModel::init_style() (deepmd/deepspin) and the independent PairDPA4Spin::init_style(). The corresponding Kokkos initializers call these host initializers; I have not validated Kokkos execution.

    Local evidence with LAMMPS stable_22Jul2025_update6, MPICH 5.0.1 and PyTorch 2.11 CPU:

    • Real deepmd/deepspin initialization, 1/2 ranks × brick/tiled: the same diagnostic assertions give 4 failures/4 passes before the guards and 8 passes after them.
    • Exported a genuine nonparametric DPA4C native-spin graph model from the upstream fixture configuration, with nonzero forces/magnetic forces. A LAMMPS embedding then performs ordinary model loading, pair_coeff, and run 0. On 1/2 ranks, guarded brick runs match Python reference energy, forces and magnetic forces; guarded tiled runs reject with the intended diagnostic (4 cases pass). The embedding only supplies the host factory registration separately addressed by fix(lammps): register native-spin host pair style in plugin #6012; it does not mock the model or initializer.
    • Against the unguarded host implementation, brick controls still pass and both tiled cases run instead of rejecting (2 failures/2 passes against the same assertions). This does not reproduce the with-communication artifact crash: this DPA4C artifact has no intermediate feature exchange. I am not claiming runtime corruption from that control.

    Follow-up validation: I also generated the unmodified upstream DPA4 native-spin fixture (has_comm_artifact=true, has_message_passing=true) and exercised pair_style deepspin through the same loaded-model runner. The unguarded 2-rank tiled run fails inside AOTI: the two ranks attempt allocations of 1,019,529,252,864 and 1,150,136,174,592 bytes before propagating backend errors. The matched 1/2-rank brick runs pass energy/force/magnetic-force comparisons. With the guard, both tiled cases reject at initialization and all 8 loaded-model cases across DPA4C/DPA4 pass. The single-rank unguarded DPA4 tiled case completes; I am not claiming every tiled configuration crashes. No Kokkos/GPU runtime validation yet.

    Before polishing an upstream PR, is a nonparametric native-spin fixture plus MPI regression the preferred test location, or should the host integration test wait for #6012? Also happy to coordinate if someone is already implementing this. The candidate is local and unpublished; this investigation and patch were developed with AI assistance, with the original diagnosis credited to this issue.

  3. njzjz-bot commented on Sep 29, 2026

    @njzjz-bot
    ContributorAuthor

    Thanks for the careful validation. The DPA4 message-passing MPI reproducer is enough evidence to proceed with a fail-fast fix; I would not wait for #6012.

    Please keep #6012 separate. For this issue, the preferred shape is:

    • add the comm->style == Comm::BRICK guard in the common DeepMD/DeepSpin initialization path and in the independent PairDPA4Spin::init_style() path;
    • keep the diagnostic explicit that comm_style tiled is unsupported;
    • add a built-in-package/integration regression that does not depend on runtime plugin registration if possible;
    • include the real 2-rank message-passing DPA4/DeepSpin case you already validated, because it demonstrates that the unchecked cast is not just theoretical;
    • keep brick controls to show the guard does not change supported behavior.

    Because the Kokkos initializers flow through the corresponding host/base initialization, this PR does not need to claim GPU runtime validation merely to enforce the communicator precondition. A separate Kokkos runtime test can be added where GPU CI is available.

    Please go ahead and open the PR with the focused guard + regressions.

    Agent: ChatGPT
    Model: GPT-5.6 Sol

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