Skip to content

[PCG] Enable piecewise CUDA graph testing for VLM models#20548

Open
edwingao28 wants to merge 12 commits intosgl-project:mainfrom
edwingao28:pcg/cicd_testing
Open

[PCG] Enable piecewise CUDA graph testing for VLM models#20548
edwingao28 wants to merge 12 commits intosgl-project:mainfrom
edwingao28:pcg/cicd_testing

Conversation

@edwingao28
Copy link
Copy Markdown
Contributor

@edwingao28 edwingao28 commented Mar 13, 2026

Motivation

Piecewise CUDA Graph initialization currently assumes the transformer layers are located at model.model.layers. This assumption works for many LLM models but fails for several VLM architectures where the language model is wrapped differently (e.g., model.language_model.model.layers, model.model.model.layers, or model.thinker.model.layers).
As a result, VLM CI tests may run without actually exercising Piecewise CUDA Graph.

This PR improves PCG coverage for VLM models by enabling the runtime to correctly locate transformer layers and by enforcing PCG in relevant test configurations.

Modifications

  • Introduces _find_transformer_layers() so PCG can work across different VLM wrapper structures

  • forces CI to actually run PCG via --enforce-piecewise-cuda-graph

  • stabilize these model-specific issues so that the majority of VLM test files can pass with PCG enabled..py

  • LLaVA: scheduler crash during PCG warmup.

  • Qwen3-VL / Qwen3-Omni: server startup returns connection refused. Will re-test after applying the Qwen3 bug fix PR. [Bugfix] fix recompile in qwen3 vl #16785

  • test_vlms_mmmu_eval.py

  • test_nvidia_nemotron_nano_v2_vl.py

  • test_encoder_dp.py

  • test_vision_openai_server_a.py

Accuracy Tests

Benchmarking and Profiling

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

@github-actions github-actions bot added Multi-modal multi-modal language model npu labels Mar 13, 2026
@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 aims to significantly improve the coverage and reliability of Piecewise CUDA Graph (PCG) testing for Vision-Language Models (VLMs). By introducing a more flexible mechanism for identifying transformer layers within complex VLM architectures and explicitly enabling PCG in relevant test configurations, the changes ensure that PCG is properly utilized and validated across a broader range of models, addressing current limitations where VLM CI tests might not have been exercising PCG effectively.

Highlights

  • Enhanced Transformer Layer Discovery: Introduced a new utility function, _find_transformer_layers, to robustly locate transformer layers within various VLM and LLM model architectures, addressing previous assumptions about layer placement.
  • Improved Piecewise CUDA Graph Initialization: Updated the init_piecewise_cuda_graphs method to utilize the new _find_transformer_layers function, enhancing compatibility with diverse VLM structures and improving PCG initialization logic.
  • Enforced PCG in VLM Tests: Configured several VLM test suites to explicitly enforce Piecewise CUDA Graph (PCG) execution, ensuring that PCG functionality is properly exercised and validated during CI runs.

🧠 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/model_executor/model_runner.py
    • Added _find_transformer_layers function to locate transformer layers in various model patterns.
    • Modified init_piecewise_cuda_graphs to use _find_transformer_layers and updated the logic for identifying language models and collecting attention/moe layers.
  • python/sglang/test/vlm_utils.py
    • Added --enforce-piecewise-cuda-graph to the fixed_args list for TestOpenAIMLLMServerBase.
  • test/registered/models/test_vlm_models.py
    • Added --enforce-piecewise-cuda-graph to the other_args for TestVLMModels.
  • test/registered/vlm/test_vision_chunked_prefill.py
    • Added --enforce-piecewise-cuda-graph to the other_args for server launch.
  • test/registered/vlm/test_vlm_input_format.py
    • Set enforce_piecewise_cuda_graph=True in ServerArgs for the test setup.
Activity
  • The author, edwingao28, opened this pull request with a "[WIP]" (Work In Progress) tag, indicating ongoing development.
  • The PR description outlines several "TODO" items, including stabilizing model-specific issues for LLaVA, Qwen3-VL, and Qwen3-Omni to pass with PCG enabled.
  • The author is awaiting a Qwen3 bug fix PR ([Bugfix] fix recompile in qwen3 vl #16785) before re-testing Qwen3-VL / Qwen3-Omni.
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.

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 enables piecewise CUDA graph (PCG) testing for a wider range of Vision Language Models (VLMs) by making the transformer layer discovery more robust. The core change is the introduction of the _find_transformer_layers function, which correctly locates transformer layers across different VLM wrapper structures. The init_piecewise_cuda_graphs function is updated to use this new discovery mechanism. Additionally, several test configurations are modified to enforce PCG, ensuring better test coverage for this feature. The changes are logical and well-implemented. I have not found any issues of medium or higher severity.

edwingao28 and others added 9 commits March 17, 2026 21:08
- LLaVA/LLaVaVid: add None guard for mm_inputs during PCG warmup,
  where ForwardBatch is constructed with mm_inputs=None
- Qwen3VL/Omni: stabilize input_deepstack_embeds kwarg to prevent
  TorchDynamo recompilation during PCG capture. Preallocate deepstack
  buffer and always pass it for consistent function signatures.

Based on sgl-project#16785.

Co-Authored-By: narutolhy <582909902@qq.com>
… leakage

The preallocated deepstack buffer is always passed as a kwarg, but
general_mm_embed_routine only zeroes it when mm_inputs are present.
For text-only batches, the buffer retains stale embeddings from the
previous multimodal request, corrupting text-only inference. Zero the
buffer before each pass so text-only batches see clean zeros.
@edwingao28 edwingao28 changed the title [WIP] [PCG] Enable piecewise CUDA graph testing for VLM models [PCG] Enable piecewise CUDA graph testing for VLM models Mar 23, 2026
@edwingao28 edwingao28 marked this pull request as ready for review March 23, 2026 07:13
@yhyang201 yhyang201 self-assigned this Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Multi-modal multi-modal language model npu

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants