Skip to content

Conversation

SamitHuang
Copy link
Contributor

@SamitHuang SamitHuang commented Sep 12, 2025

Purpose

This PR supplements fused RMSNorm for GLM4.1 vision language model. As discussed in #22184, this optimization can simplify the computation trace and enable further optimizations for the vision encoder.

related to #23884

Test Plan

Test the performance change using the vllm benchmark tool on VisionArena data, with the following settings:

# online serving
vllm serve ZhipuAI/GLM-4.1V-9B-Thinking \
  --host 0.0.0.0 \
  --port 8000 \
  --limit-mm-per-prompt '{"image":2,"video":0}' \
  --no-enable-prefix-caching \
# benchmark
vllm bench serve \
  --host 0.0.0.0 \
  --port 8000 \
  --backend openai-chat \
  --endpoint /v1/chat/completions \
  --endpoint-type openai-chat \
  --model ZhipuAI/GLM-4.1V-9B-Thinking \
  --dataset-name hf \
  --dataset-path lmarena-ai/VisionArena-Chat  \
  --seed 42 \
  --num-prompts 1000 \

Test Result

before:

============ Serving Benchmark Result ============
Successful requests:                     1000
Benchmark duration (s):                  151.32
Total input tokens:                      100608
Total generated tokens:                  127697
Request throughput (req/s):              6.61
Output token throughput (tok/s):         843.87
Total Token throughput (tok/s):          1508.72
---------------Time to First Token----------------
Mean TTFT (ms):                          66172.22
Median TTFT (ms):                        56837.92
P99 TTFT (ms):                           144176.81
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          238.06
Median TPOT (ms):                        265.18
P99 TPOT (ms):                           369.99
---------------Inter-token Latency----------------
Mean ITL (ms):                           240.68
Median ITL (ms):                         241.09
P99 ITL (ms):                            2159.38
==================================================

after

============ Serving Benchmark Result ============
Successful requests:                     1000
Benchmark duration (s):                  151.90
Total input tokens:                      100608
Total generated tokens:                  127702
Request throughput (req/s):              6.58
Output token throughput (tok/s):         840.72
Total Token throughput (tok/s):          1503.06
---------------Time to First Token----------------
Mean TTFT (ms):                          65255.95
Median TTFT (ms):                        56000.47
P99 TTFT (ms):                           144785.38
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          241.27
Median TPOT (ms):                        251.34
P99 TPOT (ms):                           358.06
---------------Inter-token Latency----------------
Mean ITL (ms):                           243.91
Median ITL (ms):                         275.00
P99 ITL (ms):                            1954.20
==================================================

Note that the Mean TTFT is reduced by 916.27ms (66172.22 to 65255.95ms), corresponding to the gain in encode and prefill stage.


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Signed-off-by: SamitHuang <285365963@qq.com>
Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors.

You ask your reviewers to trigger select CI tests on top of fastcheck CI.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

🚀

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces fused RMSNorm in the GLM4.1-VL model, aiming to simplify computation and enable further optimizations. The code changes involve modifying the forward function in glm4_1v.py to incorporate the fused RMSNorm operation. A review comment is provided to address a potential correctness issue.

Comment on lines +430 to +431
x_fused_norm, residual = self.norm2(x, residual=x_attn)
x = residual + self.mlp(x_fused_norm)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The original code x = residual + self.mlp(x_fused_norm) might introduce a correctness issue. It seems that the residual x from the input of norm2 is not considered in the calculation. It is crucial to add the initial x before applying the MLP to maintain the residual connection properly. This could lead to incorrect results in the model's output.

Consider changing the calculation to x = x + residual + self.mlp(x_fused_norm) to address this issue.

x = x + residual + self.mlp(x_fused_norm)

@SamitHuang SamitHuang changed the title [Model] Switch to Fused RMSNorm in GLM4.1-VL model [Model] Switch to Fused RMSNorm in GLM-4.1V model Sep 12, 2025
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) September 12, 2025 13:45
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Sep 12, 2025
@vllm-bot vllm-bot merged commit f17c075 into vllm-project:main Sep 12, 2025
8 of 16 checks passed
@DarkLight1337
Copy link
Member

Main is broken, let me just merge this

skyloevil pushed a commit to skyloevil/vllm that referenced this pull request Sep 13, 2025
dsxsteven pushed a commit to dsxsteven/vllm_splitPR that referenced this pull request Sep 15, 2025
bbartels pushed a commit to bbartels/vllm that referenced this pull request Sep 15, 2025
Signed-off-by: SamitHuang <285365963@qq.com>
Signed-off-by: bbartels <benjamin@bartels.dev>
FeiDaLI pushed a commit to FeiDaLI/vllm that referenced this pull request Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants