-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(gms): cherry-pick support SGLang 0.5.16 memory pool API (#12445) #12492
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 all 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 |
|---|---|---|
|
|
@@ -10,7 +10,6 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| import inspect | ||
| import logging | ||
| from contextlib import contextmanager | ||
| from typing import Optional | ||
|
|
@@ -163,84 +162,33 @@ def patch_model_runner() -> None: | |
| if hasattr(ModelRunner, "_gms_patched"): | ||
| return | ||
|
|
||
| original_init_memory_pool = ModelRunner.init_memory_pool | ||
| memory_arg_name = next( | ||
| ( | ||
| name | ||
| for name in inspect.signature(original_init_memory_pool).parameters | ||
| if name != "self" | ||
| ), | ||
| None, | ||
| ) | ||
| original_alloc_memory_pool = ModelRunner.alloc_memory_pool | ||
|
|
||
| def patched_init_memory_pool(self, *args, **kwargs): | ||
| """Patch memory baseline for SGLang old/new init_memory_pool signatures.""" | ||
| def patched_alloc_memory_pool(self, *args, **kwargs): | ||
| impl = get_gms_memory_saver_impl() | ||
| preloaded_weights_gib = 0.0 | ||
| if impl is not None: | ||
| if ( | ||
| impl is not None | ||
| and impl.preloaded_weights_bytes > 0 | ||
| and not self.__dict__.get("_gms_memory_baseline_adjusted", False) | ||
| ): | ||
| preloaded_weights_gib = impl.preloaded_weights_bytes / (1 << 30) | ||
| old_value = self.pre_model_load_memory | ||
| self.pre_model_load_memory += preloaded_weights_gib | ||
| self._gms_memory_baseline_adjusted = True | ||
|
Comment on lines
+175
to
+177
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. 🔍 Baseline adjustment now mutates ModelRunner state permanently Previously the preloaded-weight correction was applied only to the argument passed into Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| logger.info( | ||
| "[GMS] Adjusted pre_model_load_memory for preloaded weights: " | ||
| "%.2f GiB + %.2f GiB = %.2f GiB", | ||
| old_value, | ||
| preloaded_weights_gib, | ||
| self.pre_model_load_memory, | ||
| ) | ||
|
|
||
| if preloaded_weights_gib > 0 and memory_arg_name in ( | ||
| "pre_model_load_memory", | ||
| "total_gpu_memory", | ||
| ): | ||
| if args: | ||
| old_value = args[0] | ||
| new_value = ( | ||
| old_value + preloaded_weights_gib | ||
| if isinstance(old_value, (int, float)) | ||
| else old_value | ||
| ) | ||
| args = (new_value,) + args[1:] | ||
| elif memory_arg_name in kwargs: | ||
| old_value = kwargs[memory_arg_name] | ||
| new_value = ( | ||
| old_value + preloaded_weights_gib | ||
| if isinstance(old_value, (int, float)) | ||
| else old_value | ||
| ) | ||
| kwargs = dict(kwargs) | ||
| kwargs[memory_arg_name] = new_value | ||
| else: | ||
| old_value = None | ||
| new_value = None | ||
|
|
||
| if isinstance(old_value, (int, float)) and isinstance( | ||
| new_value, (int, float) | ||
| ): | ||
| logger.info( | ||
| "[GMS] Adjusted %s for preloaded weights: " | ||
| "%.2f GiB + %.2f GiB = %.2f GiB", | ||
| memory_arg_name, | ||
| old_value, | ||
| preloaded_weights_gib, | ||
| new_value, | ||
| ) | ||
| else: | ||
| logger.info( | ||
| "[GMS] Could not adjust %s for preloaded weights; value=%r", | ||
| memory_arg_name, | ||
| old_value, | ||
| ) | ||
| elif impl is not None and impl.imported_weights_bytes > 0: | ||
| if preloaded_weights_gib > 0: | ||
| logger.info( | ||
| "[GMS] Leaving %s unchanged; unsupported SGLang " | ||
| "init_memory_pool signature for preloaded weights", | ||
| memory_arg_name, | ||
| ) | ||
| else: | ||
| logger.info( | ||
| "[GMS] Leaving %s unchanged; weights were loaded by this process", | ||
| memory_arg_name, | ||
| ) | ||
|
|
||
| return original_init_memory_pool(self, *args, **kwargs) | ||
|
|
||
| ModelRunner.init_memory_pool = patched_init_memory_pool | ||
| return original_alloc_memory_pool(self, *args, **kwargs) | ||
|
|
||
| ModelRunner.alloc_memory_pool = patched_alloc_memory_pool | ||
| ModelRunner._gms_patched = True | ||
| _model_runner_patched = True | ||
| logger.info("[GMS] Patched ModelRunner.init_memory_pool") | ||
| logger.info("[GMS] Patched ModelRunner.alloc_memory_pool") | ||
|
|
||
|
|
||
| def patch_static_state_for_gms() -> None: | ||
|
|
||
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.
🟡 Worker startup crashes hard on SGLang builds that lack the new memory-pool entry point
The startup patch grabs the new memory-pool entry point unconditionally (
ModelRunner.alloc_memory_poolatlib/gpu_memory_service/integrations/sglang/patches.py:165) without any guard, so on an engine build that does not expose it the worker dies at import time instead of continuing with a warning.Impact: Users on a slightly older engine release get an unexplained worker crash at start instead of a degraded-but-working start.
Loss of the previous version-tolerant patch path
The old implementation wrapped
ModelRunner.init_memory_pooland probed its signature withinspect, tolerating both old and new parameter names, and the only failure mode was theImportErrorbranch (lib/gpu_memory_service/integrations/sglang/patches.py:156-160) which logs a warning and returns. The new code accessesModelRunner.alloc_memory_pooldirectly outside thattry, so anAttributeErrorpropagates out ofpatch_model_runner(), which is executed at module import in the scheduler child process (lib/gpu_memory_service/integrations/sglang/model_loader.py:44). Similarly,patched_alloc_memory_poolreadsself.pre_model_load_memory(patches.py:175-176) with nogetattrfallback, so a renamed/absent attribute raises during read-mode startup instead of being logged and skipped as the old code did. Wrapping the attribute lookups (e.g.getattr(ModelRunner, "alloc_memory_pool", None)and ahasattrcheck on the baseline attribute) restores graceful degradation.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.