Skip to content

Commit

Permalink
webnn: support all axes for resample2d
Browse files Browse the repository at this point in the history
Allow arbitrary axes as long as they are valid dimensions for
resample2d instead of restricting them to point to spacial dimensions.
Apply transposes for input & output when the axes is not supported by
the backend.

See spec pr: webmachinelearning/webnn#752

Change-Id: I5112abf1f43328d901000a4cff8468bd9bfe2dfb
Cq-Include-Trybots: luci.chromium.try:win11-blink-rel,mac14.arm64-blink-rel,mac14-blink-rel, linux-blink-rel
Bug: 329658123, 334914468
  • Loading branch information
philloooo authored and chromium-wpt-export-bot committed Aug 23, 2024
1 parent 26c8809 commit ff3820b
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 9 deletions.
112 changes: 112 additions & 0 deletions webnn/conformance_tests/resample2d.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,44 @@ const resample2dTests = [
}
}
},
{
'name':
'resample2d(upsample) float32 4D tensor explicit options.axes=[3, 2]',
'graph': {
'inputs': {
'resample2dInput': {
'data': [
59.92947006225586, 41.98918914794922, 66.39534759521484,
90.7006607055664, 86.95105743408203, 79.10005187988281
],
'descriptor': {'dimensions': [1, 1, 2, 3], 'dataType': 'float32'}
}
},
'operators': [{
'name': 'resample2d',
'arguments': [
{'input': 'resample2dInput'},
{'options': {'sizes': [6, 4], 'axes': [3, 2]}}
],
'outputs': 'resample2dOutput'
}],
'expectedOutputs': {
'resample2dOutput': {
'data': [
59.92947006225586, 59.92947006225586, 41.98918914794922,
41.98918914794922, 66.39534759521484, 66.39534759521484,
59.92947006225586, 59.92947006225586, 41.98918914794922,
41.98918914794922, 66.39534759521484, 66.39534759521484,
90.7006607055664, 90.7006607055664, 86.95105743408203,
86.95105743408203, 79.10005187988281, 79.10005187988281,
90.7006607055664, 90.7006607055664, 86.95105743408203,
86.95105743408203, 79.10005187988281, 79.10005187988281
],
'descriptor': {'dimensions': [1, 1, 4, 6], 'dataType': 'float32'}
}
}
}
},
{
'name':
'resample2d(upsample) float32 4D tensor explicit options.mode=\'nearest-neighbor\'',
Expand Down Expand Up @@ -429,6 +467,80 @@ const resample2dTests = [
}
}
}
},
{
'name': 'resample2d(upsample) float32 4D tensor options.axes=[0, 1]',
'graph': {
'inputs': {
'resample2dInput': {
'data': [
59.92947006225586, 90.7006607055664, 41.98918914794922,
86.95105743408203, 66.39534759521484, 79.10005187988281
],
'descriptor': {'dimensions': [3, 2, 1, 1], 'dataType': 'float32'}
}
},
'operators': [{
'name': 'resample2d',
'arguments': [
{'input': 'resample2dInput'},
{'options': {'sizes': [6, 4], 'axes': [0, 1]}}
],
'outputs': 'resample2dOutput'
}],
'expectedOutputs': {
'resample2dOutput': {
'data': [
59.92947006225586, 59.92947006225586, 90.7006607055664,
90.7006607055664, 59.92947006225586, 59.92947006225586,
90.7006607055664, 90.7006607055664, 41.98918914794922,
41.98918914794922, 86.95105743408203, 86.95105743408203,
41.98918914794922, 41.98918914794922, 86.95105743408203,
86.95105743408203, 66.39534759521484, 66.39534759521484,
79.10005187988281, 79.10005187988281, 66.39534759521484,
66.39534759521484, 79.10005187988281, 79.10005187988281
],
'descriptor': {'dimensions': [6, 4, 1, 1], 'dataType': 'float32'}
}
}
}
},
{
'name': 'resample2d(upsample) float32 4D tensor options.axes=[1, 0]',
'graph': {
'inputs': {
'resample2dInput': {
'data': [
59.92947006225586, 90.7006607055664, 41.98918914794922,
86.95105743408203, 66.39534759521484, 79.10005187988281
],
'descriptor': {'dimensions': [3, 2, 1, 1], 'dataType': 'float32'}
}
},
'operators': [{
'name': 'resample2d',
'arguments': [
{'input': 'resample2dInput'},
{'options': {'sizes': [4, 6], 'axes': [1, 0]}}
],
'outputs': 'resample2dOutput'
}],
'expectedOutputs': {
'resample2dOutput': {
'data': [
59.92947006225586, 59.92947006225586, 90.7006607055664,
90.7006607055664, 59.92947006225586, 59.92947006225586,
90.7006607055664, 90.7006607055664, 41.98918914794922,
41.98918914794922, 86.95105743408203, 86.95105743408203,
41.98918914794922, 41.98918914794922, 86.95105743408203,
86.95105743408203, 66.39534759521484, 66.39534759521484,
79.10005187988281, 79.10005187988281, 66.39534759521484,
66.39534759521484, 79.10005187988281, 79.10005187988281
],
'descriptor': {'dimensions': [6, 4, 1, 1], 'dataType': 'float32'}
}
}
}
}
];

Expand Down
19 changes: 10 additions & 9 deletions webnn/validation_tests/resample2d.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ const tests = [
options: {scales: [2.0, 2.0], sizes: [3, 6]},
output: {dataType: 'float32', dimensions: [1, 1, 3, 6]},
},
{
name:
'[resample2d] Test building resample2d with non consecutive axes=[0,2]',
input: {dataType: 'float32', dimensions: [1, 1, 2, 4]},
options: {
axes: [0, 2],
label: label,
},
output: {dataType: 'float32', dimensions: [1, 1, 2, 4]},
},
{
name:
'[resample2d] Throw if the dataType of input is not float32 or float16',
Expand Down Expand Up @@ -177,15 +187,6 @@ const tests = [
label: label,
},
},
{
// The valid values in the axes sequence are [0, 1], [1, 2] or [2, 3]
name: '[resample2d] Throw if the values of axes are inconsecutive',
input: {dataType: 'float32', dimensions: [1, 1, 2, 4]},
options: {
axes: [0, 2],
label: label,
},
},
{
name: '[resample2d] Throw if the values of axes are same',
input: {dataType: 'float32', dimensions: [1, 1, 2, 4]},
Expand Down

0 comments on commit ff3820b

Please sign in to comment.