fix(pt): honor is_sorted in SE-Attention tabulation#5905
Conversation
Forward the public sorting flag through the PyTorch forward and first-backward helpers so unsorted excluded-type rows are evaluated consistently with grad-grad. Fixes deepmodeling#5890 Coding-Agent: Codex Codex-Version: codex-cli 0.144.6 Model: gpt-5.6-sol Reasoning-Effort: xhigh
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughPyTorch SE-Attention tabulation now forwards ChangesSE-Attention sorting propagation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness bug in the PyTorch SE-Attention tabulation custom op where is_sorted was accepted/stored but not forwarded into the CPU/GPU backend entry points for forward and first-backward, causing unsorted neighbor rows to be treated as sorted. It ensures all autograd stages (forward, backward, double-backward) use the same sorting contract, matching expected backend behavior.
Changes:
- Thread
is_sortedthrough the PyTorch SE-Attention forward helper into both CPU and GPUtabulate_fusion_se_a_*entry points. - Thread
is_sortedthrough the first-backward helper so backward uses the same sorting contract as forward (and aligns with grad-grad’s existing behavior). - Add float32/float64 regression tests covering unsorted forward, backward, and second-order backward behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
source/op/pt/tabulate_multi_device.cc |
Forwards is_sorted through SE-Attention forward and first-backward helper calls into CPU/GPU backend functions and preserves the flag across autograd stages. |
source/tests/pt/test_tabulate_fusion_se_atten.py |
Adds regression coverage ensuring unsorted neighbor rows affect forward/gradients correctly for both float32 and float64, including double-backward checks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5905 +/- ##
==========================================
- Coverage 78.89% 78.64% -0.26%
==========================================
Files 1054 1054
Lines 121774 121774
Branches 4408 4408
==========================================
- Hits 96076 95771 -305
- Misses 24121 24427 +306
+ Partials 1577 1576 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
is_sortedthrough the PyTorch SE-Attention forward helper to the CPU and GPU library entry pointsFixes #5890
Testing
python -m pytest source/tests/pt/test_tabulate_fusion_se_atten.py -v(12 passed)ruff format .ruff check .pre-commit run clang-format --files source/op/pt/tabulate_multi_device.ccdp --versiondp --pt -hdeepmdanddeepmd.ptCoding agent: Codex
Codex version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary by CodeRabbit
Bug Fixes
Tests