Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions python/infinicore/ops/paged_attention_prefill.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
from infinicore.tensor import Tensor


def _ensure_head_dim_contiguous(tensor: Tensor) -> Tensor:
if tensor.ndim > 0 and tensor.stride(tensor.ndim - 1) != 1:
return tensor.contiguous()
return tensor


def paged_attention_prefill(
q: Tensor,
k_cache: Tensor,
Expand All @@ -14,6 +20,8 @@ def paged_attention_prefill(
*,
out: Tensor | None = None,
):
k_cache = _ensure_head_dim_contiguous(k_cache)
v_cache = _ensure_head_dim_contiguous(v_cache)
alibi_ptr = alibi_slopes._underlying if alibi_slopes is not None else None

if out is None:
Expand Down