[6/N][KV-Cache Layout Refactor] Standardize KV cache layout (#51718)

Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
This commit is contained in:
Lucas Wilkinson
2026-08-21 17:47:49 -07:00
committed by GitHub
parent 9ff7041b55
commit 8bdc70ec7b
150 changed files with 4006 additions and 5815 deletions
+15
View File
@@ -117,6 +117,21 @@ def is_strictly_contiguous(t: torch.Tensor) -> bool:
return True
def is_non_overlapping_and_dense(t: torch.Tensor) -> bool:
"""Check if the tensor's elements cover one gapless, non-overlapping byte
range, in any dimension order (i.e. a permuted view of a contiguous
tensor); ``is_contiguous()`` additionally requires row-major order.
"""
expected_stride = 1
for size, stride in sorted(zip(t.shape, t.stride()), key=lambda p: p[1]):
if size == 1:
continue
if stride != expected_stride:
return False
expected_stride *= size
return True
def canonicalize_singleton_dim_strides(t: torch.Tensor) -> torch.Tensor:
"""Fix degenerate strides on size=1 dimensions for CUDA TMA compatibility.