Skip to content

fix(qwen): require native KV for Qwen3 - #959

Merged
yifeif-nv merged 5 commits into
NVIDIA:mainfrom
yifeif-nv:agent/qwen3-native-fp16
Aug 21, 2026
Merged

yifeif-nv merged 5 commits into
NVIDIA:mainfrom
yifeif-nv:agent/qwen3-native-fp16

Conversation

@yifeif-nv

@yifeif-nv yifeif-nv commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Background

Qwen3 previously fell back to the legacy decoder graph whenever a build request missed the native-KV contract. That made FP16, dynamic KV, and other unsupported modes enter a path that can fail with workspace or TensorRT Myelin errors. The Qwen builders also imposed a fixed 1 GiB workspace cap that excluded valid larger tactics. Related: #955.

Exit Criteria

  • Eligible dense Qwen3 FP16 and BF16 builds use the split fixed-capacity native-KV prefill/decode path.
  • Qwen3 accepts any fixed max_cache_length in [1, max_position_embeddings]; omitting it still selects the model context.
  • Every Qwen3 request outside the native contract fails closed; no Qwen3 build reaches the legacy builder.
  • Qwen3 dynamic KV is rejected before checkpoint weight loading and produces no bundle.
  • Qwen builders retain TensorRT device-sized default WORKSPACE instead of a fixed 1 GiB limit.
  • Qwen, Qwen2, Qwen2.5, and other non-Qwen3 variants retain their existing legacy routes.

Implementation

  • Preserve explicit FP16 through Qwen3 native capability routing, fused IAttention scaling, and C++ runtime cache validation.
  • Allow bounded fixed native KV capacities up to the model context instead of requiring full context.
  • Add a family-owned build-request validation hook so Qwen3 rejects runtime-sized KV before weight loading.
  • Remove the Qwen3 plugin fallback to standard or TP legacy builders and surface the exact native capability reason instead.
  • Remove the explicit 1 GiB WORKSPACE override from standard, dual-profile, and TP Qwen builders so TensorRT uses its device-derived default.
  • Keep the README Quick Start at the validated 16,384-token fixed native capacity.
  • Keep shared legacy builders for older Qwen variants and update CLI, Python API, and Dynamic KV documentation boundaries.

Validation

  • PYTHONPATH=python python -m pytest -q tests/builder/test_cli.py tests/builder/test_qwen_llama_native_kv_attention.py tests/e2e/models/qwen/test_qwen_native_kv_routing.py: 83 passed on exact head 8fe09badd.
  • README command trtmc build Qwen/Qwen3-0.6B --max-cache-length 16384 --output ...: passed on GB300 with BF16 split prefill/decode engines; inspection reported Max cache length: 16384 and Runtime strategy: qwen_decoder_kv_cache; inference produced Paris.
  • Explicit FP16 Native KV also passed full build-and-run smoke on GB300.
  • TensorRT 11.1.0.106 on GB300 reported default WORKSPACE 296889614336 bytes (276.5 GiB), above the issue tactic request 2598728448 bytes.
  • Real Qwen3 command with --precision fp16 --dynamic-kv-cache: failed before weight loading with the actionable Dynamic KV error and created no bundle.
  • ruff check, git diff --check, focused canonical documentation reference checks, model ownership validation, and test-impact validation: passed.
  • Full-site npm build was not run because this isolated checkout has no website/node_modules.
  • The whole-tree doc-reference scan remains blocked by unrelated base issues: missing website/build/ and a stale manifest-count claim.

Notes For Future Readers

  • Qwen3 fixed capacity and Dynamic KV are separate contracts: bounded fixed capacities remain Native; runtime-resizable KV is rejected.
  • This PR removes Qwen3 legacy fallback, not the shared legacy builders used by Qwen2 and Qwen2.5.
  • Leaving WORKSPACE unset restores TensorRT default behavior; it does not preallocate the reported maximum, but permits larger tactics during build.
  • SM120/SM121 runtime proof and full HF logits/token parity were not run. Current target-hardware evidence is GB300/SM103 build-and-run smoke.

@yifeif-nv yifeif-nv changed the title fix(qwen): keep FP16 on native KV path fix(qwen): require native KV for Qwen3 Aug 21, 2026
@yifeif-nv
yifeif-nv marked this pull request as ready for review August 21, 2026 04:41
@yifeif-nv yifeif-nv added the run-internal-ci Maintainer-approved dispatch to internal CI label Aug 21, 2026
@github-actions github-actions Bot removed the run-internal-ci Maintainer-approved dispatch to internal CI label Aug 21, 2026
Allow eligible dense Qwen3 FP16 builds to preserve the requested dtype across native KV routing, fused attention, and runtime cache validation. Fail closed when native construction fails instead of falling back to the legacy masked-attention graph.

Refs: NVIDIA#955
Signed-off-by: yifeif <[email protected]>
Require every Qwen3 build to satisfy the fixed-capacity native KV contract. Reject dynamic KV before weight loading, preserve legacy routing for older Qwen variants, and align the public CLI and Python documentation.

Refs: NVIDIA#955
Signed-off-by: yifeif <[email protected]>
Remove the fixed 1 GiB workspace cap from every Qwen decoder builder so TensorRT can use its device-sized default and keep larger valid tactics eligible. Preserve the policy with a source-contract test.

Refs: NVIDIA#955
Signed-off-by: yifeif <[email protected]>
Keep the Quick Start aligned with the full-context native KV contract so the documented Qwen3 build does not request a rejected partial cache.

Refs: NVIDIA#955
Signed-off-by: yifeif <[email protected]>
Accept fixed Qwen3 native KV capacities up to the model context instead of requiring the full context. Keep dynamic KV and legacy fallback disabled while restoring the validated 16,384-token Quick Start.

Refs: NVIDIA#955
Signed-off-by: yifeif <[email protected]>
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.

1 participant