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.

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/71618.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/71618.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/71618.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Python的Pandas和matplotlib庫:讓數據可視化賊簡單

在數據爆炸的時代,數據可視化已成為數據分析的關鍵環節。Python 作為強大的編程語言,擁有眾多用于數據可視化的庫,而 pandas 庫在其中扮演著重要角色。它不僅能高效處理和分析數據,還具備強大的數據可視化功能,讓我們輕…

【代碼分享】基于IRM和RRT*的無人機路徑規劃方法詳解與Matlab實現

基于IRM和RRT*的無人機路徑規劃方法詳解與Matlab實現 1. IRM與RRT*的概述及優勢 IRM(Influence Region Map)通過建模障礙物的影響區域,量化環境中的安全風險,為RRT算法提供啟發式引導。RRT(Rapidly-exploring Random…

ubuntu打包 qt 程序,不用每次都用linuxdeployqt打包

用linuxdeployqt打包太麻煩,每次程序編譯都要用linuxdeployqt打包一次,而且每次都要很長時間,通過研究得出一個新的打包方法 1.用用linuxdeployqt得出依賴的庫文件(只要沒有增加新模塊,只要用一次就可以) …

Github 2025-03-06 Go開源項目日報 Top10

根據Github Trendings的統計,今日(2025-03-06統計)共有10個項目上榜。根據開發語言中項目的數量,匯總情況如下: 開發語言項目數量Go項目10Terraform:基礎設施即代碼的開源工具 創建周期:3626 天開發語言:Go協議類型:OtherStar數量:40393 個Fork數量:9397 次關注人數:…

redis 與 DB 的一致性 7 種策略

為什么要使用 redis 做緩存?封底估算為什么是單行數據的QPS,而不是總的? 什么時候使用DB,Redis,本地緩存 數據的分類一致性的方案1. 先清除Redis,再更新 DB2. 先更新DB,再清除 Redis使用場景: 3. 延遲刪除與延遲雙刪使用場景 4. 監聽 binlog 清除5. 雙寫使用場景: 6. 監聽bin…

使用 Elasticsearch 進行集成測試初始化??數據時的注意事項

作者:來自 Elastic piotrprz 在創建應該使用 Elasticsearch 進行搜索、數據聚合或 BM25/vector/search 的軟件時,創建至少少量的集成測試至關重要。雖然 “模擬索引” 看起來很誘人,因為測試甚至可以在幾分之一秒內運行,但它們實際…

【selenium工具操作web頁面中的下拉框元素 】

使用F12定位下拉框中的元素 使用F12定位下拉框中的元素 1、有一類元素不是直接顯示的頁面上的,而是需要點擊某些其他元素后才會顯示在頁面上,比如這里的下拉框。 2、這類元素會有一個特點:鼠標如果移開(沒在元素上),這些元素就會…

C++ set map 詳解

文章目錄 1. 容器2. set和multiset2.1 set2.1.1 構造函數2.1.2 insert和erase2.1.2.1 insert2.1.2.2 erase 2.1.3 查找和訪問2.1.3.1 set迭代器相關2.1.3.2 find && count2.1.3.3 范圍查找 2.2 multiset2.2.1 insert和erase2.2.2 find和count 2.3 set和multiset的在算法…

Unity網絡開發基礎 (2) 網絡協議基礎

本文章不作任何商業用途 僅作學習與交流 部分圖片來自Unity唐老師 目錄 1.虛擬模型 2.實際模型 TCP/IP 3.傳輸層協議 TCP/UDP TCP 協議詳解 1. 核心機制 2. 頭部格式(20 字節最小) UDP 協議詳解 1. 核心特點 2. 頭部格式(固定 8 字節…

HTML label 標簽使用

點擊 <label> 標簽通常會使與之關聯的表單控件獲得焦點或被激活。 通過正確使用 <label> 標簽&#xff0c;可以使表單更加友好和易于使用&#xff0c;同時提高整體的可訪問性。 基本用法 <label> 標簽通過 for 屬性與 id 為 username 的 <input> 元素…

JDBC、MyBatis 、MyBatis-Plus面試總結(一)

以下為你整理了一些 MyBatis 和 MyBatis-Plus 中 mapper.xml 相關的常見面試問題及答案&#xff1a; 基礎概念類 問題 1&#xff1a;什么是 mapper.xml 文件&#xff0c;它在 MyBatis 中有什么作用&#xff1f; 答案&#xff1a;mapper.xml 文件是 MyBatis 中用于定義 SQL 語…

GCC RISCV 后端 -- GCC Passes 注釋

在前面文章提到&#xff0c;當GCC 前端完成對C源代碼解析完成后&#xff0c;就會使用 處理過程&#xff08;Passes&#xff09;機制&#xff0c;通過一系列的處理過程&#xff0c;將 GENERIC IR 表示的C程序 轉步轉換成 目標機器的匯編語言。過程描述如下圖所示&#xff1a; 此…

基于Python實現的智能旅游推薦系統(Django)

基于Python實現的智能旅游推薦系統(Django) 開發語言:Python 數據庫&#xff1a;MySQL所用到的知識&#xff1a;Django框架工具&#xff1a;pycharm、Navicat 系統功能實現 總體設計 系統實現 系統首頁模塊 統首頁頁面主要包括首頁&#xff0c;旅游資訊&#xff0c;景點信息…

鴻蒙全棧開發 D2

課程目標 掌握ArkTS基礎語法與核心概念理解聲明式UI開發范式能獨立開發簡單鴻蒙應用組件建立規范的代碼編寫習慣 第一部分&#xff1a;初識ArkTS 1.1 語言全景認知 #mermaid-svg-V5mnjQN3DAHkfoBo {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size…

【YashanDB認證】yashandb23.3.1 個人版單機部署安裝實踐

YCA報名鏈接如下: YashanDB|崖山數據庫系統YashanDB學習中心-YCA認證詳情 目前免費 主要參考文檔&#xff1a; 單機&#xff08;主備&#xff09;部署 | YashanDB Doc 另外還參考摩天輪文章&#xff1a; YashanDB 23.2.9.101 企業版安裝步驟搶先看&#xff01; - 墨天輪 …

【藍橋杯】每天一題,理解邏輯(3/90)【Leetcode 快樂數】

閑話系列&#xff1a;每日一題&#xff0c;禿頭有我&#xff0c;Hello&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;,我是IF‘Maxue&#xff0c;歡迎大佬們來參觀我寫的藍橋杯系列&#xff0c;我好久沒有更新博客了&#xff0c;因為up豬我寒假用自己的勞動換了…

爬蟲Incapsula reese84加密案例:Etihad航空

聲明: 該文章為學習使用,嚴禁用于商業用途和非法用途,違者后果自負,由此產生的一切后果均與作者無關 一、找出需要加密的參數 1.js運行 atob(‘aHR0cHM6Ly93d3cuZXRpaGFkLmNvbS96aC1jbi8=’) 拿到網址,F12打開調試工具,隨便搜索航班,切換到network搜索一個時間點可以找…

緩存雪崩 緩存擊穿 緩存穿透

1. redis使用場景-緩存-緩存穿透 在實際開發中&#xff0c;Redis 被廣泛應用于緩存&#xff0c;以提高系統性能和響應速度。然而&#xff0c;在使用緩存時&#xff0c;需要注意一些問題&#xff0c;其中 緩存穿透 是一個常見且需要重點關注的場景。 什么是緩存穿透 ● 緩存穿…

【YOLOv12改進trick】多尺度大核注意力機制MLKA模塊引入YOLOv12,實現多尺度目標檢測漲點,含創新點Python代碼,方便發論文

??改進模塊??:多尺度大核注意力機制(MLKA) ??解決問題??:MLKA模塊結合多尺度、門控機制和空間注意力,顯著增強卷積網絡的模型表示能力。 ??改進優勢??:超分辨的MLKA模塊對小目標和模糊目標漲點很明顯 ??適用場景??:小目標檢測、模糊目標檢測等 ??思路…

better-sqlite3之exec方法

在 better-sqlite3 中&#xff0c;.exec() 方法用于執行包含多個 SQL 語句的字符串。與預編譯語句相比&#xff0c;這種方法性能較差且安全性較低&#xff0c;但有時它是必要的&#xff0c;特別是當你需要從外部文件&#xff08;如 SQL 腳本&#xff09;中執行多個 SQL 語句時。…