feat: Add request batching and spec tree-size options to the experimental server, fix FP8-KV and unquantized MTP draft builds - #199
Open
rain-sicoreai wants to merge 4 commits into
Conversation
The direct builder's speculative draft models (Qwen3.5 MTP, Qwen3-Omni MTP, EAGLE3, DFlash, dSpark) declared their past_key_values inputs as FP16 unconditionally, while the attention plugin they feed is created with enable_fp8_kv_cache taken from the checkpoint's kv_cache_quant. For an FP8 KV checkpoint no tensor format satisfied both, and TensorRT failed the draft build with "Failed to find any supported plugin/custom tactic format". Select the KV input dtype from the config exactly as the base text models already do. Verified by building and serving Qwen3.8-27B (ModelOpt NVFP4, FP8 KV) with MTP on Jetson AGX Thor through tensorrt-edgellm-serve. Signed-off-by: Rain Zhang <[email protected]>
A Qwen3.5 MTP draft resolves its tensors under the mtp. checkpoint namespace but shares the short module names of the base model. Two lookups leaked across that boundary when the draft layer was left unquantized (ModelOpt mixed-precision checkpoints such as RadixArk/Qwen3.8-27B-NVFP4): - module_quant_type classified layers.0.mlp.gate_proj by the base layer-0 override (NVFP4) although mtp.layers.0.mlp.gate_proj is a plain BF16 tensor, so the loader decoded BF16 bytes as packed FP4 and the draft network failed with mismatched matmul shapes. - Sidecar probes (weight_scale, input_scale, bias, k_scale, ...) resolved through candidate fallback, so the base namespace answered for sidecars the draft module does not have. Pin module sidecars to the namespace where the module's primary weight resolves, and treat a bare weight without quantization sidecars as FP16 regardless of a same-named override. lm_head is excluded from the plain check because its resolution consults module_quant_type for embedding tying. Signed-off-by: Rain Zhang <[email protected]>
…ntal server Request batching: concurrent non-streaming requests whose generation settings match (sampling, max_tokens, template and thinking flags, speculative-decoding and context-cache options) are merged into one runtime call of up to the engine's max batch size and split back per caller. Decode is memory-bandwidth bound, so the rows of a batch cost little more than one request. Enabled with --enable-batching; tuned with --batch-timeout-ms and --max-queue-batch-size. Streaming requests still run one at a time. The admission controller now allows the batch size of concurrent leases when batching is on, and /health reports the batching state. Default behaviour is unchanged. Tree size: tensorrt-edgellm-serve never forwarded verify/draft tree sizes to the direct builder, so MTP bundles defaulted to 60 positions and the runtime allocated spec-verify state for all of them (about 0.9 GB per position for a 27B hybrid model at batch 4). Add --max-verify-tree-size and --max-draft-tree-size, forwarded to the builder and included in the bundle cache key. Measured on Jetson AGX Thor with Qwen3.8-27B NVFP4, MTP draft step 5, coding prompts: 4 concurrent requests went from 47 tok/s aggregate (serialized) to 143 tok/s; single-request speed unchanged at 45-49 tok/s. Signed-off-by: Rain Zhang <[email protected]>
The direct builder extracts runtime role prefixes by rendering probe conversations through the checkpoint's Jinja chat template. It passed no enable_thinking flag, and Qwen3.8's template treats an undefined flag as thinking enabled: it injects reasoning instructions into the system block and emits a different generation prompt. The prefix/suffix extraction then misaligned, producing a processed_chat_template.json whose system and user prefixes carried the reasoning instruction, whose system suffix swallowed a user turn, and whose generation prompt began with literal <placeholder_system_prompt> / <placeholder_user_text> text. Every request served from such a bundle was rendered with that corrupted prompt (140 prompt tokens instead of 33 for a two-message chat) and answered noticeably worse than the ONNX-export path, whose extractor probes with thinking off. Render probes with enable_thinking=False by default (falling back for tokenizers that reject the argument) and slice the thinking generation prompt against a thinking-mode baseline, matching tensorrt_edgellm/chat_template.py. The regenerated template for Qwen3.8-27B is identical to the ONNX-path one. Signed-off-by: Rain Zhang <[email protected]>
|
Thanks for the detailed report. We confirmed (1) and (2) against our current main — both are real bugs, and they'll be fixed in the next release, along with your chat-template fix. We'll follow up here once it ships. On (3): thanks, but we'll pass on this one. We're implementing in-flight batching natively in the runtime instead — targeting vanilla IFB in 0.11.0 and speculative-decoding support in 0.12.0 — so we'd rather not add a second batching path in the server that it would supersede. |
7 tasks
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.
What does this PR do?
Type of change: Bug fix + new feature (experimental server and direct builder)
Overview:
Serving a ModelOpt NVFP4 checkpoint with FP8 KV cache and native MTP drafting (Qwen3.8-27B on Jetson AGX Thor) through
tensorrt-edgellm-servehit three problems, fixed here in three commits:past_key_valuesas FP16 unconditionally while the attention plugin was built with FP8 KV from the checkpoint, so TensorRT found no supported format and the draft build failed. The dtype now followskv_cache_quant, as the base text models already do.mtp.but shares short module names with the base. For checkpoints whose draft layer is left unquantized (e.g.RadixArk/Qwen3.8-27B-NVFP4), the draft'slayers.0.mlp.*picked up the base layer-0 NVFP4 override and its sidecars, and BF16 weights were decoded as packed FP4. Module sidecars are now pinned to the namespace where the module's weight resolves, and a bare weight without quantization sidecars is FP16.--enable-batchingmerges concurrent non-streaming requests with matching generation settings into one runtime call (up to the engine's max batch size), splitting the response per caller;--batch-timeout-msand--max-queue-batch-sizetune it,/healthreports it, and the admission controller admits the batch size of leases when enabled.--max-verify-tree-size/--max-draft-tree-sizeare forwarded to the builder and included in the bundle cache key; without them MTP bundles defaulted to 60 positions and the runtime allocated spec-verify state for all of them (~0.9 GB per position for a 27B hybrid model at batch 4). Defaults are unchanged.Measured (Jetson AGX Thor, Qwen3.8-27B ModelOpt NVFP4 + FP8 KV, MTP draft step 5, four coding prompts, 512 tokens):
Vision requests keep working alongside MTP on this path.
Usage
tensorrt-edgellm-serve /models/Qwen3.8-27B-NVFP4 \ --cache-dir /data/edgellm-cache \ --max-batch-size 4 --max-input-len 32768 --max-kv-cache-capacity 65536 \ --max-verify-tree-size 9 --max-draft-tree-size 9 \ --speculative-config '{"method":"mtp","num_speculative_tokens":5}' \ --enable-batching🚀 Pull Request Checklist
✅ Pre-commit Checks
pre-commitby runningpip install pre-commit.pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
tests/python-unittests/test_server_batching.py,tests/python-unittests/test_direct_builder_draft_quant.py).📄 Documentation
docs/source/user_guide/examples/experimental-server.md(Runtime Concurrency section).⚙️ Compatibility
Additional Information
The three commits are independent fixes that were all required to serve one model; they can be split into separate PRs on request.