Skip to content

fix(tf): preserve ghost gradients in ProdForceGrad#5848

Open
njzjz-bot wants to merge 1 commit into
deepmodeling:masterfrom
njzjz-bot:fix/prod-force-grad-ghost-boundary-5656
Open

fix(tf): preserve ghost gradients in ProdForceGrad#5848
njzjz-bot wants to merge 1 commit into
deepmodeling:masterfrom
njzjz-bot:fix/prod-force-grad-ghost-boundary-5656

Conversation

@njzjz-bot

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

Copy link
Copy Markdown
Contributor

Summary

  • align legacy ProdForceGrad with ProdForce's [nframes, 3 * nall] output contract
  • preserve each ghost atom's own upstream gradient instead of folding indices modulo nloc
  • validate neighbor indices and cover a second ghost at nloc + 1 across two frames

Why existing tests missed this

The direct TensorFlow gradient test exercised the newer ProdForceSeA helper with nall == nloc, so it had neither ghost atoms nor the legacy ProdForceGrad implementation. Higher-level loc-frame coverage did not differentiate the legacy force output with deliberately distinct local and ghost upstream gradients. The stale code also looked superficially consistent with the newer local-only helper even though the legacy forward op had been changed in 2018 to retain separate ghost-force outputs.

The regression invokes tf.gradients on the real legacy ProdForce op, uses j_idx == nloc + 1 so the removed j_idx > nloc modulo branch is actually exercised, assigns distinct local and two-ghost upstream gradients, and uses two frames to lock the corrected nall * 3 frame stride.

Validation

  • DP_ENABLE_PYTORCH=0 uv pip install -e .[cpu,test]
  • pytest source/tests/tf/test_prod_force_grad.py -q using the current editable finder (3 passed, 1 inherited TensorFlow helper skipped)
  • review follow-up against the rebuilt TensorFlow op: strengthened second-ghost regression passed (1 passed, 1 inherited helper skipped)
  • ruff format .
  • ruff check .
  • clang-format dry run with --Werror
  • git diff --check

Fixes #5656

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

Warning

Review limit reached

@njzjz-bot, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 3 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 093acb2a-7259-4731-bd52-7dd96e6c3320

📥 Commits

Reviewing files that changed from the base of the PR and between 6c3b985 and 86b61b1.

📒 Files selected for processing (2)
  • source/op/tf/prod_force_grad.cc
  • source/tests/tf/test_prod_force_grad.py
✨ 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.

Size upstream force gradients by all atoms and keep local and ghost slices distinct in the legacy TensorFlow ProdForce gradient. Validate atom counts and neighbor bounds before indexing.

Cover a second ghost at index nloc + 1 so the regression exercises the removed modulo branch and proves its independent upstream gradient is used.

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/prod-force-grad-ghost-boundary-5656 branch from 90f032a to 86b61b1 Compare July 17, 2026 01:50
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.32%. Comparing base (6c3b985) to head (86b61b1).

Files with missing lines Patch % Lines
source/op/tf/prod_force_grad.cc 33.33% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5848      +/-   ##
==========================================
- Coverage   78.58%   78.32%   -0.27%     
==========================================
  Files        1050     1050              
  Lines      120637   120642       +5     
  Branches     4356     4365       +9     
==========================================
- Hits        94801    94488     -313     
- Misses      24278    24592     +314     
- Partials     1558     1562       +4     

☔ 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] Handle ghost-boundary indices consistently in legacy ProdForceGrad

1 participant