Skip to content

Commit 2862ef6

Browse files
authored
[None][perf] reduce rank-0 GIL contention in disaggregated generation (#15133)
Signed-off-by: Lance Liao <108499334+lancelly@users.noreply.github.com>
1 parent f04f90e commit 2862ef6

2 files changed

Lines changed: 13 additions & 19 deletions

File tree

tensorrt_llm/_torch/distributed/communicator.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,12 @@ def safe_broadcast(comm, obj, root=0, chunk_size: int = 4 * 1024 * 1024):
308308
offset += cur
309309

310310
# ---- Reconstruction and deserialization ----
311-
# Validate the received byte count and unpickle.
312311
if rank == root:
313-
# Root already has `serialized`
314-
if len(serialized) != total_size:
315-
raise RuntimeError(
316-
f"Data size mismatch at root: expected {total_size}, got {len(serialized)}"
317-
)
318-
try:
319-
return pickle.loads(serialized) # nosec B301
320-
except Exception as e:
321-
raise RuntimeError(f"Deserialization failed: {str(e)}") from e
312+
# Root already holds `obj`; rebuilding it from its own serialized bytes
313+
# would be a needless deep copy.
314+
return obj
322315
else:
316+
# Validate the received byte count and unpickle.
323317
if len(dst_buf) != total_size:
324318
raise RuntimeError(
325319
f"Data size mismatch at rank {rank}: expected {total_size}, got {len(dst_buf)}"

tensorrt_llm/_torch/pyexecutor/scheduler/adp_router.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,17 @@ def _balance_requests_across_ranks(
369369

370370
heapq.heapify(all_ranks_new_requests_heap)
371371

372-
new_requests = sorted(
373-
new_requests,
374-
key=lambda x: len(getattr(x.request, "input_token_ids", [])) if x.request else 0,
375-
reverse=True,
376-
)
372+
# input_token_ids is a C++ getter that copies the whole token list on every
373+
# access, so read it once per request instead of in both the sort key and
374+
# the loop below.
375+
counted = [
376+
(len(req.input_token_ids) if (req := item.request) is not None else 0, item)
377+
for item in new_requests
378+
]
379+
counted.sort(key=lambda item: item[0], reverse=True)
377380

378-
for req_item in new_requests:
381+
for token_count, req_item in counted:
379382
val = heapq.heappop(all_ranks_new_requests_heap)
380-
token_count = (
381-
len(getattr(req_item.request, "input_token_ids", [])) if req_item.request else 0
382-
)
383383
val = val._replace(
384384
num_tokens=val.num_tokens + token_count,
385385
num_requests=val.num_requests + 1,

0 commit comments

Comments
 (0)