Skip to content

qwen3_vl_moe support prefill_cudagraph#1245

Open
WANDY666 wants to merge 1 commit intomainfrom
fix_qwen3_vl_qknorm
Open

qwen3_vl_moe support prefill_cudagraph#1245
WANDY666 wants to merge 1 commit intomainfrom
fix_qwen3_vl_qknorm

Conversation

@WANDY666
Copy link
Copy Markdown
Contributor

No description provided.

@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 enhances the Qwen3-VL-MoE model's inference performance by integrating CUDA graph capabilities into its prefill operations. The changes focus on reducing CPU overhead and improving execution efficiency for repetitive computational steps, such as attention and deepstack feature processing, by allowing these sequences of GPU operations to be captured and replayed as single units.

Highlights

  • CUDA Graph Support: Added support for CUDA graphs during the prefill phase of the Qwen3-VL-MoE model to optimize performance.
  • Wrapper Functions for Graph Capture: Introduced _context_attention_wrapper_run and _apply_deepstack_features_wrapper_run to conditionally capture and execute GPU operations within CUDA graphs for attention and deepstack feature application.
  • Dependency Updates: Imported InferStateInfo and tensor_to_no_ref_tensor to facilitate CUDA graph management and tensor handling within the inference process.

🧠 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.

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.

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 refactors the Qwen3VLMOETransformerLayerInfer class by introducing wrapper functions for _context_attention_kernel and apply_deepstack_features. The _apply_deepstack_features_wrapper_run method specifically adds logic to handle CUDA graph capturing for prefill operations, ensuring proper tensor handling and graph management. It also introduces new imports for InferStateInfo and tensor_to_no_ref_tensor. Feedback suggests that the type hints for infer_state and new_infer_state in the new wrapper method should be more specific (Qwen3VLInferStateInfo) for better type safety, and redundant return statements can be removed for cleaner code.

Comment on lines +74 to +105
def _apply_deepstack_features_wrapper_run(
self,
input_embeddings: torch.Tensor,
infer_state: InferStateInfo,
layer_num: int,
):
if torch.cuda.is_current_stream_capturing():
input_embeddings = input_embeddings.contiguous()
_input_embeddings = tensor_to_no_ref_tensor(input_embeddings)
pre_capture_graph = infer_state.prefill_cuda_graph_get_current_capture_graph()
pre_capture_graph.__exit__(None, None, None)

infer_state.prefill_cuda_graph_create_graph_obj()
infer_state.prefill_cuda_graph_get_current_capture_graph().__enter__()

def apply_func(new_infer_state: InferStateInfo):
apply_deepstack_features(
input_embeddings=_input_embeddings,
infer_state=new_infer_state,
layer_num=layer_num,
)
return

infer_state.prefill_cuda_graph_add_cpu_runnning_func(func=apply_func, after_graph=pre_capture_graph)
else:
apply_deepstack_features(
input_embeddings=input_embeddings,
infer_state=infer_state,
layer_num=layer_num,
)

return
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The type hints for infer_state and new_infer_state should be the more specific Qwen3VLInferStateInfo instead of InferStateInfo. The apply_deepstack_features function requires attributes that are specific to Qwen3VLInferStateInfo, so using the correct type hint improves type safety and maintainability. Additionally, the redundant return statements can be removed for cleaner code.

    def _apply_deepstack_features_wrapper_run(
        self,
        input_embeddings: torch.Tensor,
        infer_state: Qwen3VLInferStateInfo,
        layer_num: int,
    ):
        if torch.cuda.is_current_stream_capturing():
            input_embeddings = input_embeddings.contiguous()
            _input_embeddings = tensor_to_no_ref_tensor(input_embeddings)
            pre_capture_graph = infer_state.prefill_cuda_graph_get_current_capture_graph()
            pre_capture_graph.__exit__(None, None, None)

            infer_state.prefill_cuda_graph_create_graph_obj()
            infer_state.prefill_cuda_graph_get_current_capture_graph().__enter__()

            def apply_func(new_infer_state: Qwen3VLInferStateInfo):
                apply_deepstack_features(
                    input_embeddings=_input_embeddings,
                    infer_state=new_infer_state,
                    layer_num=layer_num,
                )

            infer_state.prefill_cuda_graph_add_cpu_runnning_func(func=apply_func, after_graph=pre_capture_graph)
        else:
            apply_deepstack_features(
                input_embeddings=input_embeddings,
                infer_state=infer_state,
                layer_num=layer_num,
            )

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