Skip to content
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ab6c783
more
fzyzcjy Mar 23, 2025
ed5d169
more
fzyzcjy Mar 23, 2025
cc64d08
more
fzyzcjy Mar 23, 2025
a2ae2a5
more
fzyzcjy Mar 23, 2025
5c82101
more
fzyzcjy Mar 23, 2025
82c241a
fmt
fzyzcjy Mar 23, 2025
3e2caf6
more
fzyzcjy Mar 23, 2025
9e635f8
Merge branch 'main' into feat/profiler_nsys
fzyzcjy Mar 25, 2025
940ee94
more
fzyzcjy Mar 25, 2025
55c6d26
more
fzyzcjy Mar 25, 2025
0b91b49
more
fzyzcjy Mar 25, 2025
db724e0
more
fzyzcjy Mar 25, 2025
8b26690
more
fzyzcjy Mar 25, 2025
bdc8d8c
more
fzyzcjy Mar 25, 2025
0d46f43
more
fzyzcjy Mar 25, 2025
2c90af2
more
fzyzcjy Mar 25, 2025
ed738c9
more
fzyzcjy Mar 25, 2025
1f4c297
fmt
fzyzcjy Mar 25, 2025
9a87dd9
Merge branch 'main' into feat/profiler_stop
fzyzcjy Mar 25, 2025
fd7a103
Merge branch 'main' into feat/profiler_record_shapes
merrymercy Mar 28, 2025
b754c15
Merge remote-tracking branch 'origin/feat/profiler_record_shapes' int…
fzyzcjy Mar 28, 2025
ab27d12
Merge branch 'main-upstream' into feat/profiler_stop
fzyzcjy Mar 28, 2025
4b9ccc9
Merge branch 'main' into feat/profiler_stop
merrymercy Mar 29, 2025
c0839fe
Merge branch 'main' into feat/profiler_stop
fzyzcjy Apr 4, 2025
3df453c
Merge branch 'main' into feat/profiler_stop
fzyzcjy Apr 4, 2025
3045e17
Merge branch 'main' into feat/profiler_stop
fzyzcjy Apr 9, 2025
c8ea773
Merge branch 'main' into feat/profiler_stop
zhyncs Apr 9, 2025
e19b20a
Merge branch 'main' into feat/profiler_stop
fzyzcjy Apr 21, 2025
873ac5f
Update tokenizer_manager.py
fzyzcjy Apr 21, 2025
0c7b91f
Merge branch 'main' into feat/profiler_stop
fzyzcjy May 6, 2025
a0081c5
Merge branch 'main' into feat/profiler_stop
fzyzcjy May 7, 2025
7e057de
Update scheduler.py
fzyzcjy May 7, 2025
fff7ec7
Merge branch 'main' into feat/profiler_stop
zhyncs May 12, 2025
d2477b5
Merge branch 'main' into feat/profiler_stop
zhyncs May 12, 2025
779d353
Merge branch 'main' into feat/profiler_stop
fzyzcjy May 13, 2025
286640a
Merge branch 'main' into feat/profiler_stop
zhyncs May 18, 2025
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
3 changes: 2 additions & 1 deletion python/sglang/srt/entrypoints/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ def start_profile(self):
loop.run_until_complete(self.tokenizer_manager.start_profile())

def stop_profile(self):
self.tokenizer_manager.stop_profile()
loop = asyncio.get_event_loop()
loop.run_until_complete(self.tokenizer_manager.stop_profile())

def get_server_info(self):
loop = asyncio.get_event_loop()
Expand Down
2 changes: 1 addition & 1 deletion python/sglang/srt/entrypoints/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ async def start_profile_async(obj: Optional[ProfileReqInput] = None):
@app.api_route("/stop_profile", methods=["GET", "POST"])
async def stop_profile_async():
"""Stop profiling."""
_global_state.tokenizer_manager.stop_profile()
await _global_state.tokenizer_manager.stop_profile()
return Response(
content="Stop profiling. This will take some time.\n",
status_code=200,
Expand Down
12 changes: 6 additions & 6 deletions python/sglang/srt/managers/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ def run_batch(
self.profiler_target_forward_ct
and self.profiler_target_forward_ct <= self.forward_ct
):
self.stop_profile()
self.send_to_tokenizer.send_pyobj(self.stop_profile())

# Run forward
if self.is_generation:
Expand Down Expand Up @@ -2084,7 +2084,10 @@ def start_profile(

def stop_profile(self) -> None:
if self.profiler_activities is None:
return
return ProfileReqOutput(
success=False,
message="Profiling is already not in progress. Call /start_profile first.",
)

logger.info("Stop profiling...")
if self.torch_profiler is not None:
Expand Down Expand Up @@ -2115,10 +2118,7 @@ def stop_profile(self) -> None:
self.torch_profiler_output_dir = None
self.profiler_activities = None

if self.profiler_target_forward_ct:
self.send_to_tokenizer.send_pyobj(
ProfileReqOutput(success=True, message="Succeeded.")
)
return ProfileReqOutput(success=True, message="Succeeded")

def expert_distribution_handle(self, recv_req: ExpertDistributionReq):
if recv_req == ExpertDistributionReq.START_RECORD:
Expand Down
13 changes: 10 additions & 3 deletions python/sglang/srt/managers/tokenizer_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def __init__(
self.flush_cache_communicator = _Communicator(
self.send_to_scheduler, server_args.dp_size
)
self.start_profile_communicator = _Communicator(
self.profile_communicator = _Communicator(
self.send_to_scheduler, server_args.dp_size
)
self.get_internal_state_communicator = _Communicator(
Expand Down Expand Up @@ -328,7 +328,7 @@ def __init__(
),
(
ProfileReqOutput,
self.start_profile_communicator.handle_recv,
self.profile_communicator.handle_recv,
),
(
GetInternalStateReqOutput,
Expand Down Expand Up @@ -746,7 +746,14 @@ async def start_profile(
activities=activities,
profile_id=str(time.time()),
)
result = (await self.start_profile_communicator(req))[0]
return await self._execute_profile(req)

async def stop_profile(self):
req = ProfileReq(type=ProfileReqType.STOP_PROFILE)
return await self._execute_profile(req)

async def _execute_profile(self, req: ProfileReq):
result = (await self.profile_communicator(req))[0]
if not result.success:
raise RuntimeError(result.message)
return result
Expand Down