[None][perf] Offload chat template rendering to the input-processor pool - #16231
Closed
lingjiew wants to merge 1 commit into
Closed
[None][perf] Offload chat template rendering to the input-processor pool#16231lingjiew wants to merge 1 commit into
lingjiew wants to merge 1 commit into
Conversation
Port of the AgentX chat-frontend fastpath (fork commit 346c3d6) onto main. Most of the original patch has since been absorbed upstream in other forms: the prompt is rendered once, tokenization runs on the dedicated _input_proc_executor via the generator preprocess path, and orchestrator-relayed requests bypass text entirely via prompt_token_ids_b64. The one piece still missing on main is the chat template render itself: apply_chat_template() is pure-CPU jinja + python work that runs synchronously on the asyncio event loop and grows with conversation length (hundreds of ms per request for ~100k-token agentic chats). In closed-loop AgentX serving at concurrency 32 the single-threaded frontend saturated and this stage inflated to 3.82 s mean / 10.9 s p99 of queueing (45% of TTFT); moving the render+tokenize work off the loop recovered +57% requests/s on the fork stack (GB300, Qwen3.5-397B, 256k-context traces). This change dispatches the render to the existing input-processor thread pool, mirroring the preprocess offload a few lines below. The multimodal encoder endpoint keeps its synchronous render (cold path). Signed-off-by: Lingjie Wu <lingjiew@nvidia.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Offload OpenAI chat-template rendering (
apply_chat_template) from the asyncio event loop to the existing_input_proc_executorthread pool in the chat completions path.This is the main-branch port of an AgentX serving fastpath originally developed and validated on the
qwen3.5_agentxfork (fork commit346c3d6bc8, fork PR nv-guomingz#7). Most of the original patch has since been absorbed into main in other forms — the prompt is rendered once, tokenization runs on the dedicated input-processor pool via the generatorpreprocesspath, and orchestrator-relayed requests bypass text entirely viaprompt_token_ids_b64. The one piece still missing on main is the template render itself, which remains synchronous on the event loop.Motivation / measurements (fork stack, GB300, Qwen3.5-397B, 256k-context agentic traces)
/perf_metricsfive-stage timestamps.What changed
tensorrt_llm/serve/openai_server.py: theapply_chat_template(...)call in the chat completions handler is dispatched vialoop.run_in_executor(self._input_proc_executor, ...), mirroring thepreprocessoffload a few lines below. No behavior change otherwise.Deliberately NOT ported from the fork patch
reusable_prompt_lenplumbing, so these are moot here.preprocess->PreprocessedInputspath.openai_mm_encoder) keeps its synchronous render — cold path.Test Coverage
Draft until re-validated on main: the fork-stack A/B was measured with aiperf closed-loop AgentX traces; I plan to rerun a like-for-like A/B on a main build. Thread-safety of
apply_chat_templateunder concurrent rendering was exercised on the fork at concurrency 32 for 3600 s runs without incident.PR Checklist
[ticket][type]convention🤖 Generated with Claude Code