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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric overflow in JIT #49336

Closed
datumbox opened this issue Dec 14, 2020 · 1 comment
Closed

Numeric overflow in JIT #49336

datumbox opened this issue Dec 14, 2020 · 1 comment
Labels
oncall: jit Add this issue/PR to JIT oncall triage queue
Projects

Comments

@datumbox
Copy link
Contributor

datumbox commented Dec 14, 2020

馃悰 Bug

To Reproduce

The following snippet causes numeric overflow in JIT if x is uint8:

def invert(x):
    bound = 255.0
    return bound - x # Overflow happens here due to -x when uint8

x=torch.randint(0, 256, (10, 10), dtype=torch.uint8)

script_invert = torch.jit.script(invert)
invert(x).equal(script_invert(x)) # False

We can avoid it if we define the invert differently:

def invert2(x):
    bound = 255.0
    return -(x - bound) # Avoids underflow because x is casted to float before negated


script_invert2 = torch.jit.script(invert2)
invert2(x).equal(script_invert2(x)) # True

Expected behavior

The two implementations should yield equivalent results. The invert() should return the same result either it's scripted or not.

cc @gmagogsfm

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Dec 14, 2020
@github-actions github-actions bot added this to Need triage in JIT Triage Dec 14, 2020
@eellison
Copy link
Contributor

Thanks for the issue. This should be fixed with #49247

JIT Triage automation moved this from Need triage to Done Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
oncall: jit Add this issue/PR to JIT oncall triage queue
Projects
JIT Triage
  
Done
Development

No branches or pull requests

3 participants