Skip to content

Opt moe block by dlblas, when ep > 1 #3461

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
19 changes: 18 additions & 1 deletion lmdeploy/pytorch/backends/cuda/moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,20 @@ def __init__(self,
self.use_deep_gemm = False
logger.warning('For higher performance, please install DeepGEMM https://github.com/deepseek-ai/DeepGEMM')

try:
from dlblas.layers.moe.ep_moe import FusedMoEBlockedF8Impl
self.dlblas_moe = FusedMoEBlockedF8Impl(ep_size=ep_size,
ep_group=ep_group,
top_k=top_k,
num_experts=num_experts,
hidden_dim=hidden_dim,
renormalize=renormalize,
block_size=block_size,
out_dtype=out_dtype)
except ImportError:
self.dlblas_moe = None
logger.warning('For higher performance, please install dlblas https://github.com/DeepLink-org/dlBlas')

def forward(self,
hidden_states: torch.Tensor,
topk_weights: torch.Tensor,
Expand All @@ -598,8 +612,11 @@ def forward(self,
down_scale: torch.Tensor,
expert_list: List[int] = None):
"""forward."""
topk_weights = self.do_renormalize(topk_weights)
step_ctx = get_step_ctx_manager().current_context()
if self.dlblas_moe is not None:
return self.dlblas_moe.forward(hidden_states, topk_weights, topk_ids, gate_up_weights, gate_up_scale,
down_weights, down_scale, step_ctx.is_decoding, expert_list)
topk_weights = self.do_renormalize(topk_weights)
low_latency_mode = step_ctx.is_decoding and self.use_deep_gemm
moe = self.fusedmoe_build(low_latency_mode)
out_states = moe.forward(hidden_states, topk_weights, topk_ids, gate_up_weights, gate_up_scale, down_weights,
Expand Down