Fix OOM by offloading multimodal features to CPU after embedding#16018
Fix OOM by offloading multimodal features to CPU after embedding#16018hnyls2002 merged 3 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello @liusy58, 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 critical memory optimization for multimodal models by ensuring that once image or audio features have been embedded and utilized during the initial prefill stage, they are promptly moved from the GPU to the CPU. This strategic offloading frees up valuable GPU memory, mitigating the risk of Out-Of-Memory errors that could occur if these features remained on the GPU throughout the entire generation process, thereby enhancing the stability and scalability of multimodal inference. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a memory optimization by offloading multimodal features to the CPU after they have been used for embedding during the prefill stage. This is a good change to prevent potential out-of-memory errors during the generation phase. My review includes a suggestion to simplify the new code and fix a potential bug.
|
/tag-and-rerun-ci |
|
May I ask if you enabled the SGLANG_USE_CUDA_IPC_TRANSPORT feature when you encountered the OOM issue? In fact, I found that in |
No, this PR isn't specifically designed to fix |
|
/rerun-failed-ci |
cc: #16118 |
|
/rerun-failed-ci |
There was a problem hiding this comment.
Moving to CPU is a workaround; we should use a weak ref to handle the GPU memory free. like what @yhyang201 did in #9673
@hnyls2002 Updated the comments. Please take another look. |
Motivation
In the multimodal scheduling flow, image/audio features are moved to the GPU during the
prepare_for_extendphase. However, these tensors remained on the GPU throughout the entire generation process (Decode phase), even though they are only utilized once during Prefill stage.Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist