Introduce "valid dimension", used as needed when calculating operand shapes#641
Introduce "valid dimension", used as needed when calculating operand shapes#641fdwr merged 5 commits intowebmachinelearning:mainfrom inexorabletash:bugfix-resample2d-numeric-limit
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 #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? |
|
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 |
Co-authored-by: Ningxin Hu <[email protected]>
|
@fdwr - can you please review and merge if it looks good to you? Thanks! |
fdwr
left a comment
There was a problem hiding this comment.
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