Skip to content

Commit d2880b2

Browse files
committed
rebase main
Signed-off-by: ganyi <ygan@amd.com>
1 parent e70cc7b commit d2880b2

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

vllm/v1/attention/backends/utils.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33
import abc
4-
import copy
54
import enum
65
import functools
76
from abc import abstractmethod
@@ -864,7 +863,6 @@ def reorder_batch_to_split_decodes_and_prefills(
864863
# NOTE for now we loosely use "decode" to mean requests where attention is
865864
# likely memory-bound and "prefill" to mean requests where attention is
866865
# likely compute-bound,
867-
868866
num_reqs = len(input_batch.req_ids)
869867
num_scheduled_tokens = [
870868
scheduler_output.num_scheduled_tokens[id] for id in input_batch.req_ids
@@ -900,22 +898,14 @@ def reorder_batch_to_split_decodes_and_prefills(
900898

901899
src_dest_map = {int(src): int(dst) for src, dst in zip(src_indices, orig_indices)}
902900

903-
# Then we reorder the swap_indices to dest_indices
904-
for i in range(len(swap_indices)):
905-
dst = dest_indices[i]
906-
src = swap_indices[i]
907-
if dst != src:
908-
# Get the real index position in input_batch to swap
909-
dst_pos = indices_positions[idx_mapping[dst]]
910-
src_pos = indices_positions[idx_mapping[src]]
911-
912-
input_batch.swap_states(dst_pos, src_pos)
913-
914-
dst_idx = idx_mapping[dst]
915-
swap_indices[i] = dst
916-
swap_indices[dst_idx] = src
917-
idx_mapping[dst] = i
918-
idx_mapping[src] = dst_idx
901+
for src in src_dest_map:
902+
dst = src_dest_map[src]
903+
while src != dst:
904+
input_batch.swap_states(src, dst)
905+
# Mark dst as done by updating its destination to itself
906+
next_dst = src_dest_map.get(dst, dst)
907+
src_dest_map[dst] = dst
908+
dst = next_dst
919909

920910
return True
921911

0 commit comments

Comments
 (0)