-
Notifications
You must be signed in to change notification settings - Fork 508
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
[TOSA] Add upsample_nearest2d, split_dim, outer, GELU tanh mode and misc #3886
base: main
Are you sure you want to change the base?
Conversation
- Add Torch to TOSA lowering for the following ops: + torch.aten.upsample_nearest2d + torch.aten.upsample_nearest2d.vec + torch.aten.outer + torch.prims.split_dim - Add Tanh approximation mode for GELU lowering - Add different types support for compare ops - Add different input and output types support for linalg vector norm lowering - Update xfail with new e2e results - Add new LIT tests to basic.mlir Signed-off-by: Justin Ngo <[email protected]> Change-Id: I7b1d44d94319cf94fcc9d234cc07708ef9ce321e
// "tanh" approximate | ||
// GELU(x) = 0.5 * x * (1 + Tanh(sqrt(2/pi) * (x + 0.044715 * x^3)) | ||
auto selfShape = selfType.getShape(); | ||
auto numElem = std::accumulate(selfShape.begin(), selfShape.end(), 1, |
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 assumes the shape is all static right? Can you add a failure check for dynamic shape?
Alternatively, can't we rely on broadcasting semantics of TosaOps to correctly expand the shape even for dynamic dims if these constants are defined with size 1?
if ((isOutputSizeNone && isScaleFactorsNone) || | ||
(!isOutputSizeNone && !isScaleFactorsNone)) | ||
return rewriter.notifyMatchFailure( | ||
op, "Must specified exactly one of output size and scale factors"); |
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.
typo: specified -> specify
self, rewriter.getDenseI64ArrayAttr(reshapedSelfShape)); | ||
|
||
// Calculate PyTorch-styled gather indices | ||
SmallVector<int32_t> targetIndicesVec; |
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.
Should this be int64_t as well since all the other types are int64_t?
static_cast<double>(outputWidth) / static_cast<double>(selfWidth); | ||
} | ||
|
||
if (isOutputSizeNone) { |
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.
#nit: can be merged with the previous if block since isOutputSizeNone
implies !isScaleFactorsNone
|
||
// ----- | ||
|
||
// CHECK-LABEL: func.func @torch.aten.outer$basic( |
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.
Can you also add a LIT test for tanh
approximation for Gelu
?
Change-Id: I7b1d44d94319cf94fcc9d234cc07708ef9ce321e