[KV Connector][NIXL] Coalesce host-buffer KV copies across cache groups (#54483)

Signed-off-by: beenpow <57864041+beenpow@users.noreply.github.com>
Co-authored-by: Chendi.Xue <chendi.xue@intel.com>
This commit is contained in:
Chanbin Lim
2026-10-01 13:10:54 -05:00
committed by GitHub
co-authored by Chendi.Xue
parent e9be5323f0
commit 47de9d4d04
3 changed files with 326 additions and 18 deletions
@@ -2702,17 +2702,18 @@ class NixlBaseConnectorWorker:
assert self.copy_blocks is not None
local_block_ids = meta.local_physical_block_ids
# TODO (NickLucche) D2H<>H2D ops could benefit from coalescing io across groups
# The h2d block copies below are intentionally synchronous.
# Every KV cache group allocates from the same BlockPool, so block ids
# are unique across groups and the per-group copies can be issued as one.
block_ids = [block_id for group in local_block_ids for block_id in group]
# The h2d block copy below is intentionally synchronous.
with gpu_sync_allowed():
for group_block_ids in local_block_ids:
self.copy_blocks(
self.host_xfer_buffers,
self.device_kv_caches,
group_block_ids,
group_block_ids,
"h2d",
)
self.copy_blocks(
self.host_xfer_buffers,
self.device_kv_caches,
block_ids,
block_ids,
"h2d",
)
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
"synced recved kv of request[%s] to device kv buffer,"
@@ -2740,14 +2741,18 @@ class NixlBaseConnectorWorker:
",".join(map(str, meta.local_physical_block_ids)),
)
# blocking
for group_block_ids in meta.local_physical_block_ids:
self.copy_blocks(
self.device_kv_caches,
self.host_xfer_buffers,
group_block_ids,
group_block_ids,
"d2h",
)
block_ids = [
block_id
for group in meta.local_physical_block_ids
for block_id in group
]
self.copy_blocks(
self.device_kv_caches,
self.host_xfer_buffers,
block_ids,
block_ids,
"d2h",
)
@cached_property
def _attention_kv_caches(self) -> list[torch.Tensor]: