[Kernel] Add JIT rotary_embedding_kernel#17934
Conversation
Summary of ChangesHello @pansicheng, 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 significantly enhances the rotary embedding functionality by introducing a highly optimized, JIT-compiled CUDA kernel. The primary goal is to accelerate the application of positional embeddings to query and key tensors in attention mechanisms, supporting both common embedding styles. The changes involve low-level CUDA programming for performance and a user-friendly Python API for integration, backed by thorough testing to ensure both accuracy and speed improvements. 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. 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a JIT-compiled CUDA kernel for rotary embedding, complete with Python bindings and comprehensive tests for correctness and performance. The implementation is robust and well-tested. My review includes feedback on a few areas for improvement, such as correcting a type hint, removing unused code, clarifying comments, and refactoring for better maintainability and clarity in both the CUDA kernel and the Python test suite.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
|
||
| @cache_once | ||
| def can_use_jit_rotary_embedding() -> bool: | ||
| logger = logging.getLogger(__name__) |
There was a problem hiding this comment.
can_use_jit_rotary_embedding is not need.
| @@ -0,0 +1,301 @@ | |||
| #include <sgl_kernel/tensor.h> | |||
There was a problem hiding this comment.
BBuf
left a comment
There was a problem hiding this comment.
Please apply it in sglang srt.
|
Please report benchmark result |
…l.pos_enc in SRT with logging and test updates.
applied in python/sglang/srt/layers/rotary_embedding.py |
reported in # Benchmarking and Profiling |
|
@DarkSharpness Any other advices? |
Co-authored-by: Xiaoyu Zhang <35585791+BBuf@users.noreply.github.com>
|
/tag-and-rerun-ci |
This reverts commit ff2a5c5.
7f7e875 to
8c91c7a
Compare
7fa0310 to
4fe032e
Compare
4fe032e to
9f95f8a
Compare
|
/rerun-failed-ci |
1 similar comment
|
/rerun-failed-ci |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Xiaoyu Zhang <35585791+BBuf@users.noreply.github.com> Co-authored-by: root <root@zhikuan-A10x2.ea134>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Xiaoyu Zhang <35585791+BBuf@users.noreply.github.com> Co-authored-by: root <root@zhikuan-A10x2.ea134>
…ect#17934) (sgl-project#18903) Co-authored-by: michaelzhang-ai <michaelzhang-ai@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Xiaoyu Zhang <35585791+BBuf@users.noreply.github.com> Co-authored-by: root <root@zhikuan-A10x2.ea134>
…ect#17934) (sgl-project#18903) Co-authored-by: michaelzhang-ai <michaelzhang-ai@users.noreply.github.com>
Motivation
Add JIT-compiled CUDA kernels for rotary_embedding
Modifications
Accuracy Tests
Verified against torch.ops.sgl_kernel.rotary_embedding
Check
python/sglang/jit_kernel/tests/test_pos_enc.pyRun
python -m pytest python/sglang/jit_kernel/tests/test_pos_enc.py -sBenchmarking and Profiling
h20
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci