Skip to content

fix(tf): initialize NVNMD map outputs#5847

Open
njzjz-bot wants to merge 1 commit into
deepmodeling:masterfrom
njzjz-bot:fix/nvnmd-map-output-contract-5655
Open

fix(tf): initialize NVNMD map outputs#5847
njzjz-bot wants to merge 1 commit into
deepmodeling:masterfrom
njzjz-bot:fix/nvnmd-map-output-contract-5655

Conversation

@njzjz-bot

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

Copy link
Copy Markdown
Contributor

Summary

  • correct MapFltNvnmd's stale three-input check to its registered four-input contract
  • validate table, gradient-table, and interval metadata before dimension/index arithmetic
  • zero-fill values outside every configured interval, including the corresponding input gradient

Why existing tests missed this

test_nvnmd_op.py directly covered the other NVNMD arithmetic primitives but not MapFltNvnmd. Normal descriptor and mapping-generation callers keep values inside generated table ranges, release builds compile out the stale DCHECK, and freshly allocated output pages often happen to contain zeros. Together those conditions hid both the invalid debug contract and skipped output writes.

The regression warms a large same-shaped output with nonzero values before evaluating out-of-range inputs, making allocator reuse expose the old behavior reliably instead of depending on fresh memory contents.

Validation

  • cmake --build source/build --target deepmd_op -j2
  • fresh build-tree TensorFlow op: TestOpMapFltNvnmd (2 passed; inherited TensorFlow session helper skipped)
  • ruff format .
  • ruff check .
  • clang-format dry run with --Werror
  • git diff --check

Fixes #5655

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

Summary by CodeRabbit

  • Bug Fixes

    • Added validation for input counts, tensor dimensions, table shapes, and interval metadata.
    • Invalid configurations now return clear errors instead of proceeding with calculations.
    • Outputs are initialized consistently, including zero results for values outside supported ranges.
    • Corrected table metadata and gradient handling.
  • Tests

    • Added coverage for out-of-range mapping and gradients.
    • Added validation for mismatched table and gradient shapes.

Correct the MapFltNvnmd four-input contract, validate its table metadata, and
zero outputs that fall outside every mapping interval. Cover deterministic
allocator reuse, gradient behavior, and malformed table-gradient shapes.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@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

MapFltNvnmd now enforces its four-input and shape contracts, validates table metadata, initializes outputs deterministically, and tests out-of-range mapping, gradients, and invalid table-gradient shapes.

Changes

MapFltNvnmd runtime behavior

Layer / File(s) Summary
Runtime validation and deterministic mapping
source/op/tf/map_flt_nvnmd.cc
Adds runtime validation for input count, tensor shapes, table dimensions, and interval metadata; corrects input indexing and zero-initializes outputs.
TensorFlow behavior tests
source/tests/tf/test_nvnmd_op.py
Tests zero outputs and gradients for out-of-range values, expected mapped values, and rejection of mismatched table_grad shapes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and describes the main change to NVNMD map output initialization.
Linked Issues check ✅ Passed The PR fixes the four-input contract, initializes out-of-range outputs, and adds regression tests requested by #5655.
Out of Scope Changes check ✅ Passed The changes stay focused on the MapFltNvnmd fix and its tests, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
source/op/tf/map_flt_nvnmd.cc (1)

117-134: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Interval metadata is parsed twice (validation loop here, then again in the main ss loop below).

Correctness looks solid — n0>=0 && n1<=shT.dim_size(0) prevents the OOB table read, and dx>0/n1>n0 avoid divide-by-zero and negative clamp indices. As an optional cleanup, consider extracting a small helper (e.g. a struct Interval { x0,x1,dx; int n0,n1; } parsed once per ss) so the same five floats aren't decoded from info in two separate loops.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@source/op/tf/map_flt_nvnmd.cc` around lines 117 - 134, Extract the repeated
interval metadata decoding into a small reusable representation, such as an
Interval struct, and parse each five-value entry from info once per ss. Reuse
the parsed x0, x1, dx, n0, and n1 values in both the validation loop and the
main ss processing loop, preserving the existing validation and mapping
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@source/op/tf/map_flt_nvnmd.cc`:
- Around line 117-134: Extract the repeated interval metadata decoding into a
small reusable representation, such as an Interval struct, and parse each
five-value entry from info once per ss. Reuse the parsed x0, x1, dx, n0, and n1
values in both the validation loop and the main ss processing loop, preserving
the existing validation and mapping behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6ef6e5ae-b840-4092-ba06-c22e30fbfc19

📥 Commits

Reviewing files that changed from the base of the PR and between 6c3b985 and 76dc26e.

📒 Files selected for processing (2)
  • source/op/tf/map_flt_nvnmd.cc
  • source/tests/tf/test_nvnmd_op.py

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.32%. Comparing base (6c3b985) to head (76dc26e).

Files with missing lines Patch % Lines
source/op/tf/map_flt_nvnmd.cc 50.00% 7 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5847      +/-   ##
==========================================
- Coverage   78.58%   78.32%   -0.27%     
==========================================
  Files        1050     1050              
  Lines      120637   120652      +15     
  Branches     4356     4358       +2     
==========================================
- Hits        94801    94496     -305     
- Misses      24278    24587     +309     
- Partials     1558     1569      +11     

☔ 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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code scan] Initialize MapFltNvnmd outputs and fix its input contract

1 participant