Handle broadcasted bool masks in aten.index_put#2966
Open
justinchuby with Copilot wants to merge 2 commits into
Open
Handle broadcasted bool masks in aten.index_put#2966justinchuby with Copilot wants to merge 2 commits into
aten.index_put#2966justinchuby with Copilot wants to merge 2 commits into
Conversation
Copilot
AI
changed the title
[WIP] Fix multi-mask index_put equal True counts assumption
Handle broadcasted bool masks in Jul 16, 2026
aten.index_put
justinchuby
marked this pull request as ready for review
July 16, 2026 15:20
Contributor
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.56% 72.65% +0.09%
==========================================
Files 263 265 +2
Lines 32069 32189 +120
Branches 3020 3038 +18
==========================================
+ Hits 23270 23388 +118
+ Misses 7775 7769 -6
- Partials 1024 1032 +8 ☔ View full report in Codecov by Harness. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: