Conversation
Summary of ChangesHello, 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 introduces a significant optimization to the Triton Highlights
🧠 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 AssistThe 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
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 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
|
|
/tag-and-rerun-ci |
There was a problem hiding this comment.
Code Review
This pull request refactors the Triton rotary embedding kernel to improve performance by parallelizing across heads. This includes updating the kernel's program ID structure, modifying tensor views, and adjusting the kernel launch grid and stride arguments. The review suggests re-introducing larger BLOCK_HS_HALF values in the autotune configurations to prevent potential suboptimal performance for models with large head_size.
| configs=[ | ||
| triton.Config({"BLOCK_HS_HALF": 32}, num_warps=2), | ||
| triton.Config({"BLOCK_HS_HALF": 64}, num_warps=4), | ||
| triton.Config({"BLOCK_HS_HALF": 128}, num_warps=4), | ||
| triton.Config({"BLOCK_HS_HALF": 256}, num_warps=8), | ||
| triton.Config({"BLOCK_HEADS": 1, "BLOCK_HS_HALF": 32}, num_warps=2), | ||
| triton.Config({"BLOCK_HEADS": 2, "BLOCK_HS_HALF": 32}, num_warps=2), | ||
| triton.Config({"BLOCK_HEADS": 4, "BLOCK_HS_HALF": 32}, num_warps=4), | ||
| triton.Config({"BLOCK_HEADS": 4, "BLOCK_HS_HALF": 64}, num_warps=4), | ||
| triton.Config({"BLOCK_HEADS": 8, "BLOCK_HS_HALF": 64}, num_warps=8), | ||
| ], |
There was a problem hiding this comment.
The new autotune configurations have a maximum BLOCK_HS_HALF of 64, while the previous version included values up to 256. For models with a large head_size, this could result in suboptimal performance because the kernel would need more loop iterations. It would be beneficial to re-introduce configurations with larger BLOCK_HS_HALF values (e.g., 128, 256) to give the autotuner more choices, especially for combinations with smaller BLOCK_HEADS values. This will help ensure optimal performance across a wider range of model architectures.
configs=[
triton.Config({"BLOCK_HEADS": 1, "BLOCK_HS_HALF": 32}, num_warps=2),
triton.Config({"BLOCK_HEADS": 2, "BLOCK_HS_HALF": 32}, num_warps=2),
triton.Config({"BLOCK_HEADS": 4, "BLOCK_HS_HALF": 32}, num_warps=4),
triton.Config({"BLOCK_HEADS": 1, "BLOCK_HS_HALF": 64}, num_warps=4),
triton.Config({"BLOCK_HEADS": 2, "BLOCK_HS_HALF": 64}, num_warps=4),
triton.Config({"BLOCK_HEADS": 4, "BLOCK_HS_HALF": 64}, num_warps=4),
triton.Config({"BLOCK_HEADS": 8, "BLOCK_HS_HALF": 64}, num_warps=8),
triton.Config({"BLOCK_HEADS": 1, "BLOCK_HS_HALF": 128}, num_warps=4),
triton.Config({"BLOCK_HEADS": 2, "BLOCK_HS_HALF": 128}, num_warps=8),
triton.Config({"BLOCK_HEADS": 4, "BLOCK_HS_HALF": 128}, num_warps=8),
triton.Config({"BLOCK_HEADS": 1, "BLOCK_HS_HALF": 256}, num_warps=8),
],|
/rerun-failed-ci |
…multiple heads per token (sgl-project#21387)
…multiple heads per token (sgl-project#21387)
…multiple heads per token (sgl-project#21387)
Motivation
Made this with AKO4ALL kernel optimization skill and CodeX(gpt5.4 high)
This PR optimizes the Triton
apply_rotary_embeddingkernel used by diffusion models.The main idea is to process multiple heads for the same token in one kernel program instead of launching one program per
(token, head). This improvescos/sinrow reuse, reduces redundant loads, and lowers launch overhead. The kernel now uses a 2D launch layout and autotunes bothBLOCK_HEADSandBLOCK_HS_HALF.HunyuanVideo
1.0108x1.0127xend2end 1.3% speed up.
hunyuan_rotary_baseline_20260325.mp4
hunyuan_rotary_tuned_20260325.mp4
Microbenchmark
(1, 115200, 24, 128)3.1076x(1, 32760, 12, 128)2.9350x(2, 4096, 24, 128)2.9604x(1, 4096, 32, 64)3.2424x(4096, 24, 128)2.6413x3.1026xModifications
Accuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci