Handle broadcasted bool masks in aten.index_put - #2966
Handle broadcasted bool masks in aten.index_put#2966Justin Chu (justinchuby) with Copilot wants to merge 4 commits into
aten.index_put#2966Conversation
aten.index_put
There was a problem hiding this comment.
Pull request overview
This PR fixes aten.index_put lowering for boolean masks by avoiding incorrect assumptions in the multi-index bool-mask path and routing mixed/multi boolean indexing through the existing advanced-index (ScatterND) lowering.
Changes:
- Restricts the dedicated boolean-mask lowering to the single-index form (
[mask]). - Converts 1-D boolean indices appearing in mixed/multi-index cases into integer position tensors via
NonZero, then reuses the advanced-indexScatterNDlowering (including broadcast handling). - Adds end-to-end export coverage for broadcasted multi-mask boolean indexing and for boolean indexing mixed with
None(slice-like) indices.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/function_libs/torch_lib/e2e_ops_tests.py | Adds new e2e export test cases covering broadcasted multi-mask bool indexing and bool mask mixed with None. |
| onnxscript/function_libs/torch_lib/ops/core.py | Updates aten_index_put lowering to route mixed/multi bool masks through the advanced-index path by converting bool masks to integer indices, and adjusts rank bookkeeping accordingly. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2966 +/- ##
==========================================
+ Coverage 72.64% 72.66% +0.01%
==========================================
Files 265 265
Lines 32192 32219 +27
Branches 3038 3044 +6
==========================================
+ Hits 23385 23411 +26
+ Misses 7776 7774 -2
- Partials 1031 1034 +3 ☔ View full report in Codecov by Harness. |
| i for i, index in enumerate(indices) if index is not None and index.dtype == BOOL.dtype | ||
| ] | ||
| if len(indices) == 1 and bool_index_positions == [0]: | ||
| return _aten_index_put_bool(self, indices, values, accumulate) |
There was a problem hiding this comment.
I think this should be fixed, instead
aten.index_put's bool-mask lowering handled the covered single-mask path correctly, but the multi-mask path assumed equalTruecounts and failed on valid broadcasted cases. It also rejected mixed bool/Noneindexing such asx[:, mask] = value, even though the generic advanced-index path can represent that form.What changed
[mask]case.NonZero, then reuse the existing advanced-indexScatterNDlowering.Behavioral impact
Noneand a 1-D bool mask now lowers through the generic path instead of failing early.Regression coverage
None.Example of a newly covered case: