Repository navigation
feat(qsa): Support pyhip qsa indexer for prefill/decode, sparse gqa for prefill - #43
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The pinned PyHIP revision lacks the QSA modules imported by the runtime and AMD test.
1 open finding
What changed in this PR
Adds optional PyHIP QSA acceleration for gfx942 prefill/decode and improves sparse prefill handling.
Changes:
- Adds PyHIP QSA attention/indexer integration and validation.
- Expands QSA pending rings and optimizes packed prefill K/V gathering.
- Fixes fast-top-k overflow handling with AMD coverage.
| File | Description |
|---|---|
test/registered/kernels/test_qsa.py |
Tests verify-window ring compression. |
test/registered/kernels/test_pyhip_qsa.py |
Tests PyHIP attention, indexer, and graphs. |
test/registered/kernels/ops/elementwise/test_fast_topk.py |
Tests top-k overflow on AMD. |
scripts/launch_qwen38_flash_next_fp8_mi308x_pure_tp1.sh |
Updates model and PyHIP settings. |
scripts/launch_qwen38_flash_next_fp8_mi308x_pure_tp_4_or_8_or_2.sh |
Enables PyHIP QSA for multi-TP launches. |
python/sglang/test/qsa_validation.py |
Adds numerical validation utilities. |
python/sglang/srt/mem_cache/qsa_kv_pool.py |
Enlarges per-request QSA rings. |
python/sglang/srt/layers/attention/qwen_sparse_attn_backend.py |
Integrates PyHIP sparse prefill attention. |
python/sglang/srt/layers/attention/qsa/qsa_indexer.py |
Dispatches supported frames to PyHIP. |
python/sglang/srt/layers/attention/qsa/pyhip_backend.py |
Implements PyHIP adapters. |
python/sglang/srt/layers/attention/qsa/metadata.py |
Adds expanded ring addressing. |
python/sglang/srt/layers/attention/qsa/graph_metadata.py |
Updates graph ring metadata. |
python/sglang/srt/environ.py |
Defines PyHIP QSA environment flags. |
python/sglang/kernels/jit/csrc/elementwise/fast_topk.cuh |
Adds full-row overflow fallback. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| ) | ||
| self._rope_axis_map_cache = None | ||
| self._pyhip_indexer = None | ||
| if is_hip() and envs.SGLANG_USE_PYHIP_QSA.get(): |
There was a problem hiding this comment.
Shall we add device check here ?
There was a problem hiding this comment.
There is unnecessary to double check the device in PyHIPIndexer's __init__ . Because there is a check _supports_frame in sglang/python/sglang/srt/layers/attention/qsa/pyhip_backend.py.
| if not self._supports_frame( | ||
| indexer=indexer, hidden=hidden, positions=positions | ||
| ): |
There was a problem hiding this comment.
what happened if not self._supports_frame is True, forward return None, but pyhip QSA backend does not do anything?
There was a problem hiding this comment.
Should we update this PyHIPIndexer static method _supports_frame to can_use_for_forward? Move condition check in python/sglang/srt/layers/attention/qsa/qsa_indexer.py line 616:
if hidden_states.is_cuda and self._pyhip_indexer is not None:
output = self._pyhip_indexer.forward(
indexer=self,
hidden=hidden_states,
positions=positions,
logical=logical_positions,
batch=forward_batch,
metadata=indexer_metadata,
state_slots=state_slots,
)
if output is not None:
return output
So that we could have a proper fallback if pyhip index not supported.
There was a problem hiding this comment.
That makes some sense, but function-wise, it works as a fallback. can_use_for_forward is the first function in self._pyhip_indexer.forward if it returns None, the indexer can run the original sglang functions.
QSAIndexer.forward_cuda()
└─ self._pyhip_indexer.forward(...)
└─ PyHIPIndexer.can_use_for_forward(...)
├─ False → return None
├─ EXTEND → _prefill() → runtime.prefill_indexer(...)
├─ graph DECODE / TARGET_VERIFY
│ → _decode() → runtime.decode_indexer(...)
└─ other mode → return None
QSAIndexer.forward_cuda()
└─ output is None
→ origin sglang project_qk / compress / MQA / top-k
There was a problem hiding this comment.
I've added qsa indexer support for decode eager mode(c9d2ef4), and left MTP draft verify (not in cuda graph) and MTP draft extend for follow-up PRs.
Co-authored-by: Ethan Yang <Yicheng.Yang@amd.com>
d14f81d
into
qwen38-flash-next-amd-current-fix-install

Motivation
This PR is based on tingqli/pyhip#57 . This PR introduces qsa indexer optimization for prefill/decode and sparse gqa optimization for prefill.
MTP draft extend and eager verify(no cuda graph verify) still use original sglang indexer. A follow-up PR will fix it.
Co-authored-by: Cheng Luo Cheng.Luo@amd.com
Modifications
pyhip.ops.qsa.flydsl.attentionseesrc/pyhip/ops/qsa/flydsl/readme.mdin pyhippyhip.ops.qsa.flydsl.indexer.prefill_indexerandpyhip.ops.qsa.flydsl.indexer.decode_indexeras qsa indexer..tolist()fence and move slot mapping into metadata.Accuracy Tests
TP2
TP2+MTP
TP4
TP4 MTP
Speed Tests and Profiling
All following profile and testing were run on TP2 without MTP.
E2E
Before
After
prefill indexer + sparse gqa
before
indexer



others
gqa
after
indexer

data prepare+other


gqa(union+sparse)
decode indexer
before
after
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci