[VLM] Support cos sin cache for Qwen3-VL & GLM-4.1V#15205
[VLM] Support cos sin cache for Qwen3-VL & GLM-4.1V#15205yuan-luo merged 1 commit intosgl-project:mainfrom
Conversation
Summary of ChangesHello @yuan-luo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant optimization to the Rotary Positional Embedding (RoPE) computation within the Qwen3-VL model. By implementing a caching mechanism for cosine and sine tables, the system avoids redundant calculations, particularly for the 2D vision RoPE, leading to more efficient processing and potentially improved inference speed for multimodal tasks. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the rotary positional embedding (RoPE) implementation for Qwen3-VL to use a cosine/sine cache, which is a good performance optimization. The changes are mostly correct and achieve the intended goal. I have a few suggestions for code cleanup and refactoring to improve maintainability and remove dead code.
42fabc7 to
da0c9f4
Compare
|
/tag-and-rerun-ci |
da0c9f4 to
e4aefaf
Compare
e4aefaf to
b3ea3a9
Compare
b3ea3a9 to
44168c8
Compare
44168c8 to
94c6543
Compare
94c6543 to
c196e06
Compare
|
/rerun-failed-ci |
…n3_pp * 'main' of https://github.com/sgl-project/sglang: (74 commits) [bug fix][pp] fix inconsistent latency between tp (sgl-project#15379) Fix warp illegal instruction in kimi k2 thinking PCG (sgl-project#15306) Fix gpt-oss yarn with `truncate` argument (sgl-project#14270) Monkey patch deepseek-ocr's `v_head_dim` (sgl-project#15384) [model-gateway] Replace PolicyRegistry RwLock with DashMap for lock-free policy lookups (sgl-project#15361) [PP] Fix dynamic chunking strategy for PP (sgl-project#15372) Fix issue: ENABLE_BELOW_SM90 cannot be enabled on aarch64 CPU (sgl-project#12967) Split test_piecewise_cuda_graph.py to optimize CI resource usage (sgl-project#15290) unified management of environment variables for vlm cuda ipc transport (sgl-project#14501) Mistral Large 3 NVFP4 TRTLLM MoE support (sgl-project#15049) fix: adjust time for test_epd_disaggregation.py (sgl-project#15354) Add doc for qwen3 next (sgl-project#15337) feat: DeepSeek-V3.2 Streaming tool call output (sgl-project#15278) Feature/trtllm mha workspace size configurable sgl-project#15089 (sgl-project#15131) [VLM] Support cos sin cache for Qwen3-VL & GLM-4.1V (sgl-project#15205) [Deepseek V3.2] Support Overlap Spec + NSA (sgl-project#15307) Add request-level timestamp for when prefill finishes (sgl-project#14860) [CI] Migrate LoRA tests to test/registered/lora/ (sgl-project#15176) Reserve more memory for DeepSeekOCR model and adjust server start timeout for DeepGEMM to reduce flakiness (sgl-project#15277) Fix condition check for require_gathered_buffer (sgl-project#15328) ...
Co-authored-by: luoyuan.luo <luoyuan.luo@antgroup.com>
Co-authored-by: luoyuan.luo <luoyuan.luo@antgroup.com>
Co-authored-by: luoyuan.luo <luoyuan.luo@antgroup.com>
Motivation
Support cos sin cache for Qwen3-VL & GLM-4.1V.
This PR refactors the rotary positional embedding (RoPE) implementation to expose an explicit cosine/sine cache interface and reuse it across the 2D vision RoPE code path. Rather than recomputing frequencies and repeatedly calling cos()/sin(), we precompute and cache the 1D cosine/sine tables once, then index into this cache for both text RoPE and the 2D grid RoPE used by the vision encoder.
Step 1 refactored Qwen3-VL and GLM-4.1V.
Before PR: 490us

After PR: 186us

Inspired by vllm-project/vllm#28798 & vllm-project/vllm#28962.
Modifications
Accuracy Tests
Baseline:
PR:
Benchmarking and Profiling
8xH20
Qwen3-VL-8B-Instruct
TTFT speedup 2%.
Server:
Client:
Checklist