kavin-sai-krishna opened a new issue, #17881:
URL: https://github.com/apache/tvm/issues/17881
### Expected behavior
TVM should match PyTorch's behavior for the `%` (mod) operation.
For example:
```python
>>> torch.tensor([5.3, -5.3]) % torch.tensor([-2.0])
tensor([-0.7000, -1.3000])
```
TVM's result should be `[-0.7, -1.3]` to match PyTorch.
---
### Actual behavior
TVM output differs from PyTorch:
```
Mismatched elements: 1 / 2 (50%)
Max absolute difference among violations: 2.
Max relative difference among violations: 2.8571436
ACTUAL: array([ 1.3, -1.3], dtype=float32)
DESIRED: array([-0.7, -1.3], dtype=float32)
```
TVM returns `1.3` for the first value instead of `-0.7`.
---
### Steps to reproduce
#### `fmod_exported.py`
```python
class FModModule(nn.Module):
def forward(self, x, y):
return x % y
model = FModModule()
example_args = (torch.tensor([-7.2,8.5]), torch.tensor([2.2]))
exported_program = export(model, example_args)
mod = from_exported_program(exported_program, keep_params_as_input=True)
mod, params = frontend.detach_params(mod)
mod = tvm.relax.transform.LegalizeOps()(mod)
input1 = torch.tensor([5.3, -5.3])
input2 = torch.tensor([-2.0])
torch_output = model(input1.clone(), input2.clone())
exec = tvm.compile(mod, target="llvm")
vm = tvm.relax.VirtualMachine(exec, tvm.cpu())
tvm_output = vm["main"](tvm.nd.array(input1), tvm.nd.array(input2))
assert tvm.testing.assert_allclose(tvm_output[0].numpy(),
torch_output.numpy())
```
#### `fmod_fx.py`
```python
class FModModule(nn.Module):
def forward(self, x, y):
return x % y
model = FModModule()
input1 = torch.tensor([5.3, -5.3])
input2 = torch.tensor([-2.0])
torch_output = model(input1.clone(), input2.clone())
fx_graph = torch.fx.symbolic_trace(model)
irmod = from_fx(fx_graph, [(input1.shape, torch.float32), ((1,),
torch.float32)])
mod = tvm.relax.transform.LegalizeOps()(irmod)
exec = tvm.compile(mod, target="llvm")
vm = tvm.relax.VirtualMachine(exec, tvm.cpu())
tvm_output = vm["main"](tvm.nd.array(input1), tvm.nd.array(input2))
tvm.testing.assert_allclose(tvm_output.numpy(), torch_output)
```
---
### Triage
* needs-triage
* bug
* operator
Let me know if you want me to create this as a Markdown file or assist in
posting it on GitHub.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]