Fix unidirectionally broadcast the shapes steps#663
Fix unidirectionally broadcast the shapes steps#663fdwr merged 3 commits intowebmachinelearning:mainfrom
Conversation
|
The current definition is correct given the interpretation of the first/input tensor (A) being broadcasted to the second/target tensor (B), and the text elsewhere in the spec matches that interpretation. So for So if we're going to flip the interpretation, then we'd need to adjust the wording in two places too: - Set outputDescriptor.dimensions to the result of unidirectionally broadcasting the shapes input’s shape and newShape.
+ Set outputDescriptor.dimensions to the result of unidirectionally broadcasting the shapes newShape and input’s shape.
...
- Set descriptor.dimensions to the result of unidirectionally broadcasting the shapes slope’s shape and input’s shape.
+ Set descriptor.dimensions to the result of unidirectionally broadcasting the shapes input’s shape and slope’s shape.I see for ONNX, rather than the parameter order of (input -> output) or (original shape -> target shape), it lists parameters as (target shape <- original shape), which feels oddly backwards to me, but I can accept that (technically both definitions are functionally equivalent, just a different parameter order). The bigger point of confusion is that |
We also need to change another caller "unidirectionally broadcastable": -shapeA is unidirectionally broadcastable to shapeB if [unidirectionally broadcasting the shapes](https://www.w3.org/TR/webnn/#unidirectionally-broadcasting-the-shapes) shapeA and shapeB does not result in failure.
+shapeA is unidirectionally broadcastable to shapeB if [unidirectionally broadcasting the shapes](https://www.w3.org/TR/webnn/#unidirectionally-broadcasting-the-shapes) shapeB and shapeA does not result in failure.And we need to flip one internal step of "unidirectionally broadcast the shapes": -If dimA is not equal to dimB and dimA is not equal to 1, then return failure.
+If dimB is not equal to dimA and dimB is not equal to 1, then return failure. |
+1. I suppose this ambiguity comes from the readers cannot easily tell the broadcasting direction. How about using |
7f2c783 tries to use |
index.bs
Outdated
| 1. [=list/For each=] |index| in [=the range=] 0 to |sizeB|, exclusive: | ||
| 1. Let |dimA| be |paddedA|[|index|]. | ||
| 1. Let |dimB| be |shapeB|[|index|]. | ||
| 1. If |dimA| is not equal to |dimB| and |dimA| is not equal to 1, then return failure. |
There was a problem hiding this comment.
I want to defer to @fdwr but call out:
If the claim "The current definition is correct given the interpretation of ..." is correct, and this change is turning into a strict (1) reorder and (2) rename of the params, then it seems like this line needs to be altered to maintain the current behavior.
Also, @fdwr's note about updating the "call sites" needs to happen as well?
|
Can we move forward here? I'd recommend starting from a fresh change (force-push) that just renames the parameters from |
7f2c783 to
9bc36ba
Compare
9bc36ba is a force-push, just renames the parameters from "A" to "To", "B" to "From". I'd like to point out if we just rename the following line, it is incorrect: - If |dimA| is not equal to |dimB| and |dimA| is not equal to 1, then return failure.
+ If |dimTo| is not equal to |dimFrom| and |dimTo| is not equal to 1, then return failure.because we should check whether - If |dimA| is not equal to |dimB| and |dimA| is not equal to 1, then return failure.
+ If |dimTo| is not equal to |dimFrom| and |dimFrom| is not equal to 1, then return failure.The following commit c565f4a updates the call sites according to the change. PTAL. |
I also feel backwards. a3976ae reverses the order of the two parameters. That actually becomes the same as my previous proposal: #663 (comment). |
inexorabletash
left a comment
There was a problem hiding this comment.
Thanks for walking through this patiently. LGTM!
SHA: 4eda710 Reason: push, by fdwr Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Fix #662
Preview | Diff