Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement scatterElements #105

Merged
merged 5 commits into from
Oct 8, 2024

Conversation

BruceDai
Copy link
Contributor

@huningxin @fdwr @shiyi9801 PTAL, thanks.

Copy link

@fdwr fdwr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Bruce. Some small comments, and then LGTM.

src/lib/validate-input.js Outdated Show resolved Hide resolved
src/scatter_elements.js Outdated Show resolved Hide resolved
@BruceDai
Copy link
Contributor Author

BruceDai commented Oct 8, 2024

@fdwr I've addressed your comments in the new commit, please take another look, thanks!

Copy link
Contributor

@huningxin huningxin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a comment

src/lib/validate-input.js Show resolved Hide resolved
src/scatter_elements.js Outdated Show resolved Hide resolved
Copy link
Contributor Author

@BruceDai BruceDai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @huningxin!
I've addressed your comments, please take another review in new commit.

src/lib/validate-input.js Show resolved Hide resolved
Copy link
Contributor

@huningxin huningxin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@huningxin huningxin merged commit cbf83d0 into webmachinelearning:main Oct 8, 2024
3 checks passed
Copy link

@fdwr fdwr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks Bruce.

src/scatter_elements.js Show resolved Hide resolved
let indicesValue = indices.getValueByIndex(indicesIndex);
indicesValue = indicesValue < 0 ? indicesValue + input.shape[axis] : indicesValue;
const outputLocation =
[...indicesLocation.slice(0, axis), indicesValue, ...indicesLocation .slice(axis + 1)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we restrict indices sizes are less than or equal to input sizes along every dimensions except axis? (indices.shape[i] <= input.shape[i] if i != axis). Otherwise, indicesLocation.slice() would contain invalid index value that is greater than output size.

BTW, DirectML requires "IndicesTensor.Sizes must match InputTensor.Sizes for every dimension except Axis." https://learn.microsoft.com/en-us/windows/win32/api/directml/ns-directml-dml_scatter_operator_desc. The current Chromium prototype follows this rule: https://chromium-review.googlesource.com/c/chromium/src/+/5921136/9/services/webnn/public/cpp/graph_validation_utils.cc#2563

CoreML only requires rank(indices)== rank(input): https://apple.github.io/coremltools/source/coremltools.converters.mil.mil.ops.defs.html#coremltools.converters.mil.mil.ops.defs.iOS15.scatter_gather.scatter_along_axis

@fdwr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants