Skip to content

Commit

Permalink
Bug 1934612 [wpt PR 49466] - webnn: Support scatterElements in tflite…
Browse files Browse the repository at this point in the history
… converter, a=testonly

Automatic update from web-platform-tests
webnn: Support scatterElements in tflite converter

There is no TFLite operator to map directly WebNN scatterElements, but
it can be supported with tfl.scatter_nd as the test cases[1] and the
doc[2] described.

The indices also need to be converted like gatherElements.
The update operand must be reshaped to one dimension[3].

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/tflite/src/tensorflow/lite/kernels/scatter_nd_test.cc;l=73
[2] https://www.tensorflow.org/guide/tensor_slicing#insert_data_into_tensors
[3] https://source.chromium.org/chromium/chromium/src/+/main:third_party/tflite/src/tensorflow/lite/kernels/scatter_nd.cc;l=64?q=scatter_nd.cc&ss=chromium%2Fchromium%2Fsrc

Bug: 40206287
Change-Id: If0461ceb6c4cb8bcee6ff2b59443851a5cdc7de5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6048693
Reviewed-by: Phillis Tang <[email protected]>
Commit-Queue: Phillis Tang <[email protected]>
Reviewed-by: ningxin hu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1391759}

--

wpt-commits: e9d8459f9c413260ace922b865157075bc12b465
wpt-pr: 49466
  • Loading branch information
fujunwei authored and moz-wptsync-bot committed Dec 10, 2024
1 parent 38c1c72 commit 60e0ba6
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,40 @@ const scatterElementsTests = [
}
}
},
{
'name': 'Scatter elements along axis 0 and constant indices',
'graph': {
'inputs': {
'input': {
'data': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
'descriptor': {shape: [3, 3], dataType: 'float32'}
},
'indices': {
'data': [1, 0, 2, 0, 2, 1],
'descriptor': {shape: [2, 3], dataType: 'int32'},
'constant': true
},
'updates': {
'data': [1.0, 1.1, 1.2, 2.0, 2.1, 2.2],
'descriptor': {shape: [2, 3], dataType: 'float32'}
}
},
'operators': [{
'name': 'scatterElements',
'arguments': [
{'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'},
{'options': {'axis': 0}}
],
'outputs': 'output'
}],
'expectedOutputs': {
'output': {
'data': [2.0, 1.1, 0.0, 1.0, 0.0, 2.2, 0.0, 2.1, 1.2],
'descriptor': {shape: [3, 3], dataType: 'float32'}
}
}
}
},
{
'name': 'Scatter elements along axis 1',
'graph': {
Expand Down Expand Up @@ -78,6 +112,40 @@ const scatterElementsTests = [
}
}
}
},
{
'name': 'Scatter elements along axis 1 and constant indices',
'graph': {
'inputs': {
'input': {
'data': [1.0, 2.0, 3.0, 4.0, 5.0],
'descriptor': {shape: [1, 5], dataType: 'float32'}
},
'indices': {
'data': [1, 3],
'descriptor': {shape: [1, 2], dataType: 'int32'},
'constant': true
},
'updates': {
'data': [1.1, 2.1],
'descriptor': {shape: [1, 2], dataType: 'float32'}
}
},
'operators': [{
'name': 'scatterElements',
'arguments': [
{'input': 'input'}, {'indices': 'indices'}, {'updates': 'updates'},
{'options': {'axis': 1}}
],
'outputs': 'output'
}],
'expectedOutputs': {
'output': {
'data': [1.0, 1.1, 3.0, 2.1, 5.0],
'descriptor': {shape: [1, 5], dataType: 'float32'}
}
}
}
}
];

Expand Down

0 comments on commit 60e0ba6

Please sign in to comment.