[1/N][Sparse With Hicache]: Add Sparse Interface#14741
[1/N][Sparse With Hicache]: Add Sparse Interface#14741xiezhq-hermann merged 7 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello @hzh0425, 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 establishes a foundational interface for integrating diverse sparse attention algorithms within the system. By introducing a BaseSparseAlgorithm and SparseMode enum, it provides a standardized way to implement and manage KV cache compression techniques. The PR also includes two initial algorithm implementations, DeepSeekNSAAlgorithm and KnormPageAlgorithm, demonstrating the extensibility of this new framework. This change is crucial for enabling more efficient memory usage and potentially faster inference by selectively attending to important KV cache entries. Highlights
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 valuable abstraction for sparse attention algorithms by adding a generic BaseSparseAlgorithm interface. The changes include the base class, two initial implementations (DeepSeekNSAAlgorithm and KnormPageAlgorithm), and unit tests for one of them. My review identifies a critical issue in DeepSeekNSAAlgorithm that would lead to a runtime error due to an incorrect return value. I've also pointed out several medium-severity issues in KnormPageAlgorithm related to hardcoded values, dead code, incorrect type hints, and verbose logging that could impact maintainability and performance. Overall, this is a solid architectural improvement, and addressing these points will enhance the robustness and quality of the new sparse attention framework.
python/sglang/srt/mem_cache/sparsity/algorithms/deepseek_nsa.py
Outdated
Show resolved
Hide resolved
python/sglang/srt/mem_cache/sparsity/algorithms/page_wise_algorithm.py
Outdated
Show resolved
Hide resolved
python/sglang/srt/mem_cache/sparsity/algorithms/page_wise_algorithm.py
Outdated
Show resolved
Hide resolved
python/sglang/srt/mem_cache/sparsity/algorithms/page_wise_algorithm.py
Outdated
Show resolved
Hide resolved
python/sglang/srt/mem_cache/sparsity/algorithms/page_wise_algorithm.py
Outdated
Show resolved
Hide resolved
python/sglang/srt/mem_cache/sparsity/algorithms/page_wise_algorithm.py
Outdated
Show resolved
Hide resolved
python/sglang/srt/mem_cache/sparsity/algorithms/page_wise_algorithm.py
Outdated
Show resolved
Hide resolved
199f115 to
9c9d83a
Compare
Co-authored-by: 晟海 <huangtingwei.htw@antgroup.com>
37c9b5c to
4d1a182
Compare
python/sglang/srt/mem_cache/sparsity/algorithms/base_algorithm.py
Outdated
Show resolved
Hide resolved
python/sglang/srt/mem_cache/sparsity/algorithms/deepseek_nsa.py
Outdated
Show resolved
Hide resolved
python/sglang/srt/mem_cache/sparsity/algorithms/deepseek_nsa.py
Outdated
Show resolved
Hide resolved
a07afd8 to
205c2bc
Compare
|
we performed a refactoring by removing the distinction between PageWise and TokenWise, as TokenWise is essentially a special case of PageWise with PageSize = 1. In base_algorithm.py, I implemented a BaseSparseAlgorithmImpl as a common base class. Subclasses can integrate into the pipeline by implementing a few key methods, and they also have the flexibility to override critical methods such as retrieve_topk and update_representations to customize their specific logic. Additionally, we plan to improve the performance of BaseSparseAlgorithmImpl in the next PR. Could you please review it again when you have time? @xiezhq-hermann The Accuracy Test for Quest Sparse Algo(Implemented by @magicYang1573): GSM8Kllama 8B Test: (The accuracy (ACC) of the original model is 0.94.)
aime25Qwen32B Test: |
|
/rerun-failed-ci |
Co-authored-by: 晟海 <huangtingwei.htw@antgroup.com> Co-authored-by: huangtingwei <141888744+huangtingwei9988@users.noreply.github.com> Co-authored-by: MagicYang1573 <1328657938@qq.com>
Co-authored-by: 晟海 <huangtingwei.htw@antgroup.com> Co-authored-by: huangtingwei <141888744+huangtingwei9988@users.noreply.github.com> Co-authored-by: MagicYang1573 <1328657938@qq.com>
Co-authored-by: 晟海 <huangtingwei.htw@antgroup.com> Co-authored-by: huangtingwei <141888744+huangtingwei9988@users.noreply.github.com> Co-authored-by: MagicYang1573 <1328657938@qq.com> (cherry picked from commit a89e85e)
Co-authored-by: 晟海 <huangtingwei.htw@antgroup.com> Co-authored-by: huangtingwei <141888744+huangtingwei9988@users.noreply.github.com> Co-authored-by: MagicYang1573 <1328657938@qq.com> (cherry picked from commit a89e85e)
Co-authored-by: 晟海 <huangtingwei.htw@antgroup.com> Co-authored-by: huangtingwei <141888744+huangtingwei9988@users.noreply.github.com> Co-authored-by: MagicYang1573 <1328657938@qq.com>


Motivation
This PR primarily introduces a generic Retrievable Sparse Algorithm interface.
Upstream PR:#14619
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist