-
Notifications
You must be signed in to change notification settings - Fork 520
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
fix(ONNX): avoids resizing unsupported dimensions #3945
base: main
Are you sure you want to change the base?
fix(ONNX): avoids resizing unsupported dimensions #3945
Conversation
6baa8d5
to
ab7e021
Compare
ab7e021
to
7aec80b
Compare
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.
I think the main structural question is about the need for adding the BaseTensorType
method. If it were useful elsewhere (I have some doubts, since we would need to know too much about the two tensor shapes prior to using it- namely that they are present, and they have the same rank), I would consider keeping it; however, the code is simplified here by not using it, and I suspect that the same would be true in other circumstances where it might be used.
7aec80b
to
a20ee29
Compare
a20ee29
to
574f4fe
Compare
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.
Sorry for the misdirect earlier, we need to perform the runtime asserts on the scales or sizes values instead of sizes, since we will not have access to the correct output sizes ahead of time.
int64_t const batchDimension = 0; | ||
int64_t const channelDimension = 1; | ||
int64_t nonScalableDimensions[] = { | ||
batchDimension, | ||
channelDimension, | ||
}; | ||
|
||
auto errorMessageForScaling = [](int64_t givenDimension) { | ||
switch (givenDimension) { | ||
case batchDimension: | ||
return "Unexpected intent to scale the batch dimension"; | ||
case channelDimension: | ||
return "Unexpected intent to scale the channel dimension"; | ||
default: | ||
return "Scalable dimension treated as non-scalable"; | ||
} | ||
}; | ||
|
||
auto unknownSize = Torch::kUnknownSize; | ||
|
||
// Compile-time check for dimensions of static size | ||
for (auto eachDimension : nonScalableDimensions) { |
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.
This is a personal preference, but I would certainly prefer:
int64_t const batchDimension = 0; | |
int64_t const channelDimension = 1; | |
int64_t nonScalableDimensions[] = { | |
batchDimension, | |
channelDimension, | |
}; | |
auto errorMessageForScaling = [](int64_t givenDimension) { | |
switch (givenDimension) { | |
case batchDimension: | |
return "Unexpected intent to scale the batch dimension"; | |
case channelDimension: | |
return "Unexpected intent to scale the channel dimension"; | |
default: | |
return "Scalable dimension treated as non-scalable"; | |
} | |
}; | |
auto unknownSize = Torch::kUnknownSize; | |
// Compile-time check for dimensions of static size | |
for (auto eachDimension : nonScalableDimensions) { | |
// Compile-time check for dimensions of static size | |
for (int64_t i = 0; i<2; i++) { |
This is for two reasons:
- Although the torch op might have these specific dimension specifications, the ONNX op does not. We should say something a bit more generic like "unsupported: non-trivial scaling in the first two dimensions.".
- We might want to implement support for this path instead of writing a match failure in the future. With all of the variables and structures introduced here, I think this would cause more work for the future developer.
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.
And personal preferences are worth sharing! They're heuristics for our engineering experiences, and they're worth putting out there because:
- they could help someone solve a problem that they've encountered in their own experience
- it's an opportunity to evaluate a preference, put them to words, recalibrate them, or maybe even drop them altogether when presented with new information.
- Gotcha, so we want the error message to not reveal the rational. In that case, I'll have the message report the dimension index instead. Also gives us a chance to differentiate the messages between compile-time and run-time check.
- I agree that it's work! In the case of adding support, work is unavoidable:
- the work of deleting 3 variable declarations that contain cognitive load
OR - the work of gathering the required cognitive load by
- talking to other engineers
- researching within the codebase
- reading external docs
- etc.
OR
- some other unforeseen work!
- the work of deleting 3 variable declarations that contain cognitive load
Predicted questions by future devs (especially if they're also cross-discipline):
We do 2 loops, so what's significant about the first two dimensions?
- pings engineer again
Okay, so they shouldn't be scaled, but why? What do they represent?
- pings engineer yet again
Okay, they're the batch and channels dims, but how's that different from the other dims?
- pings engineer one more time
Oh, their elements have nothing to do spatial dimensions, got it!
With the dims explicitly declared and the implementation based on them, another engineer might be able to avoid having to recollect the CL we had already collected once before.
binder.op, errorMessageForScaling(eachDimension)); | ||
} | ||
|
||
auto binderLocation = binder.getLoc(); |
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.
please use loc
. This is actually the original op's location (and not the binder), and loc
is a fairly canonical variable name for the location of the op being rewritten.
574f4fe
to
cb371ea
Compare
I think the renaming of |
05ea165
to
cb20894
Compare
14233f1
to
6e5ca41
Compare
- before, some of assignments were explicitly `Location` while the rest were `auto` - Intellisense was able to infer `mlir::Location`, meaning `auto` is sufficient
1. `loc`: when searching "loc" across the codebase, this appears in contexts where it could mean "location", "locale", etc. Avoiding abbreviations reduces this ambiguity. 2. `location`: Now the question to answer is "The location of what, exactly?" without having to ping a colleague or scrub the codebase. We see `auto location = binder.getLoc()`, so the (incorrect) inference is "ah the location of the binder, I guess", so we use that to modify the word "location" 3. `binderLocation`: Turns out that "binder" is short for "opBinder", meaning this is actually "location of _op_". So, we switch the "modifying noun" 4. `opLocation`: bakes in the understanding that probably required preceding engineers (like me) to spend theirs and others time clarifying. Adding 7 characters to "loc" avoids time to grok, avoids unnecessary roping in of other engineers, and makes it easier to onboard other engineers. Overall, this is easier to build upon from an organizational standpoint. This particular name did not exist in the codebase prior to this commit, so reverting this change is trivially easy no matter how far back in time in was added!
- avoids SSA before match failures
- cast to `ValueTensorType` was overly specific for the methods used
6e5ca41
to
8a78147
Compare
… in transforms filter
…ransforms filter - helper isn't concerned with the role of the transformations at the call site, only its interpretation
- avoids single-letter naming
…or` in onnx.resize
…nsformationVector` in onnx.resize
8a78147
to
54cf76e
Compare
Okay, @zjgarvey, I think we're in business! Got green on the CI a few hours ago. Just wrapped up self-review. I'm guessing now we'll:
I kept the commits atomic and ordered such that it's easier to propagate changes to the head of the branch in case an earlier commit needs to be inserted/tweaked/excised. Let me know what you think! |
Nice! At least for now, please exclude any commits which involve style changes not directly related to the fix content. E.g. widespread enforcement of naming preferences like the |
No description provided.