fix(glm-5.2-nvfp4): bound Mooncake synchronous transfer batches (#32758)
This commit is contained in:
@@ -219,6 +219,9 @@ class MooncakeKVManager(StagingManagerMixin, CommonKVManager):
|
||||
self.init_engine()
|
||||
self.register_buffer_to_engine()
|
||||
self.enable_staging = envs.SGLANG_DISAGG_STAGING_BUFFER.get()
|
||||
self.max_transfer_batch_indices = (
|
||||
envs.SGLANG_MOONCAKE_MAX_TRANSFER_BATCH_INDICES.get()
|
||||
)
|
||||
self.enable_trace = get_observability().enable_trace
|
||||
if self.disaggregation_mode == DisaggregationMode.PREFILL:
|
||||
self.session_failures = defaultdict(int)
|
||||
@@ -796,8 +799,64 @@ class MooncakeKVManager(StagingManagerMixin, CommonKVManager):
|
||||
return self._await_transfer_futures(futures)
|
||||
else:
|
||||
# Combining all layers' params in one batch transfer is more efficient
|
||||
# compared to using multiple threads
|
||||
return process_layers(layers_params)
|
||||
# compared to using multiple threads. Preserve this legacy path unless
|
||||
# users explicitly opt in to bounded index batches.
|
||||
max_batch_indices = self.max_transfer_batch_indices
|
||||
if max_batch_indices <= 0 or prefill_data_indices.size <= max_batch_indices:
|
||||
return process_layers(layers_params)
|
||||
|
||||
def process_index_batch(
|
||||
prefill_blocks,
|
||||
dst_blocks,
|
||||
device_prefill_blocks=None,
|
||||
device_dst_blocks=None,
|
||||
) -> int:
|
||||
transfer_blocks = []
|
||||
for src_ptr, dst_ptr, item_len in layers_params:
|
||||
if dst_device_data_ptrs and int(dst_ptr) in dst_device_data_ptrs:
|
||||
assert (
|
||||
device_prefill_blocks is not None
|
||||
and device_dst_blocks is not None
|
||||
)
|
||||
src_blocks, target_blocks = (
|
||||
device_prefill_blocks,
|
||||
device_dst_blocks,
|
||||
)
|
||||
else:
|
||||
src_blocks, target_blocks = prefill_blocks, dst_blocks
|
||||
for prefill_index, decode_index in zip(src_blocks, target_blocks):
|
||||
src_addr = src_ptr + int(prefill_index[0]) * item_len
|
||||
dst_addr = dst_ptr + int(decode_index[0]) * item_len
|
||||
length = item_len * len(prefill_index)
|
||||
transfer_blocks.append((src_addr, dst_addr, length))
|
||||
return self._transfer_data(mooncake_session_id, transfer_blocks)
|
||||
|
||||
for start in range(
|
||||
0,
|
||||
prefill_data_indices.size,
|
||||
max_batch_indices,
|
||||
):
|
||||
batch_prefill_blocks, batch_dst_blocks = group_concurrent_contiguous(
|
||||
prefill_data_indices[start : start + max_batch_indices],
|
||||
dst_data_indices[start : start + max_batch_indices],
|
||||
)
|
||||
batch_device_prefill_blocks = batch_device_dst_blocks = None
|
||||
if dst_device_data_indices is not None:
|
||||
batch_device_prefill_blocks, batch_device_dst_blocks = (
|
||||
group_concurrent_contiguous(
|
||||
prefill_data_indices[start : start + max_batch_indices],
|
||||
dst_device_data_indices[start : start + max_batch_indices],
|
||||
)
|
||||
)
|
||||
ret = process_index_batch(
|
||||
batch_prefill_blocks,
|
||||
batch_dst_blocks,
|
||||
batch_device_prefill_blocks,
|
||||
batch_device_dst_blocks,
|
||||
)
|
||||
if ret != 0:
|
||||
return ret
|
||||
return 0
|
||||
|
||||
def _validate_envelope_kv_layout(
|
||||
self,
|
||||
|
||||
@@ -752,6 +752,10 @@ class Envs:
|
||||
# staging_buffer.py once Triton kernels are fully validated in production.
|
||||
SGLANG_STAGING_USE_TORCH = EnvBool(False)
|
||||
SGLANG_MOONCAKE_CUSTOM_MEM_POOL = EnvStr(None)
|
||||
# Opt-in limit for the number of KV cache indices represented by one
|
||||
# synchronous all-layer Mooncake batch. Set to a positive value to split
|
||||
# larger transfers; 0 preserves the legacy single-batch behavior.
|
||||
SGLANG_MOONCAKE_MAX_TRANSFER_BATCH_INDICES = EnvInt(0)
|
||||
ENABLE_ASCEND_TRANSFER_WITH_MOONCAKE = EnvBool(False)
|
||||
ASCEND_NPU_PHY_ID = EnvInt(-1)
|
||||
SGLANG_MOONCAKE_SEND_AUX_TCP = EnvBool(False)
|
||||
|
||||
Reference in New Issue
Block a user