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

[torch.compile] A simple solution to recursively compile loaded model: using phi3-small as an example #8398

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

wschin
Copy link
Contributor

@wschin wschin commented Sep 12, 2024

It's often hard to apply torch.compile directly to a model because many limitations. However, there are only a few key nn.Modules we really need to compile to get max speed. This PR presents a short solution to solve the problem. Phi3-small got 15% latency improvement with this.

This PR contains 3 major functions:

  • register_module_to_compile: it registers which torch.nn.Module to compile when scanning child modules from top to bottom (e.g., from Phi3 to MLP, layernorm).
  • compile_child_modules: it is called after model is loaded to visit child nn.Module's from top (e.g., GPT2) to bottom (e.g., MLP). If a nn.Module is compiled, its child nn.Module's won't be compiled again.
  • unregister_module_to_compile: it undoes register_module_to_compile.
  • To enable this feature set COMPILE_CHILD_NN_MODULES=1.

Copy link

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

@wschin wschin changed the title [torch.compile] A simple recursive solution to recursively compile loaded model: using phi3-small as an example [torch.compile] A simple recursive to recursively compile loaded model: using phi3-small as an example Sep 12, 2024
@wschin wschin changed the title [torch.compile] A simple recursive to recursively compile loaded model: using phi3-small as an example [torch.compile] A simple solution to recursively compile loaded model: using phi3-small as an example Sep 12, 2024
@mgoin mgoin requested a review from youkaichao September 12, 2024 15:34
@wschin
Copy link
Contributor Author

wschin commented Sep 25, 2024

@youkaichao, did you get a chance to review?
@comaniac, it'd nice if you can help reviewing. At least, let me know if I should continue writing test. This solution is extremely simple and effective.

Thank you.

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.

1 participant