Skip to content

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
NVIDIA:mainfrom
rain-sicoreai:feat/experimental-server-batching-fp8kv-mtp
Open

feat: Add request batching and spec tree-size options to the experimental server, fix FP8-KV and unquantized MTP draft builds#199
rain-sicoreai wants to merge 4 commits into
NVIDIA:mainfrom
rain-sicoreai:feat/experimental-server-batching-fp8kv-mtp

Conversation

@rain-sicoreai

Copy link
Copy Markdown

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-serve hit three problems, fixed here in three commits:

  1. fix: draft KV-cache input dtype — the direct builder's draft models (Qwen3.5 MTP, Qwen3-Omni MTP, EAGLE3, DFlash, dSpark) declared past_key_values as 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 follows kv_cache_quant, as the base text models already do.
  2. fix: draft namespace resolution — a Qwen3.5 MTP draft resolves tensors under 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's layers.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.
  3. feat: request batching and spec tree-size options--enable-batching merges 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-ms and --max-queue-batch-size tune it, /health reports it, and the admission controller admits the batch size of leases when enabled. --max-verify-tree-size / --max-draft-tree-size are 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):

before after
single request 45–49 tok/s 45–49 tok/s
4 concurrent requests 47 tok/s aggregate (serialized) 143 tok/s aggregate
MTP tree 9 vs default 60, memory in use ~103 GB ~73 GB

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

  • I have installed pre-commit by running pip install pre-commit.
  • I have installed the hooks with pre-commit install.
  • I have run the hooks manually with pre-commit run --all-files and fixed any reported issues.

🧪 Tests

  • Tests have been added or updated as needed (tests/python-unittests/test_server_batching.py, tests/python-unittests/test_direct_builder_draft_quant.py).
  • All tests are passing (server and builder unit tests pass in the Thor container image; end-to-end build + serve verified for a uniform-NVFP4 checkpoint with quantized MTP draft and for a mixed-precision checkpoint with an unquantized MTP draft).

📄 Documentation

  • Updated docs/source/user_guide/examples/experimental-server.md (Runtime Concurrency section).

⚙️ Compatibility

  • The change is backward compatible: batching is opt-in; tree-size flags default to the builder's previous behaviour; the resolver change only affects modules whose sidecars are absent in their own namespace.

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.

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]>
@rain-sicoreai
rain-sicoreai requested a review from a team September 8, 2026 10:45
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]>
@nvamberl

nvamberl commented Sep 9, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants