Support symmetric memory pre-allocation to avoid fragmentation#17089
Support symmetric memory pre-allocation to avoid fragmentation#17089Fridge003 merged 3 commits intosgl-project:mainfrom
Conversation
|
/tag-and-rerun-ci |
Summary of ChangesHello @nvcastet, 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 enhances memory management within the system by introducing a mechanism to pre-allocate symmetric memory. The primary goal is to combat memory fragmentation, a common issue in PyTorch's memory pools that can lead to out-of-memory errors even when sufficient total memory is available. By allowing a configurable pre-allocation size, the system can proactively reserve memory, thereby improving overall stability and performance, especially in scenarios involving distributed operations. 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 support for symmetric memory pre-allocation to mitigate memory fragmentation in PyTorch memory pools. A new environment variable SGLANG_SYMM_MEM_PREALLOC_GB_SIZE is added for this purpose. The changes involve refactoring the forward_stream initialization and adding the pre-allocation logic in ModelRunner.
My review identifies a critical issue in the pre-allocation logic where the memory size is incorrectly calculated, potentially leading to overallocation and Out-Of-Memory errors. I've provided a code suggestion to fix this.
3f25295 to
53e71d4
Compare
|
Also can we add a B200 test for symmetric memory. Can be a subtest of this one |
53e71d4 to
4396ca5
Compare
Motivation
Related to #17038
PyTorch mempools never de-fragment memory in OOM scenarios, so we need to pre-allocate a large chunk of memory to limit fragmentation in symmetric memory pool.
Add
SGLANG_SYMM_MEM_PREALLOC_GB_SIZEto specify the prealloc size in GiB.Solved issues found in #16327 and #13863
CC @merrymercy @Fridge003
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci