[Bugfix] Fix SP pass for multimodal models and PP+SP residual handling (#33322)
Signed-off-by: Xingran Wang <wangxingran123456@outlook.com> Signed-off-by: Hongjian Zhang <hirokenovo@gmail.com> Co-authored-by: Hongjian Zhang <hirokenovo@gmail.com>
This commit is contained in:
co-authored by
Hongjian Zhang
parent
dcb3135af7
commit
0b272a6e01
@@ -3129,7 +3129,7 @@ class GPUModelRunner(
|
||||
|
||||
return tuple(tasks)
|
||||
|
||||
def sync_and_slice_intermediate_tensors(
|
||||
def sync_and_gather_intermediate_tensors(
|
||||
self,
|
||||
num_tokens: int,
|
||||
intermediate_tensors: IntermediateTensors | None,
|
||||
@@ -3140,24 +3140,23 @@ class GPUModelRunner(
|
||||
tp = self.vllm_config.parallel_config.tensor_parallel_size
|
||||
is_rs = is_residual_scattered_for_sp(self.vllm_config, num_tokens)
|
||||
|
||||
# When sequence parallelism is enabled, the "residual" tensor is sharded
|
||||
# across tensor parallel ranks, so each rank only needs its own slice.
|
||||
# When sequence parallelism is enabled, the "residual" tensor is
|
||||
# sharded across TP ranks. All-gather it here because downstream
|
||||
# QKV + Attention needs the full residual before the SP split point.
|
||||
if sync_self:
|
||||
assert intermediate_tensors is not None
|
||||
for k, v in intermediate_tensors.items():
|
||||
is_scattered = k == "residual" and is_rs
|
||||
copy_len = num_tokens // tp if is_scattered else num_tokens
|
||||
self.intermediate_tensors[k][:copy_len].copy_(
|
||||
v[:copy_len], non_blocking=True
|
||||
if is_scattered:
|
||||
local_len = num_tokens // tp
|
||||
v = get_tp_group().all_gather(v[:local_len], dim=0)
|
||||
|
||||
self.intermediate_tensors[k][:num_tokens].copy_(
|
||||
v[:num_tokens], non_blocking=True
|
||||
)
|
||||
|
||||
return IntermediateTensors(
|
||||
{
|
||||
k: v[: num_tokens // tp]
|
||||
if k == "residual" and is_rs
|
||||
else v[:num_tokens]
|
||||
for k, v in self.intermediate_tensors.items()
|
||||
}
|
||||
{k: v[:num_tokens] for k, v in self.intermediate_tensors.items()}
|
||||
)
|
||||
|
||||
def eplb_step(self, is_dummy: bool = False, is_profile: bool = False) -> None:
|
||||
@@ -3373,7 +3372,7 @@ class GPUModelRunner(
|
||||
intermediate_tensors = None
|
||||
else:
|
||||
assert intermediate_tensors is not None
|
||||
intermediate_tensors = self.sync_and_slice_intermediate_tensors(
|
||||
intermediate_tensors = self.sync_and_gather_intermediate_tensors(
|
||||
num_input_tokens, intermediate_tensors, True
|
||||
)
|
||||
|
||||
@@ -5589,7 +5588,7 @@ class GPUModelRunner(
|
||||
)
|
||||
)
|
||||
|
||||
intermediate_tensors = self.sync_and_slice_intermediate_tensors(
|
||||
intermediate_tensors = self.sync_and_gather_intermediate_tensors(
|
||||
num_tokens_padded, None, False
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user