From 93ef9a094ddd144df4043ed29e80897371bd690f Mon Sep 17 00:00:00 2001 From: Muqi Li Date: Fri, 24 Oct 2025 17:20:46 +0800 Subject: [PATCH] [Profiler] expand '~' for `torch_profiler_output_dir` (#11999) --- python/sglang/srt/managers/scheduler_profiler_mixin.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/python/sglang/srt/managers/scheduler_profiler_mixin.py b/python/sglang/srt/managers/scheduler_profiler_mixin.py index 0f78155ed..f9f3e1215 100644 --- a/python/sglang/srt/managers/scheduler_profiler_mixin.py +++ b/python/sglang/srt/managers/scheduler_profiler_mixin.py @@ -28,7 +28,7 @@ logger = logging.getLogger(__name__) class SchedulerProfilerMixin: def init_profiler(self): self.torch_profiler = None - self.torch_profiler_output_dir: Optional[str] = None + self.torch_profiler_output_dir: Optional[Path] = None self.profiler_activities: Optional[List[str]] = None self.profile_id: Optional[str] = None self.profiler_start_forward_ct: Optional[int] = None @@ -69,7 +69,7 @@ class SchedulerProfilerMixin: if activities is None: activities = ["CPU", "GPU"] - self.torch_profiler_output_dir = output_dir + self.torch_profiler_output_dir = Path(output_dir).expanduser() self.torch_profiler_with_stack = with_stack self.torch_profiler_record_shapes = record_shapes self.profiler_activities = activities @@ -213,8 +213,7 @@ class SchedulerProfilerMixin: message="Profiling is not in progress. Call /start_profile first.", ) - if not Path(self.torch_profiler_output_dir).exists(): - Path(self.torch_profiler_output_dir).mkdir(parents=True, exist_ok=True) + self.torch_profiler_output_dir.mkdir(parents=True, exist_ok=True) stage_suffix = f"-{stage.name}" if stage else "" logger.info("Stop profiling" + stage_suffix + "...")