Add text-only mode support for Qwen 3.5 model builder - #2157
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for building and running Qwen 3.5 as a standalone text-only LLM (without multimodal embedding/vision pipeline), including runtime-side fixes to avoid incorrectly injecting input_ids into decoders that only accept inputs_embeds.
Changes:
- Add “text-only mode” to the Qwen 3.5 builder, including 2D
position_idssupport with internal expansion for mRoPE and a tokenizer-regex post-export patch. - Fix multimodal runtime logic to check decoder inputs against decoder-only session metadata (avoids false positives from the embedding session).
- Register
qwen3_5_textas an LLM model type in C++.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/python/py/models/builders/qwen.py | Adds text-only build path for Qwen 3.5, adjusts position_ids handling, and patches exported tokenizer regex. |
| src/models/multi_modal.cpp | Refines decoder input detection to avoid injecting input_ids when the decoder session doesn’t accept it. |
| src/models/model_type.h | Adds qwen3_5_text to the LLM model-type allowlist. |
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
apsonawane
enabled auto-merge (squash)
May 20, 2026 22:36
kunal-vaishnavi
approved these changes
May 21, 2026
baijumeswani
pushed a commit
that referenced
this pull request
May 23, 2026
This PR enables Qwen3.5 text-only INT4 QDQ export and TRT-RTX EP inference with CUDA graph/shared past-present buffers. ## Structure The branch is rebased on latest `main` and intentionally split into two commits: 1. `Add Qwen3.5 text-only export support` - Mirrors the overlapping Qwen3.5 text-only builder/model-type work from PR #2157. - Keeps Qwen3.5 text-only ONNX input `position_ids` as `[B, S]` and expands inside the graph to `[3, B, S]` for mRoPE. 2. `Enable Qwen3.5 TRT-RTX shared-buffer inference` - Shares Qwen3.5 recurrent/conv state buffers when `past_present_share_buffer` is enabled, preserving stable input/output addresses for TRT-RTX graph replay. - Fixes QDQ SkipLayerNorm `output_3` producer wiring. - Keeps mixed-precision quantization logic in the shared base `k_quant_linear` path rather than Qwen-local code. - Adds the canonical `NvTensorRtRtx` name to the example EP choices. ## PR #2157 compatibility This branch was compared against #2157 using `git merge-tree`. The same Qwen files are touched, but Git auto-merges them cleanly and the simulation produced no conflict markers. If #2157 merges first, the first commit in this branch is the overlap and can be dropped/rebased away; the second commit contains the TRT-RTX-specific delta. ## Validation - Rebased onto latest upstream `main` (`bf6cf3fe`). - Built CUDA Release wheel with CUDA 13.2: `python build.py --use_cuda --cuda_home="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.2" --config Release --update --build --parallel --skip_tests --skip_examples` - Installed the rebuilt wheel in the minimal TRT-RTX package environment. - Exported and ran Qwen3.5 0.8B and 9B text-only INT4 QDQ models with TRT-RTX EP + CUDA graph enabled. - 0.8B: TTFT 1.18s, decode 64.44 tok/s, answer starts: "The history of artificial intelligence..." - 9B: TTFT 1.47s, decode 48.00 tok/s, answer is a coherent reasoning-style response.
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
Adds support for running Qwen 3.5 as a standalone text-only LLM (without vision/embedding pipelines).
Changes
exclude_embeds=false, the builder creates a 2D[B, S]position_ids graph input and internally expands it to 3D[3, B, S]for mRoPE compatibility. This allows the standard onnxruntime-genai runtime to provide position_ids without requiring the multimodal pipeline.save_processingoverride that patches unsupported\p{M}(Unicode Mark category) from tokenizer regex patterns after export. The C++std::regexengine in onnxruntime-extensions does not support this Unicode property class._pos_ids_3dattribute soself.input_names["position_ids"]remains as"position_ids"— ensuring genai_config.json references the actual graph input.Usage