[ROCm][Bugfix] Cap the DSA MQA-logits budget at AITER's buffer_store limit (#36960)
Co-authored-by: amdpilot-upstream-sync <amdpilot-upstream-sync@users.noreply.github.com>
This commit is contained in:
co-authored by
amdpilot-upstream-sync
parent
f8618714c5
commit
9978aaec8b
@@ -203,6 +203,8 @@ class Indexer(DSANPUIndexerMixin, BaseFusedOp):
|
||||
_MQA_LOGITS_BYTES_PER_ELEM = 4
|
||||
_MQA_LOGITS_STATIC_SKIP_ELEMS = 8_000_000
|
||||
_MQA_LOGITS_TOTAL_MEM_FRACTION = 0.3
|
||||
# aiter's fp8_mqa_logits only compiles below 2 GiB of logits (buffer_store).
|
||||
_MQA_LOGITS_MAX_BYTES_ROCM = 2**31 - 1
|
||||
_mqa_logits_budget_bytes: Dict[int, int] = {}
|
||||
|
||||
@staticmethod
|
||||
@@ -1003,7 +1005,8 @@ class Indexer(DSANPUIndexerMixin, BaseFusedOp):
|
||||
self, num_q: int, num_k: int, device_index: int
|
||||
) -> Tuple[bool, int]:
|
||||
"""
|
||||
Detect whether we need to chunk the MQA logits computation to avoid OOM
|
||||
Detect whether we need to chunk the MQA logits computation to avoid OOM,
|
||||
and on ROCm to stay under aiter's 2 GiB logits limit
|
||||
Return: (need_chunk, logits_budget_bytes)
|
||||
"""
|
||||
# Quick static check for normal batches
|
||||
@@ -1012,6 +1015,10 @@ class Indexer(DSANPUIndexerMixin, BaseFusedOp):
|
||||
|
||||
logits_bytes = num_q * num_k * self._MQA_LOGITS_BYTES_PER_ELEM
|
||||
logits_budget_bytes = self._get_mqa_logits_budget_bytes(device_index)
|
||||
if _is_hip:
|
||||
logits_budget_bytes = min(
|
||||
logits_budget_bytes, self._MQA_LOGITS_MAX_BYTES_ROCM
|
||||
)
|
||||
|
||||
need_chunk = logits_bytes > logits_budget_bytes
|
||||
return need_chunk, logits_budget_bytes
|
||||
|
||||
Reference in New Issue
Block a user