[Bugfix][XPU] Fix Mamba state pointer overflow (#48109)

Signed-off-by: Oxygen56 <jiangth99@163.com>
This commit is contained in:
Willow Lopez
2026-08-19 10:45:41 +08:00
committed by GitHub
parent e4d61d0d22
commit f936a267f9
2 changed files with 98 additions and 2 deletions
+9 -2
View File
@@ -114,6 +114,11 @@ def _memcpy_u64_tiled(
tl.store(dst_u8 + i + offsets, data, mask=mask)
def _reinterpret_u64_as_i64(value: int) -> int:
"""Preserve a uint64 pointer bit pattern in a torch.int64 tensor."""
return value if value < (1 << 63) else value - (1 << 64)
@triton.jit
def _copy_mamba_state_block(
state_idx,
@@ -836,7 +841,9 @@ class MambaSpecDecodeGPUContext:
for state_type_idx, copy_func in enumerate(mamba_state_copy_funcs):
state = kv_caches[state_type_idx]
# Base address
self.state_base_addrs[idx] = state.data_ptr()
self.state_base_addrs[idx] = _reinterpret_u64_as_i64(
state.data_ptr()
)
# Block stride (bytes between consecutive blocks)
# state shape: [num_blocks, ...], stride(0) = elements per block
@@ -923,7 +930,7 @@ class MambaSpecDecodeGPUContext:
)
self.block_table_stride_req = int(next(iter(strides)))
for i, bt in enumerate(block_tables):
self.block_table_ptrs[i] = bt.data_ptr()
self.block_table_ptrs[i] = _reinterpret_u64_as_i64(bt.data_ptr())
self.is_initialized = True