[converter] Add aten.masked_scatter lowering#16
Merged
gokulkrishna98 merged 2 commits intoJun 16, 2026
Conversation
Register a lowering for aten.masked_scatter.default. Semantics:
out = self.clone()
out[mask] = source.flatten()[: mask.sum()]
Implementation flattens self/mask/source, then for each flat position
picks from source[cumsum(mask) - 1] if mask is True else self. False
positions select away the gathered values via where(), so out-of-range
indices there are harmless. Indices for True positions are guaranteed
in [0, mask.sum() - 1] by construction.
Supports dynamic shapes by reshaping with the runtime shape vector
(coreai.get_shape) instead of the type-level shape, which carries a
sentinel for unknown dims, and by using -1 in the flat reshapes to
let coreai.reshape infer the numel. Mask broadcast also routes
through the runtime shape when self is dynamic.
Adds TestMaskedScatter covering:
- Static and dynamic IR FileCheck (full operand chain pinned for
static; op order asserted for dynamic).
- Numerical validation across {f32, f16, i32} × {static, dynamic}.
- Corner cases: all-False mask (output == self), all-True mask
(output == src reshape), src larger than mask.sum() (extras
unused), and a lower-rank mask that broadcasts right-aligned
onto self.
Lewis300
approved these changes
Jun 16, 2026
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.
Description:
Testing: