Fuse writing KV buffer into rope kernel (part 2: srt) (#9014)

Co-authored-by: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com>
This commit is contained in:
Jiaqi Gu
2025-08-12 13:15:30 -07:00
committed by GitHub
co-authored by fzyzcjy
parent 1f9ec65374
commit c9ee738515
5 changed files with 64 additions and 5 deletions
@@ -222,6 +222,7 @@ class RotaryEmbedding(CustomOp):
query: torch.Tensor,
key: torch.Tensor,
offsets: Optional[torch.Tensor] = None,
fused_set_kv_buffer_arg=None, # Optional[FusedSetKVBufferArg]
) -> Tuple[torch.Tensor, torch.Tensor]:
if _is_cuda and (self.head_size in [64, 128, 256, 512]):
apply_rope_with_cos_sin_cache_inplace(
@@ -231,8 +232,17 @@ class RotaryEmbedding(CustomOp):
head_size=self.head_size,
cos_sin_cache=self.cos_sin_cache,
is_neox=self.is_neox_style,
# Compatible with old sgl-kernel
**(
dict(fused_set_kv_buffer_arg=fused_set_kv_buffer_arg)
if fused_set_kv_buffer_arg is not None
else {}
),
)
else:
assert (
fused_set_kv_buffer_arg is None
), "save kv cache is not supported for vllm_rotary_embedding."
self.cos_sin_cache = self.cos_sin_cache.to(query.device, dtype=query.dtype)
self.vllm_rotary_embedding(
positions,