[Diffusion] Add native paged KV backend for diffusion workers (#6102)

Signed-off-by: Acerak01-fy <wfy2003324@163.com>
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
Wang fuyinandHongsheng Liu authored and GitHub committed 2026-08-22 21:45:45 +08:00
1 parent c2daa471c3
commit 72ee535fcd
34 files changed
+4595 -71

No files matched your search

@@ -15,6 +15,11 @@ class AttentionBackend(ABC):
accept_output_buffer: bool = False
supports_piecewise_spans: bool = False
# A backend that supports this capability can consume the opaque paged-KV
# context prepared by the diffusion Worker data plane. Keeping the
# capability on the backend class prevents a paged request from silently
# falling back to dense attention on an incompatible implementation.
supports_paged_kv: bool = False
# The backend can represent a contiguous valid K/V prefix by slicing the
# tensors instead of materializing a padding mask. Models may use this to
# avoid a slower masked-attention plan when tail padding is not semantic.
@@ -221,6 +226,18 @@ class AttentionImpl(ABC, Generic[T]):
else:
raise NotImplementedError(f"No forward implementation for platform: {current_omni_platform}")
def forward_paged(self, paged_kv_context: Any) -> torch.Tensor:
"""Execute one Worker-prepared paged-KV attention call.
The context is intentionally opaque to the common attention layer.
Backends opt in by setting ``supports_paged_kv`` on their backend
class and implementing this method. Dense callers continue to use
``forward`` unchanged.
"""
del paged_kv_context
raise NotImplementedError(f"{type(self).__name__} does not support paged KV attention")
def forward_cuda(
self,
query: torch.Tensor,