Fix long prompt KV allocation by falling back to torch native APIs when exceeding Triton tensor limit (#18250)
This commit is contained in:
@@ -411,7 +411,7 @@ class PagedTokenToKVPoolAllocator(BaseTokenToKVPoolAllocator):
|
|||||||
|
|
||||||
self.seen_max_num_extend_tokens_next_power_of_2 = max(
|
self.seen_max_num_extend_tokens_next_power_of_2 = max(
|
||||||
self.seen_max_num_extend_tokens_next_power_of_2,
|
self.seen_max_num_extend_tokens_next_power_of_2,
|
||||||
next_power_of_2(extend_num_tokens),
|
min(tl.core.TRITON_MAX_TENSOR_NUMEL, next_power_of_2(extend_num_tokens)),
|
||||||
)
|
)
|
||||||
|
|
||||||
bs = len(prefix_lens)
|
bs = len(prefix_lens)
|
||||||
@@ -423,16 +423,28 @@ class PagedTokenToKVPoolAllocator(BaseTokenToKVPoolAllocator):
|
|||||||
out_indices = torch.empty(
|
out_indices = torch.empty(
|
||||||
(extend_num_tokens,), dtype=torch.int64, device=self.device
|
(extend_num_tokens,), dtype=torch.int64, device=self.device
|
||||||
)
|
)
|
||||||
alloc_extend_kernel[(bs,)](
|
|
||||||
prefix_lens,
|
if extend_num_tokens < tl.core.TRITON_MAX_TENSOR_NUMEL:
|
||||||
seq_lens,
|
alloc_extend_kernel[(bs,)](
|
||||||
last_loc,
|
prefix_lens,
|
||||||
self.free_pages,
|
seq_lens,
|
||||||
out_indices,
|
last_loc,
|
||||||
next_power_of_2(bs),
|
self.free_pages,
|
||||||
self.page_size,
|
out_indices,
|
||||||
self.seen_max_num_extend_tokens_next_power_of_2,
|
next_power_of_2(bs),
|
||||||
)
|
self.page_size,
|
||||||
|
self.seen_max_num_extend_tokens_next_power_of_2,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
alloc_extend_naive(
|
||||||
|
prefix_lens,
|
||||||
|
seq_lens,
|
||||||
|
last_loc,
|
||||||
|
self.free_pages,
|
||||||
|
out_indices,
|
||||||
|
self.page_size,
|
||||||
|
self.device,
|
||||||
|
)
|
||||||
|
|
||||||
if self.debug_mode:
|
if self.debug_mode:
|
||||||
assert len(torch.unique(out_indices)) == len(out_indices)
|
assert len(torch.unique(out_indices)) == len(out_indices)
|
||||||
|
|||||||
Reference in New Issue
Block a user