[diffusion][mps] fix vae model offload#20607
Conversation
Signed-off-by: Xiaodong Ye <yeahdongcn@gmail.com>
Summary of ChangesHello, 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 resolves an issue where the VAE model's offloading behavior was incorrect, particularly on MPS devices and during the warmup phase of diffusion pipelines. The changes ensure that the VAE model is properly managed, staying loaded when needed (like during warmup) and correctly offloaded/reloaded to prevent system hangs and optimize memory usage, thereby improving the stability and performance of the diffusion generation process. 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. Changelog
Activity
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 effectively addresses an issue with VAE model offloading on MPS devices by adding torch.mps.synchronize() before model deletion, a crucial step to prevent hangs. The changes also introduce a sensible optimization to skip offloading during warmup, and generalize the component handling by replacing a hardcoded "vae" string with a dynamic component_name. The implementation is solid. I have one minor suggestion to enhance maintainability.
…oding.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
mickqian
left a comment
There was a problem hiding this comment.
some things that feel strange for me:
model_loadedstays inserver_args- do we really need this lazy load and offload?
|
/tag-and-rerun-ci |
Yes, I noticed that as well.
FastVideo appears to use the same pattern here: https://github.com/hao-ai-lab/FastVideo/blob/main/fastvideo/pipelines/stages/decoding.py#L242 Edit: However, FastVideo does not have a warmup process. After one forward pass, the model is offloaded. |
|
/rerun-failed-ci |
2 similar comments
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
@mickqian All CI (Nvidia + AMD) passed and PR is approved, ready for merge — SGLDHelper bot |
Signed-off-by: Xiaodong Ye <yeahdongcn@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Xiaodong Ye <yeahdongcn@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Xiaodong Ye <yeahdongcn@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Xiaodong Ye <yeahdongcn@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Xiaodong Ye <yeahdongcn@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Motivation
When running:
uv run sglang generate --model-path /home/dist/FLUX.1-dev \ --prompt "A logo With Bold Large text: SGL Diffusion" \ --save-output --warmupthe
--warmupoption does not work correctly onmps.Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci