commit 9ff9e72e350137a75678347c472e2a7459b33a51
parent e3cae1811ce2705f2b3bab55e95833e11b441b64
Author: junwei <junwei.fu@intel.com>
Date: Wed, 15 Oct 2025 08:24:38 +0000
Bug 1993627 [wpt PR 55331] - Reland "webnn: Enable mxbai_rerank_base_v1_fp32 model on TFLite backend", a=testonly
Automatic update from web-platform-tests
Reland "webnn: Enable mxbai_rerank_base_v1_fp32 model on TFLite backend"
This is a reland of commit 7ccda24096f5914472cbf01e76632bd09641b8cd
This reland fixes unexpected ULP distance for subgraph gatherElements +
matmul.
Original change's description:
> webnn: Enable mxbai_rerank_base_v1_fp32 model on TFLite backend
>
> GatherElements is emulated by GatherND that will always output a tensor
> with one dimension because the shape of the indices tensor is 2
> [flat_indices_size, input_rank], so we need to reshape the output tensor
> to the expected shape.
>
> For example, if the input shape is [4, 2, 2], the indices are [1, 2, 2]
> and axis = 0, then the output shape of gatherND will be [4] that is
> calculated with ResizeTensor. The shape needs to be reshaped to [1, 2,
> 2].
>
> Bug: 446463978
> Change-Id: If3cbada6a46822ec4b44b60dec831caa4bc174f0
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6987334
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Commit-Queue: Junwei Fu <junwei.fu@intel.com>
> Reviewed-by: ningxin hu <ningxin.hu@intel.com>
> Cr-Commit-Position: refs/heads/main@{#1527269}
Bug: 446463978
Change-Id: Ie869a41370ba068454b231d0b9a0e9503783dbb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7024653
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Junwei Fu <junwei.fu@intel.com>
Reviewed-by: ningxin hu <ningxin.hu@intel.com>
Cr-Commit-Position: refs/heads/main@{#1527909}
--
wpt-commits: f76d86c57aef901397a9538ebb788039e772c5a7
wpt-pr: 55331
Diffstat:
3 files changed, 75 insertions(+), 12 deletions(-)
diff --git a/testing/web-platform/tests/webnn/conformance_tests/matmul.https.any.js b/testing/web-platform/tests/webnn/conformance_tests/matmul.https.any.js
@@ -13,17 +13,6 @@
// MLOperand matmul(MLOperand a, MLOperand b);
-const getMatmulPrecisionTolerance = (graphResources) => {
- const args = graphResources.operators[0].arguments;
- const shapeA =
- graphResources.inputs[args[0][Object.keys(args[0])[0]]].descriptor.shape;
- const tolerance = shapeA[shapeA.length - 1] * 2;
- const toleranceValueDict = {float32: tolerance, float16: tolerance};
- const expectedDataType =
- getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs);
- return {metricType: 'ULP', value: toleranceValueDict[expectedDataType]};
-};
-
const matmulTests = [
{
'name': 'matmul float32 2D and 2D tensors',
@@ -1096,4 +1085,4 @@ const matmulTests = [
];
webnn_conformance_test(
- matmulTests, buildAndExecuteGraph, getMatmulPrecisionTolerance);
+ matmulTests, buildAndExecuteGraph, getPrecisionTolerance);
diff --git a/testing/web-platform/tests/webnn/conformance_tests/subgraph.https.any.js b/testing/web-platform/tests/webnn/conformance_tests/subgraph.https.any.js
@@ -2524,6 +2524,58 @@ const subgraphTests = [
}
},
{
+ 'name': 'gatherElements + matmul',
+ 'graph': {
+ 'inputs': {
+ 'gatherElementsInput': {
+ 'data': [
+ -66.05901336669922, -68.9197006225586, -77.02045440673828,
+ -26.158037185668945, 89.0337142944336, -45.89653396606445,
+ 43.84803771972656, 48.81806945800781, 51.79948425292969
+ ],
+ 'descriptor': {shape: [3, 3], dataType: 'float32'}
+ },
+ 'gatherElementsIndices': {
+ 'data': [1, 0, 2, 2, 1, 0],
+ 'descriptor': {shape: [2, 3], dataType: 'int32'},
+ 'constant': true
+ },
+ 'matmulB': {
+ 'data': [
+ 56.46701431274414, 99.86045837402344, 71.054931640625,
+ 32.454383850097656, 17.310747146606445, 2.586275100708008,
+ ],
+ 'descriptor': {shape: [3, 2], dataType: 'float32'}
+ },
+ },
+ 'operators': [
+ {
+ 'name': 'gatherElements',
+ 'arguments': [
+ {'input': 'gatherElementsInput'}, {'indices': 'gatherElementsIndices'}
+ ],
+ 'outputs': 'gatherElementsOutput'
+ },
+ {
+ 'name': 'matmul',
+ 'arguments': [
+ {'a': 'gatherElementsOutput'}, {'b': 'matmulB'}
+ ],
+ 'outputs': 'matmulOutput'
+ }
+ ],
+ 'expectedOutputs': {
+ 'matmulOutput': {
+ 'data': [
+ -5477.462890625, -4714.93212890625,
+ 7468.97021484375, 7069.02294921875
+ ],
+ 'descriptor': {shape: [2, 2], dataType: 'float32'}
+ }
+ }
+ }
+ },
+ {
'name': 'float16 graph with float32 input and output',
'graph': {
'inputs': {
diff --git a/testing/web-platform/tests/webnn/resources/utils.js b/testing/web-platform/tests/webnn/resources/utils.js
@@ -89,6 +89,10 @@ const getPrecisionTolerance = (graphResources, intermediateOperands) => {
toleranceValue += getGemmPrecisionTolerance(op, graphResources,
intermediateOperands).value;
break;
+ case 'matmul':
+ toleranceValue += getMatmulPrecisionTolerance(op, graphResources,
+ intermediateOperands).value;
+ break;
case 'softmax':
toleranceValue += getSoftmaxPrecisionTolerance(
op, graphResources, intermediateOperands)
@@ -1107,6 +1111,24 @@ const getGemmPrecisionTolerance =
return {metricType: 'ULP', value: toleranceValueDict[expectedDataType]};
};
+const getMatmulPrecisionTolerance =
+ (op, graphResources, intermediateOperands) => {
+ const {inputs} = graphResources;
+ const args = op.arguments;
+ let shapeA;
+ const indexA = args[0][Object.keys(args[0])[0]];
+ if (inputs[indexA]) {
+ shapeA = inputs[indexA].descriptor.shape;
+ } else {
+ shapeA = intermediateOperands[indexA].shape;
+ }
+ const tolerance = shapeA[shapeA.length - 1] * 2;
+ const toleranceValueDict = {float32: tolerance, float16: tolerance};
+ const expectedDataType =
+ getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs);
+ return {metricType: 'ULP', value: toleranceValueDict[expectedDataType]};
+};
+
const getConv2dPrecisionTolerance =
(op, graphResources, intermediateOperands) => {
// number of reduced input elements multiplied by filter and summed (a sliding