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

Already on GitHub? Sign in to your account

dont let dynamo inline inside of NF4 constructors or __torch_dispatch__ #544

Merged
merged 2 commits into from
Jul 28, 2024

Conversation

bdhirsh
Copy link
Contributor

@bdhirsh bdhirsh commented Jul 26, 2024

This fixes a few known "gotchas" for NF4Tensor when getting it to work with compile. Enumerating:

(1) the NF4Tensor() constructor needs to be wrapped in a function that is annotated with torch._dynamo.allow_in_graph. We want to make this work more automatically soon, see tracking issue: pytorch/pytorch#114389

(2) NF4Tensor.__new__ and NF4Tensor.__torch_dispatch__ both need to be marked with torch._dynamo.disable.

There isn't really a great fix for (2) today. One thing to note though is that as long as your model doesn't have a million graph breaks, you are unlikely to run into problems with (2). In the torchtune repro, there were a lot of deeply nested graph breaks in the FSDP2 code that caused dynamo to try to e.g. install itself directly onto the NF4Tensor.__new__ frame, which causes problems.

Copy link

pytorch-bot bot commented Jul 26, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 7b10019 with merge base afde175 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 26, 2024
@msaroufim msaroufim self-requested a review July 26, 2024 19:15
Copy link
Member

@msaroufim msaroufim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@msaroufim msaroufim merged commit e5b705c into pytorch:main Jul 28, 2024
13 checks passed
Hanxian97 pushed a commit that referenced this pull request Jul 29, 2024
…__ (#544)

* dont let dynamo inline inside of NF4 constructors or __torch_dispatch__

* allow_in_graph the ctr instead of disabling it
dbyoung18 pushed a commit to dbyoung18/ao that referenced this pull request Jul 31, 2024
…__ (pytorch#544)

* dont let dynamo inline inside of NF4 constructors or __torch_dispatch__

* allow_in_graph the ctr instead of disabling it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants