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

[bugfix][relay] fix wrong calculate logic about celu #14796

Merged
merged 4 commits into from
May 8, 2023

Conversation

jikechao
Copy link
Contributor

@jikechao jikechao commented May 7, 2023

The calculation formula of CELU is wrong in relay/pytorch. This pr fix it.

From the pytorch documentation, we can get the calculating logic of CELU.
image

Reproducible Script

import torch
from tvm import relay
import tvm
import numpy as np

m = torch.nn.CELU()
input_data = torch.tensor([[-1.0, 2.0]], dtype=torch.float32)

torch_outputs = m(input_data)

trace = torch.jit.trace(m, input_data)
input_shapes = [('input0', torch.Size([1,2]))]

mod, params = relay.frontend.from_pytorch(trace, input_shapes)

with tvm.transform.PassContext(opt_level=3):
    exe = relay.create_executor('graph', mod=mod, params=params, device=tvm.device('llvm', 0), target='llvm').evaluate()
input_tvm = {'input0': np.array([[-1.,  2.]], dtype='float32')}
tvm_outputs = exe(**input_tvm).asnumpy()

np.testing.assert_allclose(torch_outputs, tvm_outputs, rtol=1e-3, atol=1e-3)

script output

image

cc @AndrewZhaoLuo @echuraev

@tvm-bot
Copy link
Collaborator

tvm-bot commented May 7, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

Copy link
Contributor

@echuraev echuraev left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for your PR!

@echuraev echuraev merged commit e01cb47 into apache:main May 8, 2023
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.

4 participants