Skip to content

fix: use dist.reduce_scatter_tensor to avoid memory leak #1688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions vllm_ascend/ops/fused_moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,11 +1342,17 @@
final_hidden_states = final_hidden_states[start:end, :]
dispose_tensor(e_hidden_states)
elif fused_moe_state == FusedMoEState.AllGather:
final_hidden_states = dist._functional_collectives.reduce_scatter_tensor(
e_hidden_states,
"sum",
scatter_dim=0,
group=get_dp_group().device_group)
final_hidden_states_shape = (

Check warning on line 1345 in vllm_ascend/ops/fused_moe.py

View check run for this annotation

Codecov / codecov/patch

vllm_ascend/ops/fused_moe.py#L1345

Added line #L1345 was not covered by tests
e_hidden_states.size(0) //
self.dp_size, ) + e_hidden_states.shape[1:]
final_hidden_states = torch.empty(

Check warning on line 1348 in vllm_ascend/ops/fused_moe.py

View check run for this annotation

Codecov / codecov/patch

vllm_ascend/ops/fused_moe.py#L1348

Added line #L1348 was not covered by tests
final_hidden_states_shape,
dtype=e_hidden_states.dtype,
device=e_hidden_states.device)
dist.reduce_scatter_tensor(final_hidden_states,

Check warning on line 1352 in vllm_ascend/ops/fused_moe.py

View check run for this annotation

Codecov / codecov/patch

vllm_ascend/ops/fused_moe.py#L1352

Added line #L1352 was not covered by tests
e_hidden_states,
op=dist.ReduceOp.SUM,
group=get_dp_group().device_group)
final_hidden_states = final_hidden_states[:num_tokens]
dispose_tensor(e_hidden_states)
else:
Expand Down
Loading