[Feature]Add MSProbe dump support in SGLang (#18349)

This commit is contained in:
Yujing
2026-04-25 10:12:50 +03:00
committed by GitHub
parent 21835fb0af
commit 6175946db7
4 changed files with 653 additions and 0 deletions
@@ -363,6 +363,11 @@ class ModelRunner(ModelRunnerKVCacheMixin):
self.remote_instance_transfer_engine = None
self.remote_instance_transfer_engine_session_id = ""
self.remote_instance_transfer_engine_weight_info = None
self.msprobe_debugger = None
if server_args.msprobe_dump_config is not None:
self.init_msprobe()
# auxiliary hidden capture mode. TODO: expose this to server args?
self.eagle_use_aux_hidden_state = False
self.dflash_use_aux_hidden_state = False
@@ -515,6 +520,21 @@ class ModelRunner(ModelRunnerKVCacheMixin):
is_draft_model=is_draft_model,
)
def init_msprobe(self):
# Init the msprobe
try:
from msprobe.pytorch import PrecisionDebugger, seed_all
except ImportError:
logger.warning(
"Please install msprobe for tensor data dump: pip install mindstudio-probe --pre, "
"see https://gitcode.com/Ascend/msprobe for details."
)
return
seed_all(mode=True)
self.msprobe_debugger = PrecisionDebugger(
config_path=self.server_args.msprobe_dump_config
)
def init_mindspore_runner(self):
# Init the mindspore runner
# for now, there is only some communication initialization work
@@ -2918,6 +2938,12 @@ class ModelRunner(ModelRunnerKVCacheMixin):
) -> ModelRunnerOutput:
self.forward_pass_id += 1
if self.msprobe_debugger is not None:
rank_id = (
self.gpu_id if self.dp_size is not None and self.dp_size > 1 else None
)
self.msprobe_debugger.start(model=self.model, rank_id=rank_id)
step_span_ctx = (
torch.profiler.record_function(_build_step_span_name(forward_batch))
if torch.autograd._profiler_enabled()
@@ -2974,6 +3000,10 @@ class ModelRunner(ModelRunnerKVCacheMixin):
if dumper.may_enable:
dumper.step()
if self.msprobe_debugger is not None:
self.msprobe_debugger.stop()
self.msprobe_debugger.step()
return output
def _forward_raw(
+20
View File
@@ -759,6 +759,9 @@ class ServerArgs:
# For forward hooks
forward_hooks: Optional[List[dict[str, Any]]] = None
# For msProbe
msprobe_dump_config: Optional[str] = None
def __post_init__(self):
"""
Orchestrates the handling of various server arguments, ensuring proper configuration and validation.
@@ -4024,6 +4027,15 @@ class ServerArgs:
self.disable_cuda_graph = True
self.skip_server_warmup = True
if self.msprobe_dump_config is not None:
logger.warning(
"When msProbe is enabled, "
"cuda graph is disabled(disable_cuda_graph=True) because msProbe only supports dump in eager mode, "
"warmup is disabled(skip_server_warmup=True) because there is no need to dump data for this stage."
)
self.disable_cuda_graph = True
self.skip_server_warmup = True
# Validate limit_mm_per_prompt modalities
if self.limit_mm_data_per_request:
if isinstance(self.limit_mm_data_per_request, str):
@@ -6495,6 +6507,14 @@ class ServerArgs:
help="JSON-formatted forward hook specifications to attach to the model.",
)
# For msProbe
parser.add_argument(
"--msprobe-dump-config",
type=str,
default=ServerArgs.msprobe_dump_config,
help="The path of the JSON configuration file for msProbe. If specified, enables msProbe dump.",
)
@classmethod
def from_cli_args(cls, args: argparse.Namespace):
args.tp_size = args.tensor_parallel_size