Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/sglang/srt/managers/io_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ class ProfileReq:
activities: Optional[List[str]] = None
with_stack: Optional[bool] = None
record_shapes: Optional[bool] = None
profile_id: Optional[str] = None


@dataclass
Expand Down
11 changes: 8 additions & 3 deletions python/sglang/srt/managers/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ def __init__(
self.torch_profiler = None
self.torch_profiler_output_dir: Optional[str] = None
self.profiler_activities: Optional[List[str]] = None
self.profiler_id: Optional[str] = None
self.profiler_target_forward_ct: Optional[int] = None

# Init metrics stats
Expand Down Expand Up @@ -1805,6 +1806,7 @@ def profile(self, recv_req: ProfileReq):
recv_req.activities,
recv_req.with_stack,
recv_req.record_shapes,
recv_req.profile_id,
)
else:
return self.stop_profile()
Expand All @@ -1816,6 +1818,7 @@ def start_profile(
activities: Optional[List[str]],
with_stack: Optional[bool],
record_shapes: Optional[bool],
profile_id: Optional[str],
) -> None:
if self.profiler_activities:
return ProfileReqOutput(
Expand All @@ -1830,9 +1833,11 @@ def start_profile(

self.torch_profiler_output_dir = output_dir
self.profiler_activities = activities
self.profiler_id = profile_id
logger.info(
"Profiling starts. Traces will be saved to: %s",
"Profiling starts. Traces will be saved to: %s (with id %s)",
self.torch_profiler_output_dir,
self.profiler_id,
)

activity_map = {
Expand Down Expand Up @@ -1874,14 +1879,14 @@ def stop_profile(self) -> None:
self.torch_profiler.export_chrome_trace(
os.path.join(
self.torch_profiler_output_dir,
str(time.time()) + f"-TP-{self.tp_rank}" + ".trace.json.gz",
self.profiler_id + f"-TP-{self.tp_rank}" + ".trace.json.gz",
)
)

if "MEM" in self.profiler_activities:
memory_profile_path = os.path.join(
self.torch_profiler_output_dir,
str(time.time()) + f"-TP-{self.tp_rank}-memory" + ".pickle",
self.profiler_id + f"-TP-{self.tp_rank}-memory" + ".pickle",
)
torch.cuda.memory._dump_snapshot(memory_profile_path)
torch.cuda.memory._record_memory_history(enabled=None)
Expand Down
1 change: 1 addition & 0 deletions python/sglang/srt/managers/tokenizer_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ async def start_profile(
output_dir=output_dir,
num_steps=num_steps,
activities=activities,
profile_id=str(time.time()),
)
result = (await self.start_profile_communicator(req))[0]
if not result.success:
Expand Down
Loading