Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webnn] Add tests for WebNN API constant (fillSequence) #43801

Merged
merged 4 commits into from
Feb 18, 2024

Conversation

BruceDai
Copy link
Contributor

@BruceDai BruceDai commented Dec 27, 2023

Current this pr doesn't include tests of uint64 type which will be added later.
@fdwr @Honry PTAL, thanks!

@@ -291,6 +291,7 @@ const PrecisionMetrics = {
batchNormalization: {ULP: {float32: 6, float16: 6}},
clamp: {ULP: {float32: 0, float16: 0}},
concat: {ULP: {float32: 0, float16: 0}},
constant: {ULP: {float32: 2, float16: 2, int32: 0, uint32: 0, int64: 0, int8: 0, uint8: 0}},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting case because there are two constant overloads, with one that should be always exact (the one taking the Float32Array), but the other with start and step could have a ULP delta of 2.

Technically the integers could be off by 1 too for large values too (above 16777216) since the constant overload only accepts float start and step values, but none of our test cases go near that high. So in the general case, 0 ULP is valid for integers, and that's fine.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(feel free to resolve this comment)

Copy link

@fdwr fdwr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add some negative values for int8 as a sanity check.
Might consider if we should have different ULP's for overloads of the same operator name. Unsure how to achieve that though 🤔.
Otherwise LGTM.

@BruceDai
Copy link
Contributor Author

@fdwr Thanks for your reviewing!
I've updated test data, please take another look, thanks.

@@ -616,7 +616,7 @@
"name": "constant float32 4D tensor of int8 type",
"inputs": {
"start": {
"data": 0.22992068529129028,
"data": -5.520709991455078,
"type": "float32"
Copy link

@fdwr fdwr Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, this isn't supported, mixing and matching different data types like float32 and int8. If the output is an integer tensor, then the start and delta must be integers too. It would be legal to pass start of -5 and delta of 1 though. Otherwise DirectML will complain (fail API validation) that the DML_FILL_VALUE_SEQUENCE_OPERATOR_DESC::ValueDataType does not match the outputTensorDesc->Type.

Bin Miao (https://chromium-review.googlesource.com/c/chromium/src/+/5091540) is currently working on a way via the IDL to express both float64 and int64 in the API.

Also by mixing types, you'll get weird artifacts like this repeated 0 x 3 in the output data:

          -2,
          -1,
          0, // <-----
          0, // <-----
          0, // <-----
          1,
          2,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we need use integer numbers for such cases, though Spec define start and step as float, or does it need update this Spec?

start: a [float](https://webidl.spec.whatwg.org/#idl-float) scalar. The starting value of the range.

step: a [float](https://webidl.spec.whatwg.org/#idl-float) scalar. The gap value between two data points in the range.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should update the spec with additional wording. Even if you pass it as a float/double, internally it will be casted to an integer before any calculations are done with it. So then the baseline should cast any floating-point values (start and delta values) to integers (or BigInt) before computing.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, for the integer cases, can we just pass integer start and delta values?
"data": -5.520709991455078, -> "data": -5,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll update test data for those integer cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please have another look, thanks.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One case with a negative step for the integers would be good, but LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. Please take another look, thanks.

@@ -616,7 +616,7 @@
"name": "constant float32 4D tensor of int8 type",
"inputs": {
"start": {
"data": 0.22992068529129028,
"data": -5.520709991455078,
"type": "float32"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One case with a negative step for the integers would be good, but LGTM.

Copy link

@fdwr fdwr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Bruce.

@anssiko
Copy link
Member

anssiko commented Feb 5, 2024

@Honry PTAL similarly to #43794, we'd like to get this test reviewed and merged prior to our next big spec release.

Copy link
Contributor

@Honry Honry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@Honry Honry merged commit 155f94a into web-platform-tests:master Feb 18, 2024
18 of 19 checks passed
marcoscaceres pushed a commit that referenced this pull request Feb 23, 2024
* [webnn] Add tests for WebNN API constant (fillSequence)

* [webnn] Update test data with negative start

* [webnn] Update test data for integer test cases

* [webnn] Add a test with negative integer step
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants