From 8c04f0f2e1695fd40c291280d8ace6e901be7f4e Mon Sep 17 00:00:00 2001 From: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com> Date: Fri, 28 Mar 2025 14:01:42 +0800 Subject: [PATCH] Support with_stack and record_shapes in profiler (#4740) Co-authored-by: Lianmin Zheng --- python/sglang/srt/managers/io_struct.py | 2 ++ python/sglang/srt/managers/scheduler.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/python/sglang/srt/managers/io_struct.py b/python/sglang/srt/managers/io_struct.py index 578b39c21..e25a8f242 100644 --- a/python/sglang/srt/managers/io_struct.py +++ b/python/sglang/srt/managers/io_struct.py @@ -675,6 +675,8 @@ class ProfileReq: output_dir: Optional[str] = None num_steps: Optional[int] = None activities: Optional[List[str]] = None + with_stack: Optional[bool] = None + record_shapes: Optional[bool] = None @dataclass diff --git a/python/sglang/srt/managers/scheduler.py b/python/sglang/srt/managers/scheduler.py index e386a5854..f696862da 100644 --- a/python/sglang/srt/managers/scheduler.py +++ b/python/sglang/srt/managers/scheduler.py @@ -1807,7 +1807,11 @@ class Scheduler( def profile(self, recv_req: ProfileReq): if recv_req.type == ProfileReqType.START_PROFILE: return self.start_profile( - recv_req.output_dir, recv_req.num_steps, recv_req.activities + recv_req.output_dir, + recv_req.num_steps, + recv_req.activities, + recv_req.with_stack, + recv_req.record_shapes, ) else: return self.stop_profile() @@ -1817,6 +1821,8 @@ class Scheduler( output_dir: Optional[str], num_steps: Optional[int], activities: Optional[List[str]], + with_stack: Optional[bool], + record_shapes: Optional[bool], ) -> None: if self.profiler_activities: return ProfileReqOutput( @@ -1847,7 +1853,8 @@ class Scheduler( if torchprof_activities: self.torch_profiler = torch.profiler.profile( activities=torchprof_activities, - with_stack=True, + with_stack=with_stack if with_stack is not None else True, + record_shapes=record_shapes if record_shapes is not None else False, ) self.torch_profiler.start()