You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 <[email protected]>
Reviewed-by: Reilly Grant <[email protected]>
Commit-Queue: Junwei Fu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1387213}
0 commit comments