Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup codebase: removed unnecessary code/logic #298

Merged
merged 1 commit into from
Mar 23, 2024
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
8 changes: 6 additions & 2 deletions python/sglang/srt/managers/router/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ async def loop_for_forward(self):
self.send_to_detokenizer.send_pyobj(obj)

# async sleep for receiving the subsequent request and avoiding cache miss
slept = False
if len(out_pyobjs) != 0:
has_finished = any([obj.finished for obj in out_pyobjs])
if has_finished:
await asyncio.sleep(self.extend_dependency_time)
if self.extend_dependency_time > 0:
slept = True
await asyncio.sleep(self.extend_dependency_time)

await asyncio.sleep(0.0006)
if not slept:
await asyncio.sleep(0.0006)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Did you find this give better performance?
  2. @hnyls2002 please also take a look

Copy link
Contributor Author

@Qubitium Qubitium Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. In my limited testing with low concurrency (1-2 concurrent requests with range 1-10 batches each) I did not find performance diff.

But this is unnecessary code/logic. There is no need to sleep for another 0.6ms (causing potential thread context switch) when it has slept for 30ms in earlier condition extend_dependency_time: float = 0.03.


async def loop_for_recv_requests(self):
while True:
Expand Down
1 change: 0 additions & 1 deletion python/sglang/srt/managers/router/model_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def exposed_init_model(
tokenizer_mode=server_args.tokenizer_mode,
trust_remote_code=server_args.trust_remote_code,
)
self.eos_token_id = self.tokenizer.eos_token_id
self.max_total_num_token = self.model_runner.max_total_num_token
self.max_num_running_seq = self.max_total_num_token // 2
self.max_prefill_num_token = max(
Expand Down
7 changes: 2 additions & 5 deletions python/sglang/srt/managers/tokenizer_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ReqState:
out_list: List
finished: bool
event: asyncio.Event
lock: asyncio.Lock


global global_processor
Expand Down Expand Up @@ -178,9 +177,8 @@ async def generate_request(self, obj: GenerateReqInput):
)
self.send_to_router.send_pyobj(tokenized_obj)

lock = asyncio.Lock()
event = asyncio.Event()
state = ReqState([], False, event, lock)
state = ReqState([], False, event)
self.rid_to_state[rid] = state

while True:
Expand Down Expand Up @@ -221,9 +219,8 @@ async def generate_request(self, obj: GenerateReqInput):
)
self.send_to_router.send_pyobj(tokenized_obj)

lock = asyncio.Lock()
event = asyncio.Event()
state = ReqState([], False, event, lock)
state = ReqState([], False, event)
self.rid_to_state[rid] = state

output_list = []
Expand Down