Skip to content

[dynamo] Prevent unnecessary recompilation, when using disable inside of compile #157491

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jmaczan
Copy link

@jmaczan jmaczan commented Jul 2, 2025

Fixes #157399 by skipping convert_frame._compile for functions with code.co_names equal to (torch, _dynamo, disable)

It's my naive first approach and my first PR to PyTorch. I tested it locally on simple tensors and seem to work fine. I'll be grateful for a further guidance with improving the fix and adding unit tests.

Thanks!

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames

Copy link

pytorch-bot bot commented Jul 2, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/157491

Note: Links to docs will display an error until the docs builds have been completed.

❌ 4 New Failures, 37 Pending

As of commit 1a03f45 with merge base 34c8033 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Copy link

linux-foundation-easycla bot commented Jul 2, 2025

CLA Signed


The committers listed above are authorized under a signed CLA.

@jmaczan jmaczan changed the title [dynamo] Prevent recompilation always when using disable inside of compile [dynamo] Prevent unnecessary recompilation, when using disable inside of compile Jul 2, 2025
@jmaczan
Copy link
Author

jmaczan commented Jul 2, 2025

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label Jul 2, 2025
@thenumberouscode
Copy link
Contributor

thenumberouscode commented Jul 3, 2025

Your fix might cause a issue that could lead to unexpected behavior in the following repro code; the inductor isn't compiling any functions.

@torch.compile(backend="inductor")
def main(x):

    # @torch.compiler.disable
    @torch._dynamo.disable
    def my_fn(x):
        return x + 10

    return 1 + my_fn(x)

@jmaczan
Copy link
Author

jmaczan commented Jul 3, 2025

Thx @thenumberouscode, I’ll look into that today, try to reproduce it and improve the fix if needed

@thenumberouscode
Copy link
Contributor

thenumberouscode commented Jul 3, 2025

Bro, I tried to fix this issue as well. Would you mind checking it for me? Thanks!
#157566

@jmaczan
Copy link
Author

jmaczan commented Jul 3, 2025

I think this fix needs further refinement. I'm closing the PR for now

@jmaczan jmaczan closed this Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[dynamo] using disable inside of compile always recompiles
3 participants