fix(ops): validate tabulation tensor shapes - #5932
Conversation
Reject malformed TensorFlow and PyTorch tabulation buffers before native kernels can index outside their logical storage. 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 (5)
📝 WalkthroughWalkthroughShared checked arithmetic validates tabulation metadata and required buffer sizes. PyTorch and TensorFlow tabulation operations now validate tensor contracts before native dispatch, with new tests covering malformed shapes, flattened layouts, and undersized buffers. ChangesTabulation validation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant TabulationWrapper
participant ValidationHelpers
participant NativeKernel
Caller->>TabulationWrapper: provide table and operation tensors
TabulationWrapper->>ValidationHelpers: validate shapes and required capacity
ValidationHelpers-->>TabulationWrapper: accept or report validation error
TabulationWrapper->>NativeKernel: dispatch validated inputs
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #5932 +/- ##
==========================================
- Coverage 79.21% 78.90% -0.31%
==========================================
Files 1069 1070 +1
Lines 124070 124302 +232
Branches 4522 4551 +29
==========================================
- Hits 98278 98079 -199
- Misses 24171 24584 +413
- Partials 1621 1639 +18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Root cause
The TensorFlow and PyTorch tabulation wrappers checked mostly tensor rank, then derived
nloc, neighbor dimensions, and output sizes from other tensors. The native CPU and GPU code indexes flat buffers using those derived sizes. A rank-correct but shorterem_x,em,two_embed, cotangent, descriptor,table_info, or table could therefore be read or written beyond its logical allocation.Introduction and history
This is an accumulated public-boundary validation gap rather than one recent native-kernel regression:
54aff9571, PR pt: add 4 tabulate_fusion op #3877, in 2024;dddba6e8c, PR Enable model compression for se_atten #2532, in 2023;76a1a2a1dand472d7c4e5.Each wrapper trusted shapes produced by the normal descriptor path, but raw custom-op calls and upstream shape bugs can violate that trust boundary.
Test gap
Existing PyTorch tests covered matched forward, backward, and second-order inputs only. TensorFlow had model-compression tests for valid graphs but no focused raw-op rejection tests. They also did not explicitly preserve the legal flattened rank-2
em_xlayout used by TensorFlow compression, which was important while tightening validation.Fix
Validation
test_1framescenarios passed for SE-A, SE-Attention, SE-T, and SE-R;em_x, truncatedem, shorttwo_embed, shorttable_info, short table storage, and mismatched gradient shapes;ruff format .;ruff check ..Fixes #5895
Coding agent: Codex
Codex version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary by CodeRabbit
Bug Fixes
Tests