Skip to content

perf: token-level multimodal mm token expansion. - #2268

Open
kongweiqian wants to merge 1 commit into
xLLM-AI:mainfrom
kongweiqian:perf/vlm-mm-token-expansion
Open

perf: token-level multimodal mm token expansion.#2268
kongweiqian wants to merge 1 commit into
xLLM-AI:mainfrom
kongweiqian:perf/vlm-mm-token-expansion

Conversation

@kongweiqian

Copy link
Copy Markdown

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_seconds for multimodal requests—especially those with high-resolution or multi-image inputs—while producing identical token_ids and span metadata.

A new mm_prompt_expansion_latency_seconds counter is added to track the expansion step independently.

Related Issues

N/A

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactor
  • Documentation
  • Test
  • Build or CI

Pull Request Checklist

PR Title and Commit Messages

  • The PR title and each commit message follow the xLLM commit format: <type>: <subject>.

Pre-commit Checks

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

Self Review

  • I have self-reviewed the code according to .agents/skills/code-review/references/custom-code-style.md, especially code written or assisted by AI.
  • I have rebased this PR onto the latest main branch.

Build and Test Coverage

  • Tests have been added or updated as needed.
  • CUDA: python setup.py build test has passed on a CUDA machine.
  • NPU: python setup.py build test has passed on an NPU machine.
  • MLU: python setup.py build test has passed on an MLU machine.

Reviewer Notes

This PR touches xllm/processors/ (prompt processors for GLM4V, Qwen2-VL, Qwen3-VL) and xllm/core/common/metrics.*.

Validated on NPU (Ascend 910) with Qwen2.5-VL-3B:

  • Correctness: new token-level path produces identical token_ids and multimodal span offsets vs. legacy string-expand path across 256×256 to 2048×2048 resolutions.
  • Performance: up to 4× reduction in tokenization latency for 2048×2048 images; no regression for text-only prompts.
  • Multi-image ordering preserved (verified with 5-image interleaved prompts).

@weizhehuang0827 weizhehuang0827 changed the title perf: token-level multimodal mm token expansion perf: token-level multimodal mm token expansion. Aug 19, 2026
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