Skip to content

[DP encoder] Fix pos_emb layer TP issue when DP encoder enabled for Qwen3 VL#20788

Merged
ispobock merged 2 commits intosgl-project:mainfrom
jianan-gu:fix_emb_dp_encoder
Mar 18, 2026
Merged

[DP encoder] Fix pos_emb layer TP issue when DP encoder enabled for Qwen3 VL#20788
ispobock merged 2 commits intosgl-project:mainfrom
jianan-gu:fix_emb_dp_encoder

Conversation

@jianan-gu
Copy link
Copy Markdown
Contributor

@jianan-gu jianan-gu commented Mar 17, 2026

Issue description:
Enable DP encoder for qwen3-vl model and TP size = 2:

python3 -m sglang.launch_server  --model Qwen/Qwen3-VL-8B-Instruct --trust-remote-code --tp 2  --disable-radix-cache   --mm-enable-dp-encoder

Where DP size shall also be equal to TP size, depending image distribution.
However, in current init code, pos_emb layer in encoder is not correct (https://github.com/sgl-project/sglang/blob/v0.5.9/python/sglang/srt/models/qwen3_vl.py#L308-L313) .
In corner case, where image is total 1 (e.g., sglang server launch warmpup) but total 2 DP encoder, once TP_rank 0 has 1 image as input (and enabled TP), but TP_rank 1 does not have image as input (will not respond to rank0), the pos_emb layer will stuck for waiting.

This PR adds minor fix to correct above issue.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 resolves a specific synchronization problem within the Qwen3-VL model's encoder when operating in a distributed environment that combines data parallelism with tensor parallelism. The change ensures that the positional embedding layer correctly handles its parallelism configuration, preventing deadlocks and improving the robustness of the distributed inference setup.

Highlights

  • Tensor Parallelism (TP) Fix for pos_emb Layer: Addressed a critical issue where the pos_emb layer in the Qwen3-VL model could get stuck or deadlock when the Data Parallel (DP) encoder was enabled alongside Tensor Parallelism (TP), especially in scenarios with uneven image distribution across TP ranks.
  • Conditional Tensor Parallelism Disablement: Implemented a conditional logic to disable tensor parallelism for the pos_emb layer when data parallelism is active, preventing synchronization issues and ensuring correct operation.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • python/sglang/srt/models/qwen3_vl.py
    • Modified the __init__ method of the QwenVLChatProcessor to add an enable_tp argument to the pos_embed layer initialization.
    • Set enable_tp to False if use_data_parallel is True, otherwise set it to True.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@jianan-gu jianan-gu changed the title [DP encoder] Fix pos_emb layer TP issue when DP encoder enabled [DP encoder] Fix pos_emb layer TP issue when DP encoder enabled for Qwen3 VL Mar 17, 2026
Copy link
Copy Markdown
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 addresses a tensor parallelism issue in the pos_emb layer of the vision encoder when data parallelism is enabled. The fix involves conditionally disabling tensor parallelism for this layer, which is a correct approach to prevent hangs in distributed environments with uneven data distribution. My review includes a minor suggestion to improve code readability by simplifying a boolean expression.

Comment thread python/sglang/srt/models/qwen3_vl.py
@ispobock
Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@ispobock ispobock merged commit 21c4fc6 into sgl-project:main Mar 18, 2026
131 of 156 checks passed
Wangzheee pushed a commit to Wangzheee/sglang that referenced this pull request Mar 21, 2026
0-693 pushed a commit to 0-693/sglang that referenced this pull request Mar 25, 2026
dutsc pushed a commit to dutsc/sglang that referenced this pull request Mar 30, 2026
JustinTong0323 pushed a commit to JustinTong0323/sglang that referenced this pull request Apr 7, 2026
yhyang201 pushed a commit to yhyang201/sglang that referenced this pull request Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants