Skip to content

[Diffusion] Disable packed QKV for FLUX & Z-Image#16038

Merged
BBuf merged 1 commit intomainfrom
delete_pack_qkv_in_dit
Dec 29, 2025
Merged

[Diffusion] Disable packed QKV for FLUX & Z-Image#16038
BBuf merged 1 commit intomainfrom
delete_pack_qkv_in_dit

Conversation

@BBuf
Copy link
Copy Markdown
Collaborator

@BBuf BBuf commented Dec 29, 2025

Motivation

Refer to #15812

Pack qkv will cause a uncontiguous concat kernel, which is a not efficient cuda kernel and caused performance drop.

图片

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

@github-actions github-actions bot added the diffusion SGLang Diffusion label Dec 29, 2025
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @BBuf, 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 refactors the attention mechanism for the FLUX and Z-Image models by decoupling the Query, Key, and Value (QKV) projections. Previously, these were handled by a single fused QKV layer, which led to performance degradation due to inefficient CUDA kernel operations involving uncontiguous memory concatenation. By separating these projections into distinct linear layers, the aim is to eliminate this bottleneck and improve overall model performance.

Highlights

  • QKV Fusion Removal: The packed QKV (Query, Key, Value) projection mechanism has been disabled for FLUX and Z-Image models.
  • Performance Improvement: This change addresses a performance bottleneck caused by inefficient CUDA kernels due to uncontiguous concatenation when using packed QKV, which led to performance degradation.
  • Architectural Refactoring: Configuration files were updated to remove QKV fusion mappings, and runtime files were refactored to use separate linear layers for Q, K, and V projections instead of a single fused layer.

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

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 disables packed QKV projections for FLUX, FLUX-2, and Z-Image models to improve performance by avoiding an inefficient uncontiguous concat kernel. The changes involve updating model configurations to remove packed parameter mappings and modifying the model implementations to use separate linear layers for query, key, and value projections instead of a single fused layer. The modifications are consistent across all affected models and correctly implement the intended change. I've suggested a minor refactoring to improve code organization by moving a helper function into its associated class for better encapsulation. Otherwise, the changes look good.

@BBuf BBuf added the run-ci label Dec 29, 2025
@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Dec 29, 2025

/tag-and-rerun-ci

@BBuf BBuf merged commit 8305dc1 into main Dec 29, 2025
115 of 123 checks passed
@BBuf BBuf deleted the delete_pack_qkv_in_dit branch December 29, 2025 06:33
YChange01 pushed a commit to YChange01/sglang that referenced this pull request Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants