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

[wip][meta-llama][torch.compile] Fix issues with torch.compile #32102

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anijain2305
Copy link
Contributor

What does this PR do?

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@anijain2305 anijain2305 marked this pull request as draft July 19, 2024 21:37
torch._dynamo.mark_static_address(new_layer_key_cache)
torch._dynamo.mark_static_address(new_layer_value_cache)
# torch._dynamo.mark_static_address(new_layer_key_cache)
# torch._dynamo.mark_static_address(new_layer_value_cache)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in __init__ function. A proper fix would be to hoist the construction of the StaticCache such that it is outside of torch.compile scope.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can maybe compile _generate, and generate inits the cache then call the compiled _generate.

Copy link
Contributor Author

@anijain2305 anijain2305 Jul 22, 2024

Choose a reason for hiding this comment

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

Ok, I looked more into why this was not a problem for gpt-fast.

In gpt-fast, the KV cache is an instance of nn.Module, with the k and v caches being marked as buffers. Since buffers are considered static by torch.compile, we don't need to annotate them as mark_static_address. This is the pointer - https://github.com/pytorch-labs/gpt-fast/blob/main/model.py#L73

@ArthurZucker @gante Would you be willing to carry out a refactor similar to gpt-fast by making these caches an instance of nn-module? This will improve compatibility with torch.compile.

Thanks to @mlazos and @yanboliang for pointing me to gpt-fast. cc @Chillee

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah! TBH as long as we don't see performance reduction, this should be alright (AKA just inheriting from nn.Module + marking as buffers).
You can also potentially add it here!

Copy link
Member

Choose a reason for hiding this comment

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

@anijain2305 sounds great!

Will you open a PR for it? :D

Copy link
Collaborator

Choose a reason for hiding this comment

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

#32159 we actually needed the deep copy so went ahead and added that for now, testing is required on my end

Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

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