[sgl] fix using symmetric memory issues for attention_tp (#22286)
This commit is contained in:
@@ -1724,6 +1724,7 @@ def initialize_model_parallel(
|
|||||||
moe_data_model_parallel_size: int = 1,
|
moe_data_model_parallel_size: int = 1,
|
||||||
backend: Optional[str] = None,
|
backend: Optional[str] = None,
|
||||||
duplicate_tp_group: bool = False,
|
duplicate_tp_group: bool = False,
|
||||||
|
enable_symm_mem: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Initialize model parallel groups.
|
Initialize model parallel groups.
|
||||||
@@ -1884,7 +1885,7 @@ def initialize_model_parallel(
|
|||||||
group_ranks,
|
group_ranks,
|
||||||
get_world_group().local_rank,
|
get_world_group().local_rank,
|
||||||
backend,
|
backend,
|
||||||
use_pynccl=SYNC_TOKEN_IDS_ACROSS_TP,
|
use_pynccl=SYNC_TOKEN_IDS_ACROSS_TP or enable_symm_mem,
|
||||||
use_mscclpp_allreduce=False,
|
use_mscclpp_allreduce=False,
|
||||||
use_custom_allreduce=False,
|
use_custom_allreduce=False,
|
||||||
use_torch_symm_mem_allreduce=False,
|
use_torch_symm_mem_allreduce=False,
|
||||||
|
|||||||
@@ -1503,9 +1503,13 @@ class RowParallelLinear(LinearBase):
|
|||||||
# Only fuse bias add into GEMM for rank 0 (this ensures that
|
# Only fuse bias add into GEMM for rank 0 (this ensures that
|
||||||
# bias will not get added more than once in TP>1 case)
|
# bias will not get added more than once in TP>1 case)
|
||||||
bias_ = None if (self.tp_rank > 0 or self.skip_bias_add) else self.bias
|
bias_ = None if (self.tp_rank > 0 or self.skip_bias_add) else self.bias
|
||||||
with use_symmetric_memory(
|
if self.use_dp_attention_reduce:
|
||||||
get_tp_group(), disabled=not is_allocation_symmetric()
|
symm_ctx = use_symmetric_memory(get_attention_tp_group())
|
||||||
):
|
else:
|
||||||
|
symm_ctx = use_symmetric_memory(
|
||||||
|
get_tp_group(), disabled=not is_allocation_symmetric()
|
||||||
|
)
|
||||||
|
with symm_ctx:
|
||||||
output_parallel = self.quant_method.apply(self, input_parallel, bias=bias_)
|
output_parallel = self.quant_method.apply(self, input_parallel, bias=bias_)
|
||||||
|
|
||||||
if self.reduce_results and self.tp_size > 1 and not skip_all_reduce:
|
if self.reduce_results and self.tp_size > 1 and not skip_all_reduce:
|
||||||
|
|||||||
@@ -1027,6 +1027,7 @@ class ModelRunner(ModelRunnerKVCacheMixin):
|
|||||||
attention_context_model_parallel_size=self.attn_cp_size,
|
attention_context_model_parallel_size=self.attn_cp_size,
|
||||||
moe_data_model_parallel_size=self.moe_dp_size,
|
moe_data_model_parallel_size=self.moe_dp_size,
|
||||||
duplicate_tp_group=self.server_args.enable_pdmux,
|
duplicate_tp_group=self.server_args.enable_pdmux,
|
||||||
|
enable_symm_mem=self.server_args.enable_symm_mem,
|
||||||
)
|
)
|
||||||
initialize_dp_attention(
|
initialize_dp_attention(
|
||||||
server_args=self.server_args,
|
server_args=self.server_args,
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ class LlamaMLP(nn.Module):
|
|||||||
reduce_results: bool = True,
|
reduce_results: bool = True,
|
||||||
tp_rank: Optional[int] = None,
|
tp_rank: Optional[int] = None,
|
||||||
tp_size: Optional[int] = None,
|
tp_size: Optional[int] = None,
|
||||||
|
use_dp_attention_reduce: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.gate_up_proj = MergedColumnParallelLinear(
|
self.gate_up_proj = MergedColumnParallelLinear(
|
||||||
@@ -93,6 +94,7 @@ class LlamaMLP(nn.Module):
|
|||||||
reduce_results=reduce_results,
|
reduce_results=reduce_results,
|
||||||
tp_rank=tp_rank,
|
tp_rank=tp_rank,
|
||||||
tp_size=tp_size,
|
tp_size=tp_size,
|
||||||
|
use_dp_attention_reduce=use_dp_attention_reduce,
|
||||||
)
|
)
|
||||||
if hidden_act != "silu":
|
if hidden_act != "silu":
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|||||||
Reference in New Issue
Block a user