perf: token-level multimodal mm token expansion. - #2268
Open
kongweiqian wants to merge 1 commit into
Open
Conversation
kongweiqian
requested review from
DongheJin,
DragonFive,
JimHsiung,
Kang-Meng,
liujinguang0125,
liutongxuan,
ustcfy,
xiao-yu-chen,
yingxudeng,
yinjiawei01 and
zhang-minchao
as code owners
August 19, 2026 08:09
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
Add token-level multimodal placeholder expansion for VLM prompt processors (Qwen2-VL, Qwen3-VL, GLM4V).
The legacy path performs string-level placeholder insertion followed by a full re-tokenization of the entire prompt. The new path operates directly on the token sequence: it locates placeholder token IDs and expands them in-place with the correct image/video token count, avoiding redundant tokenization work.
This reduces
tokenization_latency_secondsfor multimodal requests—especially those with high-resolution or multi-image inputs—while producing identicaltoken_idsand span metadata.A new
mm_prompt_expansion_latency_secondscounter is added to track the expansion step independently.Related Issues
N/A
Change Type
Pull Request Checklist
PR Title and Commit Messages
<type>: <subject>.Pre-commit Checks
pre-commitby runningpip install pre-commitor an equivalent command.pre-commit install.pre-commit run --all-filesand fixed any reported issues.Self Review
.agents/skills/code-review/references/custom-code-style.md, especially code written or assisted by AI.mainbranch.Build and Test Coverage
python setup.py build testhas passed on a CUDA machine.python setup.py build testhas passed on an NPU machine.python setup.py build testhas passed on an MLU machine.Reviewer Notes
This PR touches
xllm/processors/(prompt processors for GLM4V, Qwen2-VL, Qwen3-VL) andxllm/core/common/metrics.*.Validated on NPU (Ascend 910) with Qwen2.5-VL-3B:
token_idsand multimodal span offsets vs. legacy string-expand path across 256×256 to 2048×2048 resolutions.