Skip to content

fix(tf): honor NVNMD tensor neighbor lists#5845

Open
njzjz-bot wants to merge 1 commit into
deepmodeling:masterfrom
njzjz-bot:fix/nvnmd-tensor-neighbor-list-5652
Open

fix(tf): honor NVNMD tensor neighbor lists#5845
njzjz-bot wants to merge 1 commit into
deepmodeling:masterfrom
njzjz-bot:fix/nvnmd-tensor-neighbor-list-5652

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • parse mode-4 neighbor lists stored in NVNMD mesh tensors instead of rebuilding them from coordinates
  • validate the tensor layout, reject local or neighbor indices outside the current frame, and own copied neighbor rows for the duration of the op
  • cover both standard and mixed-type NVNMD env-mat operators, including malformed input

Why existing tests missed this

Existing NVNMD entrypoint tests only exercised self-built neighbor lists with 0-, 1-, 6-, or 7-element meshes. No NVNMD env-mat test passed a mesh larger than 16 elements, no malformed test supplied a nonnegative index beyond nall, and no caller-provided list intentionally differed from the distance-built list. In normal inference paths those two lists are usually identical, so rebuilding the list produced plausible output and hid the bug.

Validation

  • cmake --build source/build --target deepmd_op -j2
  • fresh build-tree TensorFlow op: TestOpProdEnvMatNvnmdTensorNlist (5 passed), including a positive out-of-range neighbor index
  • ruff format .
  • ruff check .
  • git diff --check

Fixes #5652

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

Summary by CodeRabbit

  • New Features

    • Added support for neighbor lists supplied through mesh tensors in NVNMD environment-matrix operations.
    • Added validation for malformed mesh data and out-of-range neighbor references.
  • Bug Fixes

    • Improved error handling for incomplete or invalid neighbor-list inputs.
  • Tests

    • Added coverage for standard and mixed-type operations using mesh-provided neighbor lists.

@dosubot dosubot Bot added the bug label Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

NVNMD CPU environment-matrix operations now parse neighbor lists from mesh tensors for nei_mode == 4, validate malformed inputs, propagate preparation errors, and test standard and mixed-type execution paths.

Changes

NVNMD tensor neighbor-list handling

Layer / File(s) Summary
Mesh neighbor-list parsing and status handling
source/op/tf/prod_env_mat_multi_device_nvnmd.cc
The CPU preparation helpers now parse mesh-provided neighbor lists, validate headers, offsets, frame bounds, and indices, populate InputNlist data, and return TensorFlow statuses.
Operation integration
source/op/tf/prod_env_mat_multi_device_nvnmd.cc
Standard and mixed-type NVNMD CPU paths pass mesh tensor sizes to _prepare_coord_nlist_cpu and propagate its status with OP_REQUIRES_OK.
Tensor neighbor-list validation
source/tests/tf/test_nvnmd_op.py
Tests cover supplied neighbor-list output for both operations and invalid truncated or out-of-range mesh data.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant ProdEnvMatNVNMD
  participant _prepare_coord_nlist_cpu
  participant _prepare_mesh_nlist_cpu
  Test->>ProdEnvMatNVNMD: provide mesh tensor and nei_mode 4
  ProdEnvMatNVNMD->>_prepare_coord_nlist_cpu: pass mesh data and size
  _prepare_coord_nlist_cpu->>_prepare_mesh_nlist_cpu: parse and validate mesh list
  _prepare_mesh_nlist_cpu-->>_prepare_coord_nlist_cpu: return neighbor-list data or error
  _prepare_coord_nlist_cpu-->>ProdEnvMatNVNMD: return status
  ProdEnvMatNVNMD-->>Test: return environment-matrix result or InvalidArgumentError
Loading

Possibly related PRs

Suggested labels: OP, Python

Suggested reviewers: njzjz

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code and tests match #5652 by honoring mode-4 mesh neighbor lists in both NVNMD env-mat ops and verifying malformed and differing lists.
Out of Scope Changes check ✅ Passed The changes stay focused on the NVNMD neighbor-list fix and its tests, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: NVNMD TensorFlow ops now honor tensor-provided neighbor lists.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@njzjz-bot
njzjz-bot force-pushed the fix/nvnmd-tensor-neighbor-list-5652 branch from 83da73e to 74c0cd2 Compare July 16, 2026 21:06
Comment thread source/op/tf/prod_env_mat_multi_device_nvnmd.cc Fixed
Parse and validate mode-4 mesh tensors instead of rebuilding their neighbor lists in the NVNMD environment-matrix operators. Reject truncated lists, invalid local indices, and neighbor indices outside the current frame before downstream coordinate or type access.

Cover both operator variants, malformed tensor input, and positive out-of-range neighbor indices.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@njzjz-bot
njzjz-bot force-pushed the fix/nvnmd-tensor-neighbor-list-5652 branch from 74c0cd2 to 29cc7b5 Compare July 17, 2026 01:41
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.83333% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.31%. Comparing base (6c3b985) to head (29cc7b5).

Files with missing lines Patch % Lines
source/op/tf/prod_env_mat_multi_device_nvnmd.cc 70.83% 8 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5845      +/-   ##
==========================================
- Coverage   78.58%   78.31%   -0.27%     
==========================================
  Files        1050     1050              
  Lines      120637   120672      +35     
  Branches     4356     4367      +11     
==========================================
- Hits        94801    94510     -291     
- Misses      24278    24582     +304     
- Partials     1558     1580      +22     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code scan] Honor tensor-provided neighbor lists in NVNMD env-mat ops

2 participants