Skip to content

Commit

Permalink
webnn: Remove some activations not usable with recurrent ops
Browse files Browse the repository at this point in the history
clamp() and softmax() may no longer be created as MLActivations

More details on the spec PR:
webmachinelearning/webnn#703

Bug: 341518634
Change-Id: I7dda713c8be5454690f21c66665d90be274513f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5598089
Commit-Queue: Austin Sullivan <[email protected]>
Reviewed-by: Alex Gough <[email protected]>
Reviewed-by: ningxin hu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1313205}
  • Loading branch information
a-sully authored and chromium-wpt-export-bot committed Jun 11, 2024
1 parent 55e4664 commit a4597eb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 27 deletions.
20 changes: 1 addition & 19 deletions webnn/validation_tests/clamp.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

validateInputFromAnotherBuilder('clamp');

validateUnaryOperation(
'clamp', allWebNNOperandDataTypes, /*alsoBuildActivation=*/ true);
validateUnaryOperation('clamp', allWebNNOperandDataTypes);

promise_test(async t => {
const options = {minValue: 1.0, maxValue: 3.0};
Expand All @@ -27,11 +26,6 @@ promise_test(async t => {
assert_array_equals(output.shape(), [1, 2, 3, 4]);
}, '[clamp] Test building an operator with options.minValue == options.maxValue');

promise_test(async t => {
const options = {minValue: 2.0};
builder.clamp(options);
}, '[clamp] Test building an activation with options');

promise_test(async t => {
const options = {minValue: 3.0, maxValue: 1.0};
const input =
Expand All @@ -46,15 +40,3 @@ promise_test(async t => {
const input = builder.input('input', {dataType: 'float16', dimensions: []});
assert_throws_js(TypeError, () => builder.clamp(input, options));
}, '[clamp] Throw if options.minValue is -Infinity when building an operator');

promise_test(async t => {
const options = {minValue: 2.0, maxValue: -1.0};
assert_throws_js(TypeError, () => builder.clamp(options));
}, '[clamp] Throw if options.minValue > options.maxValue when building an activation');

// To be removed once NaN `maxValue` is allowed. Tracked in
// https://github.com/webmachinelearning/webnn/pull/647.
promise_test(async t => {
const options = {maxValue: NaN};
assert_throws_js(TypeError, () => builder.clamp(options));
}, '[clamp] Throw if options.maxValue is NaN when building an activation');
4 changes: 2 additions & 2 deletions webnn/validation_tests/gru.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ multi_builder_test(async (t, builder, otherBuilder) => {
}, '[gru] throw if initialHiddenState option is from another builder');

multi_builder_test(async (t, builder, otherBuilder) => {
const activation = builder.clamp();
const activationFromOtherBuilder = otherBuilder.clamp();
const activation = builder.relu();
const activationFromOtherBuilder = otherBuilder.relu();
const options = {activations: [activation, activationFromOtherBuilder]};

const input = builder.input('input', kExampleInputDescriptor);
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/gruCell.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ multi_builder_test(async (t, builder, otherBuilder) => {
}, '[gruCell] throw if recurrentBias option is from another builder');

multi_builder_test(async (t, builder, otherBuilder) => {
const activation = builder.clamp();
const activationFromOtherBuilder = otherBuilder.clamp();
const activation = builder.relu();
const activationFromOtherBuilder = otherBuilder.relu();
const options = {activations: [activation, activationFromOtherBuilder]};

const input = builder.input('input', kExampleInputDescriptor);
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/lstm.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ multi_builder_test(async (t, builder, otherBuilder) => {
}, '[lstm] throw if initialCellState option is from another builder');

multi_builder_test(async (t, builder, otherBuilder) => {
const activation = builder.clamp();
const activationFromOtherBuilder = otherBuilder.clamp();
const activation = builder.relu();
const activationFromOtherBuilder = otherBuilder.relu();
const options = {activations: [activation, activationFromOtherBuilder]};

const input = builder.input('input', kExampleInputDescriptor);
Expand Down
4 changes: 2 additions & 2 deletions webnn/validation_tests/lstmCell.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ multi_builder_test(async (t, builder, otherBuilder) => {
}, '[lstmCell] throw if peepholeWeight option is from another builder');

multi_builder_test(async (t, builder, otherBuilder) => {
const activation = builder.clamp();
const activationFromOtherBuilder = otherBuilder.clamp();
const activation = builder.relu();
const activationFromOtherBuilder = otherBuilder.relu();
const options = {activations: [activation, activationFromOtherBuilder]};

const input = builder.input('input', kExampleInputDescriptor);
Expand Down

0 comments on commit a4597eb

Please sign in to comment.