You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
🐛 [Bug] torch.ops.aten.remainder.Scalar seems not working with big int #3230
bugSomething isn't workingstory: Operator Coverage & ConvertersMissing ATen op converters, converter accuracy bugs, type-casting issues, and new operator support r
torch.ops.aten.remainder.Scalar seems to return fmod result when input number is big
To Reproduce
save it and run the script below
import torch
import torch.nn as nn
a = torch.tensor([[5950571286963681280]]).cuda()
example_args = (a,)
class ToyModel(nn.Module):
def __init__(self):
super(ToyModel, self).__init__()
def forward(self, x):
return torch.remainder(x, 196613)
model = ToyModel().eval().cuda()
with torch.no_grad():
ep = torch.export.export(model, args=example_args)
from torch_tensorrt.dynamo._compiler import compile as dynamo_compile
from torch_tensorrt import logging as ts_logging
with ts_logging.debug():
compiled = dynamo_compile(
exported_program=ep,
disable_tf32=True,
inputs=example_args,
min_block_size=1,
debug=True,
)
with torch.no_grad():
print(compiled(*example_args))
Thanks for pointing this out.
I looked into this a bit.
TRT does not support fmod operation directly. So in torchTRT we implement it as fmod(fmod(dividend, divisor) + divisor)
and fmod in turn is sub(dividend, prod(trunc_div(dividend, divisor), divisor))
Generally dividend > prod(trunc_div(dividend, divisor), divisor)
But in large integers trunc_div(dividend, divisor) in this case results in 30265401409536 (should be 30,265,401,000,766) which results in prod(trunc_div(dividend, divisor), divisor) > dividend and results in the negative number.
As you said, 5950571286963681280 falls in the signed int64 range, so I am not sure why TRT is returning reduced precision. I can get it clarified more from TRT team. It must be loss of accuracy in computation. Please note that float32 would also lead in accuracy loss.
Thanks @apbose for your help. I have tried to export this graph to onnx and compile it with trtexec, it seems the same issue. The result I get by this way is -80369420288,
I have attached my exported onnx in this scalar.zip
What is the suggested way to deal with these big numbers, do you have any suggestions?
bugSomething isn't workingstory: Operator Coverage & ConvertersMissing ATen op converters, converter accuracy bugs, type-casting issues, and new operator support r
Activity
sean-xiang-applovin commentedon Oct 12, 2024
BTW,
torch.ops.aten.remainder.Scalarseems not even as fast as original ops.torch.ops.aten.remainder.Scalarworks with int that is not that big. Not sure if this is caused by int64apbose commentedon Oct 22, 2024
Thanks for pointing this out.
I looked into this a bit.
TRT does not support fmod operation directly. So in torchTRT we implement it as
fmod(fmod(dividend, divisor) + divisor)and fmod in turn is
sub(dividend, prod(trunc_div(dividend, divisor), divisor))Generally dividend > prod(trunc_div(dividend, divisor), divisor)
But in large integers
trunc_div(dividend, divisor)in this case results in 30265401409536 (should be 30,265,401,000,766) which results inprod(trunc_div(dividend, divisor), divisor) > dividendand results in the negative number.As you said, 5950571286963681280 falls in the signed int64 range, so I am not sure why TRT is returning reduced precision. I can get it clarified more from TRT team. It must be loss of accuracy in computation. Please note that float32 would also lead in accuracy loss.
sean-xiang-applovin commentedon Oct 24, 2024
Thanks @apbose for your help. I have tried to export this graph to onnx and compile it with trtexec, it seems the same issue. The result I get by this way is
-80369420288,I have attached my exported onnx in this scalar.zip
What is the suggested way to deal with these big numbers, do you have any suggestions?