-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
feat: offload weights to cpu before fp8 online quant #19967
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
base: main
Are you sure you want to change the base?
Conversation
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run 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 either: Add 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @yma11, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a crucial memory optimization for FP8 online quantization by enabling the temporary offloading of model weights to the CPU before the quantization process begins. This addresses a significant limitation by reducing the GPU memory footprint required during model loading and quantization. The feature is controlled via a new environment variable and includes a safeguard to prevent its concurrent use with existing CPU offload functionalities, ensuring system stability.
Highlights
- Enhanced FP8 Quantization Memory Efficiency: Implemented a mechanism to offload model weights to CPU memory prior to online FP8 quantization. This significantly reduces the peak GPU memory usage during the model loading and quantization process, addressing a previous limitation where the entire model had to reside on the GPU.
- New Configuration Option: Introduced
VLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT
as an environment variable. Setting this to1
enables the new weight offloading behavior, allowing for more memory-efficient FP8 quantization. - Feature Incompatibility Enforcement: Added a validation check to prevent simultaneous use of
VLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT
andcpu_offload_gb
. This ensures stable operation and avoids potential conflicting behaviors between the two memory management strategies. - Documentation Update: Updated the FP8 quantization documentation (
docs/features/quantization/fp8.md
) to reflect the new memory optimization feature and provide guidance on its usage. - New Test Coverage: Added a dedicated test case (
test_offload_weights_before_quant_fp8
intests/quantization/test_cpu_offload.py
) to verify the correct functionality of theVLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT
feature.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request introduces a new feature to offload model weights to the CPU before FP8 online quantization. This addresses memory limitations when quantizing large models. The changes include modifications to the documentation, a new test case, updates to the configuration and environment variable handling, and adjustments to the FP8 quantization process to accommodate CPU offloading. The code appears well-structured and addresses the intended problem. However, some comments could be improved for clarity.
@@ -135,4 +135,4 @@ print(result[0].outputs[0].text) | |||
``` | |||
|
|||
!!! warning | |||
Currently, we load the model at original precision before quantizing down to 8-bits, so you need enough memory to load the whole model. | |||
Currently, by default we load the model at original precision before quantizing down to 8-bits, so you need enough memory to load the whole model. To avoid this, adding `VLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT=1` can allow offloading weights to cpu before quantization and quantized weights will be kept in device. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider rephrasing for clarity. Suggestion: "Currently, the model is loaded at its original precision before being quantized to 8-bits. This requires sufficient memory to hold the entire model. To avoid this, set VLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT=1
to offload weights to CPU before quantization; the quantized weights will then be stored on the device."
Currently, by default we load the model at original precision before quantizing down to 8-bits, so you need enough memory to load the whole model. To avoid this, adding `VLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT=1` can allow offloading weights to cpu before quantization and quantized weights will be kept in device. | |
Currently, by default we load the model at original precision before quantizing down to 8-bits, so you need enough memory to load the whole model. To avoid this, adding `VLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT=1` can allow offloading weights to cpu before quantization and quantized weights will be kept in device. |
if self.cpu_offload_gb > 0 and envs.VLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT: | ||
raise ValueError("CPU offload can't work together with" | ||
"OFFLOAD_WEIGHTS_BEFORE_QUANT") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a more descriptive error message, including the names of the conflicting variables. Suggestion: "cpu_offload_gb
and VLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT
cannot be enabled simultaneously. Disable one to resolve the conflict."
raise ValueError("CPU offload can't work together with"
"OFFLOAD_WEIGHTS_BEFORE_QUANT")
if VLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT: | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider rephrasing for clarity. Suggestion: "If weights were loaded onto the CPU for FP8 online quantization, there is no need to move them back to the original device."
if VLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT: | |
return | |
# If weights were loaded on cpu for fp8 online quantization, won't need move | |
# back to original device |
Signed-off-by: yan <[email protected]>
This pull request has merge conflicts that must be resolved before it can be |
We offload weights to cpu before online quantization so that device doesn't need to hold whole model weights, which fix the limitation mentioned in upstream fp8 quantization. Note that, this option can't work together with
cpu_offload_gb
to avoid obscure behaviors.This feature controlled by env variable
VLLM_OFFLOAD_WEIGHTS_BEFORE_QUANT
, example command: