DeepSeek group-limited expert routing和负载均衡
Ref
https://github.com/deepseek-ai/DeepSeek-V3/blob/main/inference/model.py
GitHub - deepseek-ai/EPLB: Expert Parallelism Load Balancer
DeepSeek-V3 Technical Report
DeepSeek的路由方法
class Gate(nn.Module):def __init__(self, args: ModelArgs):super().__init__()self.dim = args.dimself.topk = args.n_activated_expertsself.n_groups = args.n_expert_groupsself.topk_groups = args.n_limited_groupsself.score_func = args.score_funcself.route_scale = args.route_scaleself.weight = nn.Parameter(torch.empty(args.n_routed_experts, args.dim))self.bias = nn.Parameter(torch.empty(args.n_routed_experts)) if self.dim == 7168 else Nonedef forward(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:scores = linear(x, self.weight)if self.score_func == "softmax":scores = scores.softmax(dim=-1, dtype=torch.float32)else:scores = scores.sigmoid()original_scores = scoresif self.bias is not None:scores = scores + self.biasif self.n_groups > 1: # n_groups = n_expert_groups = 8scores = scores.view(x.size(0), self.n_groups, -1)if self.bias is None:group_scores = scores.amax(dim=-1)else:group_scores = scores.topk(2, dim=-1)[0].sum(dim=-1)indices = group_scores.topk(self.topk_groups, dim=-1)[1] # topk_groups = n_limited_groups = 4mask = torch.zeros_like(scores[..., 0]).scatter_(1, indices, True)scores = (scores * mask.unsqueeze(-1)).flatten(1)indices = torch.topk(scores, self.topk, dim=-1)[1] # topk = n_activated_experts = 8weights = original_scores.gather(1, indices)if self.score_func == "sigmoid":weights /= weights.sum(dim=-1, keepdim=True)weights *= self.route_scalereturn weights.type_as(x), indices
每个token有1个共享专家和256个路由专家,对这256个路由专家选择出8个专家进行实际的计算。
常规的MOE是根据score选择最高的topk个专家,具有较大的随机性。
但是DeepSeek把这256个专家分成了连续的n_expert_groups=8个组,然后根据每个组的最高score选择出n_limited_groups=4个组,其他组的score值清零。使得最终选择的topk=8随机分布在4个组内。但并没有限制每个组一定有多少个专家选中。这一定程度上限制了topk出现的随机性。
Expert-Parallel Load Balancer
- 核心问题:对于给定 MoE 模型,存在一些天然的高负载专家(expert),导致不同 GPU 的专家计算负载不均衡
- 优化目标:每个 GPU 上的专家计算量均衡(即最小化所有 GPU 的 dispatch 接收量的最大值)。To achieve load balancing among different experts in the MoE part, we need to ensure that each GPU processes approximately the same number of tokens.
Moreover, thanks to the group-limited expert routing used in DeepSeek-V3, we also attempt to place the experts of the same group to the same node to reduce inter-node data traffic, whenever possible.
Prefill阶段 Hierarchical Load Balancing
Prefill:路由专家 EP32、MLA 和共享专家 DP32,一个部署单元是 4 节点,32 个冗余路由专家,每张卡 9 个路由专家和 1 个共享专家
When the number of server nodes divides the number of expert groups, we use the hierarchical load balancing policy to harness the group-limited expert routing. We first pack the expert groups to nodes evenly, ensuring the loads of different nodes are balanced. Then, we replicate the experts within each node. Finally, we pack the replicated experts to individual GPUs to ensure different GPUs are load-balanced. The hierarchical load balancing policy can be used in prefilling stage with a smaller expert-parallel size.
To achieve load balancing among different experts in the MoE part, we need to ensure that each GPU processes approximately the same number of tokens. To this end, we introduce a deployment strategy of redundant experts, which duplicates high-load experts and deploys them redundantly. The high-load experts are detected based on statistics collected during the online deployment and are adjusted periodically (e.g., every 10 minutes). After determining the set of redundant experts, we carefully rearrange experts among GPUs within a node based on the observed loads, striving to balance the load across GPUs as much as possible without increasing the cross-node all-to-all communication overhead. For the deployment of DeepSeek-V3, we set 32 redundant experts for the prefilling stage. For each GPU, besides the original 8 experts it hosts, it will also host one additional redundant expert.
Furthermore, in the prefilling stage, to improve the throughput and hide the overhead of all-to-all and TP communication, we simultaneously process two micro-batches with similar computational workloads, overlapping the attention and MoE of one micro-batch with the dispatch and combine of another.
Finally, we are exploring a dynamic redundancy strategy for experts, where each GPU hosts more experts (e.g., 16 experts), but only 9 will be activated during each inference step. Before the all-to-all operation at each layer begins, we compute the globally optimal routing scheme on the fly. Given the substantial computation involved in the prefilling stage, the overhead of computing this routing scheme is almost negligible.
Decoding阶段 Global Load Balancing
Decode:路由专家 EP144、MLA 和共享专家 DP144,一个部署单元是 18 节点,32 个冗余路由专家,每张卡 2 个路由专家和 1 个共享专家
In other cases, we use the global load balancing policy that replicates the experts globally regardless of expert groups, and pack the replicated experts to individual GPUs. This policy can be adopted in decoding stage with a larger expert-parallel size.
During decoding, we treat the shared expert as a routed one. From this perspective, each token will select 9 experts during routing, where the shared expert is regarded as a heavy-load one that will always be selected. The minimum deployment unit of the decoding stage consists of 40 nodes with 320 GPUs. The attention part employs TP4 with SP, combined with DP80, while the MoE part uses EP320. For the MoE part, each GPU hosts only one expert, and 64 GPUs are responsible for hosting redundant experts and shared experts. All-to-all communication of the dispatch and combine parts is performed via direct point-to-point transfers over IB to achieve low latency. Additionally, we leverage the IBGDA (NVIDIA, 2022) technology to further minimize latency and enhance communication efficiency.
Similar to prefilling, we periodically determine the set of redundant experts in a certain interval, based on the statistical expert load from our online service. However, we do not need to rearrange experts since each GPU only hosts one expert. We are also exploring the dynamic redundancy strategy for decoding. However, this requires more careful optimization of the algorithm that computes the globally optimal routing scheme and the fusion with the dispatch kernel to reduce overhead.
相关文章:
DeepSeek group-limited expert routing和负载均衡
Ref https://github.com/deepseek-ai/DeepSeek-V3/blob/main/inference/model.py GitHub - deepseek-ai/EPLB: Expert Parallelism Load Balancer DeepSeek-V3 Technical Report DeepSeek的路由方法 class Gate(nn.Module):def __init__(self, args: ModelArgs):super().__…...
智慧消防新篇章:4G液位/压力传感器,筑牢安全防线!
火灾无情,防患未“燃”!在智慧消防时代,如何实现消防水系统的实时监测、预警,保障人民生命财产安全?山东一二三物联网深耕物联网领域,自主研发4G液位、4G压力智能传感器,为智慧消防水位、水压无…...
C++ primier plus 函数探幽第二部分
系列文章目录 C primer plus 第一节 步入C-CSDN博客 C primer plus 第二节 hello world刨析-CSDN博客 C primer plus 第三节 数据处理-CSDN博客 C primer plus 第四节 复合类型-CSDN博客 C primer plus 第五节 循环-CSDN博客 C primier plus 第七节 函数探幽第一部分-CSDN博客 …...
DBus名词术语命名规范详解:构建清晰、规范的DBus通信
引言 DBus(Desktop Bus)是一种高效、灵活的进程间通信(IPC)机制,广泛应用于Linux桌面环境中。为了确保DBus通信的清晰性和规范性,DBus定义了一套严格的命名规范,涵盖了总线、服务名、对象路径、…...
用低代码平台集成人工智能:无需专业开发也能实现智能化
引言:人工智能的普及与企业需求 随着人工智能(AI)技术的飞速发展,越来越多的企业开始意识到其在提升运营效率、优化客户体验和推动业务创新方面的巨大潜力。从智能客服到自动化决策支持,从数据分析到个性化推荐&#x…...
Java停车平台高并发抢锁技术方案设计 - 慧停宝开源停车管理平台
Java停车平台高并发抢锁技术方案设计 一、业务场景特征 瞬时流量峰值 早晚高峰时段(07:30-09:00, 17:30-19:00)请求量激增10倍热门商圈停车场每秒并发请求可达5000 QPS 资源竞争特性 单个车位被多人同时抢占(超卖风险)用户操作链…...
C++关键字:typename 用于依赖名消歧器(disambiguator)
目录 1. 说明 2. 示例 1. 说明 在模板(包括别名模板)的声明或定义中,非当前实例的成员且依赖于模板参数的名称不视为类型,除非使用关键字 typename 或除非它已被建立为类型名称(例如使用 typedef 声明或用于命名基…...
第六课:数据库集成:MongoDB与Mongoose技术应用
本文详细介绍了如何在Node.js应用程序中集成MongoDB数据库,并使用Mongoose库进行数据操作。我们将涵盖MongoDB在Ubuntu 20系统中的安装、Bash命令的CRUD操作、Mongoose数据建模(Schema/Model)、关联查询与聚合管道,以及实战案例—…...
TypeError: Cannot set properties of undefined (setting ‘xxx‘)
🤍 前端开发工程师、技术日更博主、已过CET6 🍨 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 🕠 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》、《前端求职突破计划》 🍚 蓝桥云课签约作者、…...
Gravitino源码分析-SparkConnector 实现原理
Gravitino SparkConnector 实现原理 本文参考了官网介绍,想看官方解析请参考 官网地址 本文仅仅介绍原理 文章目录 Gravitino SparkConnector 实现原理背景知识-Spark Plugin 介绍(1) **插件加载**(2) **DriverPlugin 初始化**(3) **ExecutorPlugin 初始化**(4) *…...
windows下使用msys2编译ffmpeg
三种方法: 1、在msys2中使用gcc编译 2、在msys2中使用visual studio编译(有环境变量) 3、在msys2中使用visual studio编译(无环境变量) 我的环境: 1、msys2-x86_64-20250221 2、vs2015 3、ffmpeg-7.1…...
Linux内核自定义协议族开发指南:理解net_device_ops、proto_ops与net_proto_family
在Linux内核中开发自定义协议族需要深入理解网络协议栈的分层模型。net_device_ops、proto_ops和net_proto_family是三个关键结构体,分别作用于不同的层次。本文将详细解析它们的作用、交互关系及实现方法,并提供一个完整的开发框架。 一、核心结构体的作用与层级关系 struct…...
可视化+图解链表
链表(Linked list)是一种常用的数据结构,它由一系列节点组成,每个节点包含数据域和指针域。指针域存储了下一个节点的地址,从而建立起各节点之间的线性关系。 1、链表节点 1.1 节点构成 链表节点如下图所示ÿ…...
Docker参数,以及仓库搭建
一。Docker的构建参数 注释: 1.对于CMD,如果不想显示,而是使用交互界面:docker run -ti --rm --name test2 busybox:v5 sh 2.对于CMD,一个交互界面只可以使用一个,如果想多次使用CMD,则用ENTR…...
正十七边形尺规作图证明——从高斯的发现到几何实现
正十七边形尺规作图证明——从高斯的发现到几何实现 1. 引言:一个历史性的数学突破 在欧几里得几何中,尺规作图(仅使用直尺和圆规)是最为基础的几何构造方法。古希腊数学家已知如何构造正三角形、正方形和正五边形,但…...
常见Web应用源码泄露问题
文章目录 前言一、常见的源码泄露漏洞git源码泄露SVN源码泄露DS_Store文件泄漏网站备份压缩文件泄露WEB-INF/web.xml泄露CVS泄露.hg源码泄露Bazaar/bzr泄露.swp文件泄露 前言 在Web应用方面对于安全来说,可能大家对SQL注入、XSS跨站脚本攻击、文件上传等一些漏洞已…...
如何使用 Python+Flask+win32print 实现简易网络打印服务1
Python 实现网络打印机:Flask win32print 在工作场景中,我们可能需要一个简单的网页接口,供他人上传文档并自动打印到指定打印机。 本文将演示如何使用 Python Flask win32print 库来实现这一需求。 代码详见:https://github.…...
使用Modelsim手动仿真
FPGA设计流程 在设计输入之后,设计综合前进行 RTL 级仿真,称为综合前仿真,也称为前仿真或 功能仿真。前仿真也就是纯粹的功能仿真,主旨在于验证电路的功能是否符合设计要求,其特点是不考虑电路门延迟与线延迟。在完成一个设计的代码编写工作之后,可以直接对代码进行仿真,…...
DeepSeek、Grok与ChatGPT:AI三巨头的技术博弈与场景革命
## 引言:AI工具的三国杀时代 2025年的AI江湖,DeepSeek以黑马之姿横扫全球应用榜单,Grok 3凭借马斯克的狂言抢占头条,ChatGPT则稳坐行业王座。这场技术竞赛不仅是参数量的比拼,更是一场关于效率、成本与场景适配的终极…...
windows自动锁屏,并且要输入密码。如何取消?
Windows 电脑自动锁屏并需要输入密码,通常是因为系统的 电源和睡眠设置 或 组策略 设定了自动锁屏。你可以按照以下方法取消自动锁屏或去掉密码要求: 方法 1:修改 Windows 设置 取消锁屏时间 Win I 打开 设置,进入 系统 → 电源和…...
Redis 主从复制、哨兵与集群的关系及工作原理详解
一、核心概念与关系 Redis 的 主从复制、哨兵(Sentinel) 和 集群(Cluster) 是逐步演进的高可用与分布式解决方案,三者关系如下: 主从复制:数据冗余与读写分离的基础。 哨兵:在主从…...
XSD 对 XML 数据格式验证 java
xsd文件,文件名bean.xsd,放在当前java文件目录下 <?xml version"1.0" encoding"UTF-8"?> <xs:schema xmlns:xs"http://www.w3.org/2001/XMLSchema"><xs:element name"bean"><xs:comple…...
利用 ArcGIS Pro 快速统计省域各市道路长度的实操指南
在地理信息分析与处理的工作中,ArcGIS Pro 是一款功能强大的 GIS 软件,它能够帮助我们高效地完成各种复杂的空间数据分析任务。 现在,就让我们一起深入学习如何借助 ArcGIS Pro 来统计省下面各市的道路长度,这一技能在城市规划、…...
1.4 单元测试与热部署
本次实战实现Spring Boot的单元测试与热部署功能。单元测试方面,通过JUnit和Mockito等工具,结合SpringBootTest注解,可以模拟真实环境对应用组件进行独立测试,验证逻辑正确性,提升代码质量。具体演示了HelloWorld01和H…...
蓝桥杯备考:六级词汇积累(day5)
dense 稠密的 condense 压缩 compassion 同情,怜悯 compact 紧凑的,紧密的 resent 愤恨 sober 清醒的 sole 唯一的,独占的 solely only solemn 表情严肃的,庄重的 stun 使昏迷 Stunned by the impact, he lay on the ground won…...
掌握Kubernetes Network Policy,构建安全的容器网络
在 Kubernetes 集群中,默认情况下,所有 Pod 之间都是可以相互通信的,这在某些场景下可能会带来安全隐患。为了实现更精细的网络访问控制,Kubernetes 提供了 Network Policy 机制。Network Policy 允许我们定义一组规则,…...
结合rpart包的决策树介绍
决策树与CART算法 决策树是一种基于树状结构的监督学习算法。它通过从根节点开始递归地对特征进行划分,构建出一棵树来进行决策。决策树的构建过程需要解决的重要问题有三个:如何选择自变量、如何选择分割点、确定停止划分的条件。解决这些问题是希望随…...
VScode代码格式化插件black失效问题
之前有如下提示: 没太当回事,发现还能用。之后突然就用不了了,跟着官方插件的文档来查看log: 查看发现提示: Message: TypeError: type object is not subscriptable 在github界面找到解决方案:安装Versio…...
【经验分享】Ubuntu20.04编译RK3568 AI模型报错问题(已解决)
【经验分享】Ubuntu20.04编译RK3568 AI模型报错问题(已解决) 前言问题现象问题分析解决方案总结 前言 这里使用的是Rockchip提供的rknn_model_zoo,https://github.com/airockchip/rknn_model_zoo/tree/main 此解决方案适用于Rockchip芯片在U…...
AI革命先锋:DeepSeek与蓝耘通义万相2.1的无缝融合引领行业智能化变革
云边有个稻草人-CSDN博客 目录 引言 一、什么是DeepSeek? 1.1 DeepSeek平台概述 1.2 DeepSeek的核心功能与技术 二、蓝耘通义万相2.1概述 2.1 蓝耘科技简介 2.2 蓝耘通义万相2.1的功能与优势 1. 全链条智能化解决方案 2. 强大的数据处理能力 3. 高效的模型…...
