mirror of
https://github.com/kvcache-ai/sglang.git
synced 2026-07-13 02:46:57 +00:00
Fix: Add token heuristic increment in total_tokens load balancing (#22614)
This commit is contained in:
@@ -98,7 +98,7 @@ class DPBudget:
|
||||
)
|
||||
self.total_tokens[load.dp_rank] = load.num_total_tokens
|
||||
|
||||
def dispatch(self, method: LoadBalanceMethod):
|
||||
def dispatch(self, method: LoadBalanceMethod, estimated_tokens: int = 0):
|
||||
if method == LoadBalanceMethod.TOTAL_REQUESTS:
|
||||
target_rank = self.total_requests.index(min(self.total_requests))
|
||||
elif method == LoadBalanceMethod.TOTAL_TOKENS:
|
||||
@@ -112,6 +112,7 @@ class DPBudget:
|
||||
|
||||
# Increment the load of that worker by one as a heuristic
|
||||
self.total_requests[target_rank] += 1
|
||||
self.total_tokens[target_rank] += estimated_tokens
|
||||
return target_rank
|
||||
|
||||
|
||||
@@ -584,7 +585,10 @@ class DataParallelController:
|
||||
def total_tokens_scheduler(self, req: Req):
|
||||
if self.maybe_external_dp_rank_routing(req):
|
||||
return
|
||||
target_worker = self.dp_budget.dispatch(LoadBalanceMethod.TOTAL_TOKENS)
|
||||
estimated_tokens = len(req.input_ids)
|
||||
target_worker = self.dp_budget.dispatch(
|
||||
LoadBalanceMethod.TOTAL_TOKENS, estimated_tokens=estimated_tokens
|
||||
)
|
||||
self.workers[target_worker].send_pyobj(req)
|
||||
|
||||
def event_loop(self):
|
||||
|
||||
Reference in New Issue
Block a user