[None][perf] executor: memcpy int32 token buffer into tle::Request ctor#15211
Draft
hyukn wants to merge 1 commit into
Draft
[None][perf] executor: memcpy int32 token buffer into tle::Request ctor#15211hyukn wants to merge 1 commit into
hyukn wants to merge 1 commit into
Conversation
RpcWorker.submit constructs a tle::Request from prompt_token_ids on a GIL-held thread; nanobind casts the Python list[int] -> std::vector<int32> element-by-element (one PyLong read per token). This is O(ISL) and, in the decode phase (short forward steps), the submit thread stalls the executor loop on the GIL (~15.7 ms/iter observed in nsys). Add a buffer fast-path to the Request constructor: a 1-D contiguous int32 ndarray is memcpy'd into VecTokens (no per-element cast); list[int] still works via the default sequence cast, so the change is back-compatible. base_worker._enqueue_request passes prompt_token_ids straight through when it is already an ndarray. This is the construction-path complement to NVIDIA#15134, which bytes-encodes Request pickling (the DP/TP broadcast). Here we target Request construction on the RpcWorker.submit / _enqueue_request path, which NVIDIA#15134 does not touch. NOTE: the C++ change requires a rebuild to verify (not built in this env). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Yukun He <23156053+hyukn@users.noreply.github.com>
Collaborator
Author
|
/bot run --disable-fail-fast |
Collaborator
|
PR_Github #53284 [ run ] triggered by Bot. Commit: |
Collaborator
|
PR_Github #53284 [ run ] completed with state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
RpcWorker.submit→BaseWorker._enqueue_requestbuilds atle::Requestfromprompt_token_idson a GIL-held thread. nanobind casts the Pythonlist[int]→std::vector<int32>element-by-element (one PyLong read per token), which is O(ISL). In the decode phase (short forward steps, host-bound iteration) the submit thread's per-element cast stalls the PyExecutor loop on the GIL (~15.7 ms/iter observed in nsys on a disagg GEN worker).This PR adds a buffer fast-path to the
Requestconstructor binding: a 1-D contiguous int32ndarrayismemcpy'd intoVecTokens(no per-element cast).list[int]still works via the default sequence cast, so the change is back-compatible. On the Python side,_enqueue_requestpassesprompt_token_idsstraight through when it is already an ndarray.Microbenchmark (numpy proxy; real bindings not built in dev env)
Per-submit token handling: the current
list→vectorcast is O(ISL) (≈4 µs @128 → ≈480 µs @16k tokens); the fixedint32 buffer → memcpyis bandwidth-bound (low single-digit µs) → ~12×–240× on that component. Activates when tokens reach the worker as a buffer (e.g. bytes-serialized request on the wire); no-op and back-compatible otherwise.Status / TODO (draft)
try_cast/ndarrayusage compiles.feat/deepseek_v4alone the fast-path is dormant (tokens arrive aslist); the win is realized when paired with bytes-on-the-wire request serialization (keeps tokens as ndarray end-to-end).Test Coverage
TBD — back-compatible path is exercised by existing executor tests; buffer path needs a unit test passing an int32 ndarray to
tllm.Request.🤖 Generated with Claude Code