Skip to content

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

Merged
echuraev merged 4 commits intoapache:mainfrom
jikechao:fix_celu
May 8, 2023
Merged

[bugfix][relay] fix wrong calculate logic about celu#14796
echuraev merged 4 commits intoapache:mainfrom
jikechao:fix_celu

Conversation

@jikechao
Copy link
Copy Markdown
Member

@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
Copy Markdown
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

@github-actions github-actions Bot requested review from AndrewZhaoLuo and echuraev May 7, 2023 15:29
Copy link
Copy Markdown
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