Support non-intrusive arbitrary dumping in dumper and add e2e tests (#19563)

This commit is contained in:
fzyzcjy
2026-02-28 18:06:55 +08:00
committed by GitHub
parent ccbc47d6be
commit 63a4778542
5 changed files with 311 additions and 10 deletions

View File

@@ -138,6 +138,7 @@ class DumperConfig(_BaseConfig):
collective_timeout: int = 60
server_port: str = "-1"
non_intrusive_mode: str = "core"
source_patcher_config: Optional[str] = None
@classmethod
def _env_prefix(cls) -> str:
@@ -325,6 +326,25 @@ class _Dumper:
return decorator
def apply_source_patches(self) -> None:
"""Apply source patches from DUMPER_SOURCE_PATCHER_CONFIG if set.
Automatically injects ``from sglang.srt.debug_utils.dumper import dumper``
into every replacement block so users don't need to write it in YAML.
"""
config_path = self._config.source_patcher_config
if not config_path:
return
from sglang.srt.debug_utils.source_patcher import apply_patches_from_config
yaml_content: str = Path(config_path).read_text()
print(f"[source_patcher] loading config from {config_path}")
apply_patches_from_config(
yaml_content,
extra_imports=["from sglang.srt.debug_utils.dumper import dumper"],
)
def register_non_intrusive_dumper(
self,
model: "torch.nn.Module",
@@ -588,11 +608,13 @@ class _NonIntrusiveDumper:
def _detect_module_ctx(
cls, module_name: str, module: "torch.nn.Module"
) -> Optional[dict]:
if cls._LAYER_NAME_RE.fullmatch(module_name):
match = cls._LAYER_NAME_RE.fullmatch(module_name)
if match:
for plugin in _plugins:
layer_id = plugin.detect_layer_id(module)
if layer_id is not None:
return {"layer_id": layer_id}
return {"layer_id": int(match.group(1))}
return None
def _register_ctx_hooks(self, module: "torch.nn.Module", *, ctx: dict) -> None:

View File

@@ -1061,6 +1061,7 @@ class ModelRunner(ModelRunnerKVCacheMixin):
)
if dumper.may_enable:
dumper.apply_source_patches()
dumper.register_non_intrusive_dumper(self.model)
# Pre-expand RoPE cache before CUDA Graph capture
@@ -1763,9 +1764,10 @@ class ModelRunner(ModelRunnerKVCacheMixin):
init_new_workspace=init_new_workspace,
)
self.prefill_attention_backend_str, self.decode_attention_backend_str = (
self.server_args.get_attention_backends()
)
(
self.prefill_attention_backend_str,
self.decode_attention_backend_str,
) = self.server_args.get_attention_backends()
if self.decode_attention_backend_str != self.prefill_attention_backend_str:
from sglang.srt.layers.attention.hybrid_attn_backend import (