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

insert_deferred_runtime_asserts does not work with modulus #125376

Open
ezyang opened this issue May 2, 2024 · 2 comments
Open

insert_deferred_runtime_asserts does not work with modulus #125376

ezyang opened this issue May 2, 2024 · 2 comments
Labels
module: dynamic shapes triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@ezyang
Copy link
Contributor

ezyang commented May 2, 2024

馃悰 Describe the bug

insert_deferred_runtime_asserts operates by symbolic tracing through the PythonReferenceAnalysis. However, the implementation of mod is not traceable:

    @staticmethod
    def mod(x, y): 
        ret = abs(x) % abs(y)
        if x < 0:
            ret *= -1
        return ret

due to the conditional on x.

This is related to @lezcano complaining about how C and Python modulus semantics are not the same.

Versions

main

@ezyang
Copy link
Contributor Author

ezyang commented May 2, 2024

Minimal repro:

import torch
import torch._dynamo

torch._dynamo.config.capture_scalar_outputs = True


@torch.compile(fullgraph=True)
def f(x, w):
    y = x.item()
    torch._check(y % 4 == 0)
    return x * w


print(f(torch.tensor(20), torch.randn(3)))

@lezcano
Copy link
Collaborator

lezcano commented May 2, 2024

We need to implement our own C-modulus SymPy class to fix this one.

@drisspg drisspg added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: dynamic shapes triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants