"git@developer.sourcefind.cn:change/sglang.git" did not exist on "fdcb1d13c5aeb8f3ac11560d8903227c141e50a1"
Unverified Commit 30ca18f4 authored by Yuan Luo's avatar Yuan Luo Committed by GitHub
Browse files

Refactor group_concurrent_contiguous in NIXL (#6214)


Co-authored-by: default avatarluoyuan.luo <luoyuan.luo@antgroup.com>
parent 03886917
...@@ -35,29 +35,19 @@ logger = logging.getLogger(__name__) ...@@ -35,29 +35,19 @@ logger = logging.getLogger(__name__)
NixlEngineInfo: TypeAlias = Dict[str, Union[str, int]] NixlEngineInfo: TypeAlias = Dict[str, Union[str, int]]
# From Mooncake backend.
def group_concurrent_contiguous( def group_concurrent_contiguous(
src_indices: npt.NDArray[np.int64], dst_indices: npt.NDArray[np.int64] src_indices: npt.NDArray[np.int64], dst_indices: npt.NDArray[np.int64]
) -> Tuple[List[npt.NDArray[np.int64]], List[npt.NDArray[np.int64]]]: ) -> Tuple[List[npt.NDArray[np.int64]], List[npt.NDArray[np.int64]]]:
src_groups = [] """Vectorised NumPy implementation."""
dst_groups = [] if src_indices.size == 0:
current_src = [src_indices[0]] return [], []
current_dst = [dst_indices[0]]
brk = np.where((np.diff(src_indices) != 1) | (np.diff(dst_indices) != 1))[0] + 1
for i in range(1, len(src_indices)): src_groups = np.split(src_indices, brk)
src_contiguous = src_indices[i] == src_indices[i - 1] + 1 dst_groups = np.split(dst_indices, brk)
dst_contiguous = dst_indices[i] == dst_indices[i - 1] + 1
if src_contiguous and dst_contiguous:
current_src.append(src_indices[i])
current_dst.append(dst_indices[i])
else:
src_groups.append(current_src)
dst_groups.append(current_dst)
current_src = [src_indices[i]]
current_dst = [dst_indices[i]]
src_groups.append(current_src) src_groups = [g.tolist() for g in src_groups]
dst_groups.append(current_dst) dst_groups = [g.tolist() for g in dst_groups]
return src_groups, dst_groups return src_groups, dst_groups
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment