-
Notifications
You must be signed in to change notification settings - Fork 46
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
Remove builder.constant(value, type)
variant
#475
Comments
sgtm :) |
I don't oppose it. Are there any impacts besides just our hello world sample? Having the constant scalar overload is convenient for JS callers, but if we don't expect ordinary JS users to call WebNN directly anyway, instead expecting calls from existing tensor definitions in libraries, then it doesn't matter much. There is no perf benefit to it either, because under the hood, that single constant becomes a buffer anyway. 🔎 One data point is that I just scanned my own SimpleWebNN.html test file (~3000 lines long), and I found 0 occurrences of the
So, I guess the biggest impact of this change codewise would be our hello world samples :b. Btw, I never noticed these two overloads have swapped parameters, with the value/type in different orders 🙃:
I suppose the reasoning was that for the first, you could just specify the constant and default the type to |
builder.constant(value, dataType)
variantbuilder.constant(value, type)
variant
Given discussions in #492 about rethinking constant() overloads in general... how are people feeling about this issue? Proceed with removal? Retain but change the signature? Other? I note that many of the decompositions given in the spec use this, e.g. -return builder.max(builder.constant(0), x);
+return builder.max(builder.constant(x.dataType, 0), x); ... but it gets uglier if the overload is removed entirely. |
I'm warming to keeping the scalar constant overload for convenience and to benefit for decompositions in the spec, but passing the parameters in the order The |
Make MLGraphBuilder's constant() operand-vending methods consistent and take the data type as the first parameter. This implicitly makes the type required instead of optional. Use of constant() in decompositions are updated as well, and now use "input" consistently instead of "x" sometimes. Fixes webmachinelearning#475
* Swap parameters of scalar constant() operand method Make MLGraphBuilder's constant() operand-vending methods consistent and take the data type as the first parameter. This implicitly makes the type required instead of optional. Use of constant() in decompositions are updated as well, and now use "input" consistently instead of "x" sometimes. Fixes #475 * fix typo - thanks @zolkis * Update explainer
In the current spec,
MLGraphBuilder.constant(value, type)
allows to build a scalar from the specified number, e.g.,However,
MLGraphBuilder.constant(descriptor, bufferView)
also allows to build a scalar from data buffer, like the example in #390The proposal is to drop the scalar-specific
MLGraphBuilder.constant(value, type)
method and only keep more genericMLGraphBuilder.constant(descriptor, bufferView)
method.The scalar-specific build method can be polyfilled by user code. This would help reduce the browser implementation complexity.
/cc @wchao1115 @fdwr @wacky6 @BruceDai @Honry
(Edit by @anssiko: fix link and naming to account for name changes dataType -> type and buffer -> bufferView)
The text was updated successfully, but these errors were encountered: