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

[fx_importer] Convert non-persistent buffers lifted as tensor constants #2902

Merged
merged 4 commits into from
Feb 13, 2024

Conversation

sjain-stanford
Copy link
Member

@sjain-stanford sjain-stanford commented Feb 13, 2024

The investigation is largely recorded in #2881, but this change allows us to capture non-persistent buffers that were lifted as tensor constants (after pytorch/pytorch#118969 landed in upstream PyTorch), and propagate them to Torch dialect as "frozen" torch.vtensor.literal. I believe this patch should work with both nightly and stable PyTorch, but will let CI confirm the same. Thanks @stellaraccident for the valuable pointers and guidance.

vivekkhandelwal1 and others added 2 commits February 8, 2024 15:03
Set PyTorch and TorchVision version to nightly release 2024-02-07.

Signed-Off By: Vivek Khandelwal <vivekkhandelwal1424@gmail.com>
@sjain-stanford sjain-stanford changed the title Bump pytorch nightly [fx_importer] Fixes to convert non-persistent buffers lifted as tensor constants Feb 13, 2024
Copy link
Collaborator

@stellaraccident stellaraccident left a comment

Choose a reason for hiding this comment

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

If the CI passes, this lgtm and can land. Once it does, let's close the original PR.

@sjain-stanford sjain-stanford changed the title [fx_importer] Fixes to convert non-persistent buffers lifted as tensor constants [fx_importer] Convert non-persistent buffers lifted as tensor constants Feb 13, 2024
@stellaraccident
Copy link
Collaborator

stellaraccident commented Feb 13, 2024

You'll need to hasattr(..., "constants") to guard the new clause: " AttributeError: 'ExportedProgram' object has no attribute 'constants'"

If doing that, I would probably make it fully conditional with a note about where the change happened: If there is no "constants" attribute, consult the "state_dict". Otherwise, only look at "constants". Future us will thank us because the freezing of states will be something we want to undo eventually (just like the upstream patch had to fix this).

@sjain-stanford
Copy link
Member Author

sjain-stanford commented Feb 13, 2024

If doing that, I would probably make it fully conditional with a note about where the change happened: If there is no "constants" attribute, consult the "state_dict". Otherwise, only look at "constants". Future us will thank us because the freezing of states will be something we want to undo eventually (just like the upstream patch had to fix this).

Done. Just a clarification that we will need to continue using state_dict for parameters (irrespective of how buffers are handled). Is that correct?

@stellaraccident
Copy link
Collaborator

If doing that, I would probably make it fully conditional with a note about where the change happened: If there is no "constants" attribute, consult the "state_dict". Otherwise, only look at "constants". Future us will thank us because the freezing of states will be something we want to undo eventually (just like the upstream patch had to fix this).

Done. Just a clarification that we will need to continue using state_dict for parameters (irrespective of how buffers are handled). Is that correct?

I think that how you have this now gets this in the safe state. If we were unconditionally looking at state_dict, then we would likely be lifting things that future-us actually wants to be treating as mutable, model-level things. Many systems are just figuring out what to do about that, but better to have this do the right thing at the front door for now.

@stellaraccident stellaraccident merged commit 3e836d8 into llvm:main Feb 13, 2024
3 checks passed
@sjain-stanford sjain-stanford deleted the roll-pytorch branch February 13, 2024 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants