-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[diffusion] chore: improve memory usage on consumer-level GPU #18997
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |||||||||||||||||||||||||||||||||||||||||||
| from sglang.multimodal_gen.runtime.layers.quantization.configs.nunchaku_config import ( | ||||||||||||||||||||||||||||||||||||||||||||
| NunchakuConfig, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| from sglang.multimodal_gen.runtime.loader.utils import BYTES_PER_GB | ||||||||||||||||||||||||||||||||||||||||||||
| from sglang.multimodal_gen.runtime.platforms import ( | ||||||||||||||||||||||||||||||||||||||||||||
| AttentionBackendEnum, | ||||||||||||||||||||||||||||||||||||||||||||
| current_platform, | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -411,7 +412,18 @@ def _adjust_quant_config(self): | |||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def _adjust_offload(self): | ||||||||||||||||||||||||||||||||||||||||||||
| if self.pipeline_config.task_type.is_image_gen(): | ||||||||||||||||||||||||||||||||||||||||||||
| # TODO: to be handled by each platform | ||||||||||||||||||||||||||||||||||||||||||||
| if current_platform.get_device_total_memory() / BYTES_PER_GB < 30: | ||||||||||||||||||||||||||||||||||||||||||||
| logger.info("Enabling all offloading for GPU with low device memory") | ||||||||||||||||||||||||||||||||||||||||||||
| if self.dit_cpu_offload is None: | ||||||||||||||||||||||||||||||||||||||||||||
| self.dit_cpu_offload = True | ||||||||||||||||||||||||||||||||||||||||||||
| if self.text_encoder_cpu_offload is None: | ||||||||||||||||||||||||||||||||||||||||||||
| self.text_encoder_cpu_offload = True | ||||||||||||||||||||||||||||||||||||||||||||
| if self.image_encoder_cpu_offload is None: | ||||||||||||||||||||||||||||||||||||||||||||
| self.image_encoder_cpu_offload = True | ||||||||||||||||||||||||||||||||||||||||||||
| if self.vae_cpu_offload is None: | ||||||||||||||||||||||||||||||||||||||||||||
| self.vae_cpu_offload = True | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+416
to
+425
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hardcoded value
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| elif self.pipeline_config.task_type.is_image_gen(): | ||||||||||||||||||||||||||||||||||||||||||||
| logger.info( | ||||||||||||||||||||||||||||||||||||||||||||
| "Disabling some offloading (except dit, text_encoder) for image generation model" | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1086,7 +1098,7 @@ def _validate_offload(self): | |||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| self.use_fsdp_inference = False | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if self.dit_cpu_offload: | ||||||||||||||||||||||||||||||||||||||||||||
| if self.dit_cpu_offload is None: | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change from The previous logic correctly handled this by disabling
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| logger.warning( | ||||||||||||||||||||||||||||||||||||||||||||
| "dit_layerwise_offload is enabled, automatically disabling dit_cpu_offload." | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
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.
The added logic for low-memory GPUs is nearly identical to the
elseblock on lines 438-447, which introduces code duplication. This can make future modifications more error-prone.Additionally, the value
30is a magic number. It would be better to define it as a constant, for exampleLOW_GPU_MEMORY_THRESHOLD_GB = 30, to improve readability and make it easier to change.Please consider refactoring the
_adjust_offloadmethod to eliminate this duplication.