github web-platform-tests/wpt merge_pr_49343

latest releases: merge_pr_49470, epochs/three_hourly/2024-12-03_06H, epochs/six_hourly/2024-12-03_06H...
9 months ago

webnn: Support gatherElements in tflite converter

There is no TFLite operator to map directly WebNN gatherElements, but
it can be supported with tfl.gather_nd, the test cases[1] and the
doc[2] show the gather_nd can gether not only slices but also elements,
but gather_nd can't gather along the axis, so the indices used by
gather_nd need to be calculated by unravelling the flat index and
adjusting value with the axis.

The coordinates are calculated by the stride of each dimension. For
example a shape (3, 2) array can map to the following coordinates:
// index row, col
// [[0, 1,] [[0, 0], [0, 1],
// [2, 3,] => [1, 0], [1, 1]
// [4, 5,]] [2, 0], [2, 1]]

Adjusting the coordinates with WebNN indices operand along the axis,
// unravelled index WebNN indices axis = 0 TFLite indices
// [[0, 0], [0, 1], [[1, 0], [[1 ,0], [0, 1],
// [1, 0], [1, 1] [2, 1], => [2, 0], [1, 1],
// [2, 0], [2, 1]] [0, 2]] [0, 0], [2, 1]]

[1] https://www.tensorflow.org/mlir/tfl_ops#tflgather_nd_tflgatherndop
[2] https://www.tensorflow.org/guide/tensor_slicing#insert_data_into_tensors

Bug: 40206287
Change-Id: I61ad75585405039da10af05f3300799fe8f32855
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6000111
Reviewed-by: ningxin hu ningxin.hu@intel.com
Reviewed-by: Reilly Grant reillyg@chromium.org
Commit-Queue: Junwei Fu junwei.fu@intel.com
Cr-Commit-Position: refs/heads/main@{#1387213}

Don't miss a new wpt release

NewReleases is sending notifications on new releases.