Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

justin-ngo-arm
Copy link
Contributor

  • 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

Change-Id: I7b1d44d94319cf94fcc9d234cc07708ef9ce321e

- 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
@sjarus sjarus requested a review from sahas3 November 21, 2024 19:15
// "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,
Copy link
Contributor

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");
Copy link
Contributor

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;
Copy link
Contributor

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) {
Copy link
Contributor

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(
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants