Skip to content

Conversation

@BruceDai
Copy link
Contributor

@BruceDai BruceDai commented May 9, 2025

This pr is to align with latest WebNN API Spec change for Restrict padding options to better match backend limits.

@fdwr @huningxin PTAL, thanks!

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.

👍

Comment on lines +837 to +839
if (inputRank === 0) {
throw new Error(`The input's rank should be greater than 0.`);
}
Copy link

@fdwr fdwr May 13, 2025

Choose a reason for hiding this comment

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

Looking at the spec, pad currently has this odd outlier in the algorithm steps "If input’s rank is 0, then throw a TypeError", but I don't see any other operator with that explicitly, and also, the table for pad says that any rank is allowed...

operand allowed data types allowed ranks
input any N
output same as input same as input

...which is inconsistent. Logically, pad should be able to accept a scalar, as the beginningPadding.length (==0) and endingPadding.length (==0) will still equal rank (==0), and it's simply a nop, but I don't know if the spec should support 0D, because I fear that many backends will not (ORT with the DML EP works fine with this case, but then ORT's CPU EP breaks, and CoreML/TF probably will too).

Anyway, resolve this, as the code is consistent with the current spec.

@huningxin huningxin merged commit 360ee24 into webmachinelearning:main Jun 24, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants