-
Notifications
You must be signed in to change notification settings - Fork 49
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
Introduce "valid dimension", used as needed when calculating operand shapes #641
Introduce "valid dimension", used as needed when calculating operand shapes #641
Conversation
If explicit sizes aren't provided, the size of an output dimension is calculated as shape[i] * scales[i] which could be larger than can be represented as a dimension in MLOperandDescriptor. Explicitly validate and throw if this constraint isn't satisfied. Fixes webmachinelearning#610
Up for discussion. A few more thoughts here:
(dropping "greater than zero" depending on #391) ... and then change check dimensions to say:
Thoughts? |
If we introduce a "valid dimension" definition, we probably want to use it in these other places that calculate a dimension: ... which are the obvious places where a dimension is assigned from a calculation. Probably more places. |
Ah yes, it's a sum of other dimensions, so could overflow. I think those are cases where the intermediate value could overflow if the math is done in uint32 space, but the final values used for dimensions are always valid uint32, since they come directly from other MLOperands. So those are cases where #636 applies. I'm gonna update this PR to introduce the "valid dimension" term (done in e737dcb). Should I go ahead and expand it beyond resample2d() or do that in another PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks @inexorabletash !
Given "valid dimension" is defined, having all its usages in this PR sounds good to me. But I am also fine if doing it in another PR. |
Done in 4f30583 - I'll update the PR name / description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a nit
Co-authored-by: Ningxin Hu <[email protected]>
@fdwr - can you please review and merge if it looks good to you? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny wording thought (do you prefer one over the other? I'll go with whatever you like.), else LGTM. Thanks, as I like centralizing this dimension validity rather than it being scattered around.
Co-authored-by: Dwayne Robinson <[email protected]>
Suggested wording change was great @fdwr - it felt awkward as I was writing it. |
Certain operands like reshape2d() calculate dimensions in their output shape with expressions like shape[i] * scales[i] which could be larger than can be represented as a dimension in MLOperandDescriptor.
Introduce a "valid dimension" term, use it when calculating output dimensions in the following ops, and throw if needed.
Fixes #610
Preview | Diff