[ROCm] Fix TurboQuant on ROCm: backend routing, flash-attn compat, int64 overflow (#39953)

Signed-off-by: aditi <aditi.rana@amd.com>
This commit is contained in:
aditi-amd
2026-04-17 13:08:37 -07:00
committed by GitHub
parent 58da4ee047
commit 6ef1efd51f
4 changed files with 22 additions and 23 deletions
@@ -143,12 +143,12 @@ def _tq_decode_stage1(
Block_table_ptr + bt_base + page_idx,
mask=kv_mask,
other=0,
)
).to(tl.int64)
slot_bases = (
block_nums * stride_cache_block
+ page_off * stride_cache_pos
+ kv_head * stride_cache_head
+ page_off.to(tl.int64) * stride_cache_pos
+ tl.cast(kv_head, tl.int64) * stride_cache_head
)
# ============================================================
@@ -356,11 +356,11 @@ def _tq_full_dequant_kv(
page_idx = pos // BLOCK_SIZE
page_off = pos % BLOCK_SIZE
block_num = tl.load(Block_table_ptr + bid * stride_bt_b + page_idx)
block_num = tl.load(Block_table_ptr + bid * stride_bt_b + page_idx).to(tl.int64)
slot_base = (
block_num * stride_cache_block
+ page_off * stride_cache_pos
+ hid * stride_cache_head
+ tl.cast(page_off, tl.int64) * stride_cache_pos
+ tl.cast(hid, tl.int64) * stride_cache_head
)
d_offs = tl.arange(0, BLOCK_D)
@@ -174,10 +174,13 @@ def _tq_fused_store_fp8(
slot = tl.load(Slot_mapping_ptr + token_idx)
if slot < 0:
return
blk = slot // BLOCK_SIZE
off = slot % BLOCK_SIZE
blk = (slot // BLOCK_SIZE).to(tl.int64)
off = (slot % BLOCK_SIZE).to(tl.int64)
head_idx_i64 = tl.cast(head_idx, tl.int64)
slot_base = (
blk * stride_cache_block + off * stride_cache_pos + head_idx * stride_cache_head
blk * stride_cache_block
+ off * stride_cache_pos
+ head_idx_i64 * stride_cache_head
)
base = pid * D
@@ -259,10 +262,13 @@ def _tq_fused_store_mse(
slot = tl.load(Slot_mapping_ptr + token_idx)
if slot < 0:
return
blk = slot // BLOCK_SIZE
off = slot % BLOCK_SIZE
blk = (slot // BLOCK_SIZE).to(tl.int64)
off = (slot % BLOCK_SIZE).to(tl.int64)
head_idx_i64 = tl.cast(head_idx, tl.int64)
slot_base = (
blk * stride_cache_block + off * stride_cache_pos + head_idx * stride_cache_head
blk * stride_cache_block
+ off * stride_cache_pos
+ head_idx_i64 * stride_cache_head
)
base = pid * D