Skip to content

added support for Celu op #3139

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

Merged
merged 5 commits into from
Apr 30, 2025
Merged

Conversation

logeshwaranmcw
Copy link
Contributor

@logeshwaranmcw logeshwaranmcw commented Apr 24, 2025

Added support for Celu op in the ONNX to krnl and also added the test case in Elementwise_with_canonicalize.mlir and Elementwise_with_canonicalize_O3.mlir

closes #3137

Signed-off-by: logeshwaranmcw <logeshwaran.elanchelian@multicorewareinc.com>
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

Copy link
Collaborator

@tungld tungld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for quickly creating a PR for Celu! It's almost done.

Could you add backend tests for Celu which checks if we get correct answers for Celu or not? You would add the tests in this file
https://github.com/onnx/onnx-mlir/blob/main/test/backend/inference_backend.py#L73. Please refer to Selu as an example. Test names for Celu are https://github.com/onnx/onnx-mlir/blob/main/test/backend/all_test_names.txt#L231.
To run the backend test locally, you can invoke: make check-onnx-backend


template <>
GenOpMix getGenOpMix<ONNXCeluOp>(Type t, Operation *op) {
return {{GenericOps::ArithmeticGop, 1}};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should count all types of operations, which helps generate the best SIMD code. Could you take a look at operation types here and update this? Thanks!

Copy link
Contributor Author

@logeshwaranmcw logeshwaranmcw Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not noticing that earlier. I have now added all the operations @tungld .

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the added operations. I see 2 min/max {GenericOps::MinMaxGop, 2}, the add (already covered), but increase the count to reflect the -1, a mult, div, and exp: {GenericOps::DivGop, 1}, {GenericOps::MulGop, 1}, {GenericOps::ExpGop, 1}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AlexandreEichenberger, sorry I had misplaced the operation in LeakyRelu. I've just corrected it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good

Value emitScalarOpFor<ONNXCeluOp>(ConversionPatternRewriter &rewriter,
Location loc, Operation *op, Type elementType,
ArrayRef<Value> scalarOperands) {
CheckIfCustomScalarOpIsSupported<ONNXCeluOp>(elementType);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful if you put the equation for Celu here as a comment, say // celu(x) = max(0, x) + min(0, alpha * (exp(x/alpha) - 1))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the comment

@@ -2744,6 +2792,7 @@ void populateLoweringONNXElementwiseOpPattern(RewritePatternSet &patterns,
ONNXElementwiseBinaryOpLowering<mlir::ONNXPowOp>,
ONNXElementwiseUnaryOpLowering<mlir::ONNXReciprocalOp>,
ONNXElementwiseUnaryOpLowering<mlir::ONNXReluOp>,
ONNXElementwiseUnaryOpLowering<mlir::ONNXCeluOp>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list is ordered by the ONNX op name in the alphabetic order. So we should move ONNXCeluOp up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the ONNX op name

@tungld
Copy link
Collaborator

tungld commented Apr 25, 2025

@jenkins-droid test this please

Signed-off-by: logeshwaranmcw <logeshwaran.elanchelian@multicorewareinc.com>
@logeshwaranmcw
Copy link
Contributor Author

Thank you for quickly creating a PR for Celu! It's almost done.

Could you add backend tests for Celu which checks if we get correct answers for Celu or not? You would add the tests in this file https://github.com/onnx/onnx-mlir/blob/main/test/backend/inference_backend.py#L73. Please refer to Selu as an example. Test names for Celu are https://github.com/onnx/onnx-mlir/blob/main/test/backend/all_test_names.txt#L231. To run the backend test locally, you can invoke: make check-onnx-backend

Added the backend test @tungld

Copy link
Collaborator

@AlexandreEichenberger AlexandreEichenberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the cost model for the Celu, made suggestions given the comment you provided:

celu(x) = max(0, x) + min(0, alpha * (exp(x/alpha) - 1))


template <>
GenOpMix getGenOpMix<ONNXCeluOp>(Type t, Operation *op) {
return {{GenericOps::ArithmeticGop, 1}};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the added operations. I see 2 min/max {GenericOps::MinMaxGop, 2}, the add (already covered), but increase the count to reflect the -1, a mult, div, and exp: {GenericOps::DivGop, 1}, {GenericOps::MulGop, 1}, {GenericOps::ExpGop, 1}

@AlexandreEichenberger
Copy link
Collaborator

@tungld thanks for spotting the missing model for SIMD. It does not appear to have been updated, I provided a detailed comment on how to update the model. I will keep track of that.

Once that is done, do you want to go over PR again and approve it if all your other requests have been satisfied?

Signed-off-by: logeshwaranmcw <logeshwaran.elanchelian@multicorewareinc.com>
Copy link
Collaborator

@tungld tungld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the update!

Copy link
Collaborator

@AlexandreEichenberger AlexandreEichenberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the update, much appreciated

@AlexandreEichenberger
Copy link
Collaborator

Will merge once it passes the CIs @logeshwaranmcw, please respond if not ok with you.

@AlexandreEichenberger AlexandreEichenberger merged commit 7a7beda into onnx:main Apr 30, 2025
7 checks passed
@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #16611 [push] added support for Celu o... started at 15:37

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #16613 [push] added support for Celu o... started at 16:37

@jenkins-droid
Copy link
Collaborator

Jenkins Linux ppc64le Build #15556 [push] added support for Celu o... started at 16:37

@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #16611 [push] added support for Celu o... passed after 1 hr 23 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #16613 [push] added support for Celu o... passed after 1 hr 25 min

@logeshwaranmcw
Copy link
Contributor Author

Will merge once it passes the CIs @logeshwaranmcw, please respond if not ok with you.

It's completely fine, @AlexandreEichenberger. Thank you both, @AlexandreEichenberger and @tungld, for the review comments

@AlexandreEichenberger
Copy link
Collaborator

Thanks for contributing, looking forward to many more :-)

tungld pushed a commit to brnorris03/onnx-mlir that referenced this pull request May 9, 2025
Signed-off-by: logeshwaranmcw <logeshwaran.elanchelian@multicorewareinc.com>
Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
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.

Conversion of CeLU Op from Krnl to MLIR Dialect
4 participants