京東超大規模聯邦學習探索實踐

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對於AI飛速發展的今天來說,大規模的多維度、高質量的數據是其成功的關鍵要素,也是制約其進一步發展的重要瓶頸。隨着大家對數據的重要性與隱私性的認知程度的不斷提升,跨組織的數據的合作越來越謹慎,相關隱私法律法規也陸續出臺 ( GDPR ),這樣就造成了大量了的數據孤島,無法充分的利用數據進行分析、決策,嚴重製約了AI的發展。聯邦學習在保證數據隱私安全及合法合規的基礎上,打破數據孤島,實現共同建模,共創共贏,將成爲未來AI發展的一個重要方向,9N-FL作爲聯邦學習的整體開源解決方案,也會在未來發揮越來越大的作用。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本文將通過了解聯邦學習的原理以及解決方案9N-FL,並且結合本公司的業務,進行應用,爲大分享如何開闢新的業務模式與增長點。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"背景"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/3c\/3cd0ed25f45a338ef55e218fe49273f4.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"基於數據孤島的考量而提出聯邦學習,數據孤島的產生有以下兩方面的原因:"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"數據重要性:數據是AI的石油,加速了AI的高速發展,同時多維度高質量的數據是制約其進一步發展的瓶頸。隨着各個組織對於數據重視程度的不斷提升,跨組織以及組織內部不同部門之間的數據合作將變得越來越謹慎,大量數據以孤島的形式存在。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"數據隱私法:鑑於數據隱私的重要性,國內外對於數據的保護意識逐步加強。2018年歐盟發佈了《通用數據保護條例》 ( GDPR ),我國國家互聯網信息辦公室起草了《數據安全管理辦法 ( 徵求意見稿 ) 》,因此數據在安全合規的前提下自由流動成了大勢所趨。這些法律法規的出臺,不同程度的對人工智能傳統處理數據的方式提出了更多的挑戰。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"上述都限制了數據的流動,造成了大量信息孤島。如右圖所示,主要有兩種方式造成信息孤島:第一是企業獲得用戶信息越來越難;第二是企業之間數據不共享。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"聯邦學習概述"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1. 聯邦學習概述"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/09\/09da6a169b2b90caf3e36b5d2805710b.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"信息孤島的解決方案是聯邦學習。2016年,谷歌提出在安卓手機用戶中進行聯邦學習,解決個人用戶數據在終端上的隱私問題,它可以不上傳用戶隱私數據,在終端上進行模型訓練。後續衆多業內研究機構和組織對聯邦學習投入了極大的熱情,研究了更加安全、使用範圍更廣的聯邦學習機制,將聯邦學習應用到更加廣闊的領域。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"聯邦學習的本質是基於數據隱私保護的一種分佈式機器學習技術或機器學習框架。聯邦學習的目標是在保證數據隱私安全及合法合規的基礎上,在模型無損的前提實現共同建模,提升AI模型的效果。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2. 聯邦學習的特徵"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/f8\/f8e18be65258610a7ff7384f4bd57b0e.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"聯邦學習框架有以下四個特徵:"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"兩個或以上兩個以上參與方,共同構建機器學習模型。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在模型訓練過程中,每個參與方數據都不會離開本地,也就是它的原始特徵不會離開本地。在進行聯合訓練的時候,其實是把分佈式平臺的計算資源放到多家公司的機房裏分開部署,而不是把數據集中起來放到一個地方進行訓練。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"模型的相關信息以加密方式傳輸。因爲在模型訓練的時候,需要傳遞梯度這些中間結果,所有的中間結果是通過加密的方式進行傳輸,並且保證任何參與方都不能推斷出其他方的原始數據。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"聯邦學習模型的性能要充分逼近理想模型的性能。所有數據集中在一起搭建的模型和聯邦學習這種跨域進行訓練的模型的性能是比較接近的,右側是性能逼近的公式。"}]}]}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"3. 聯邦學習的分類"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/c6\/c627139f2009ec858da5881d07baaadc.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"聯邦學習主要分爲三大類:橫向聯邦學習、縱向聯邦學習、聯邦遷移學習,聯邦遷移學習用的稍微少一些。"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"橫向聯邦學習:比如剛纔介紹的谷歌輸入法案例,就是一個比較典型的橫向聯邦學習的案例。它的特點是各個參與方數據的特徵維度是相同的,但是樣本ID不同。適用於銀行以及手機終端邊緣計算等同質數據場景。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"縱向聯邦學習:它的特點是數據樣本ID基本相同,特徵不同。比如兩個數據集的用戶大規模重疊,但它們的特徵不一樣。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"9N-FL主要解決的是縱向聯邦學習的問題。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"4. 聯邦學習的架構"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/a5\/a5ec3a0e9d46702beb3f8d833784de8e.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如圖是聯邦學習的架構,主要簡單介紹了橫向聯邦學習架構和縱向聯邦學習架構。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"京東開源聯邦學習解決方案-9NFL"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1. 9N-FL總體架構"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/cf\/cf884a0034cb0e163ef3fa921991d55f.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"項目背景:我們部門主要是做廣告營銷,在京東站外的一些營銷場景中有很多用戶,對於我們來說我們並不認識,比如在抖音、快手這些渠道投放廣告的時候,這個用戶我們不認識,但我們又想給他都放廣告,對於頭條和快手來說,他們不可能把用戶的原始數據給我們。我們就想了一個辦法,可以做一下聯邦學習,這樣對於我們不認識的用戶,也可以去進行廣告競拍。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"項目大概是在2019年11月份進行的開發,2020上半年進行了正式的上線,並且在2020年9月份完成了正式的對外開源。9N-FL平臺主要包含以下幾個重要的部分:"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"多任務跨域調度"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"跨域高性能網絡代理"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大規模樣本匹配"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大規模跨域聯合訓練"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"模型分層級加密"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"主要創新點:"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"業界前沿技術自主研發:從0到1開發設計的,實現了從大規模樣本匹配到模型訓練\/預測的完整解決方案。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"營銷推薦領域技術落地:支持百億規模的樣本和百T容量的數據,並且在電商領域進行了業務落地,取得了不錯的落地效果。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"複雜場景下平臺演進:整個場景比較複雜,涉及到跨域跨網,在這種複雜多變的環境下,要進行聯合訓練,難度還是比較大的。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"取得的成績:自上線以來,九數聯邦學習平臺(9N-FL)在取得了較好業務成績的同時,也經受住了業務大數據、大算力的考驗。在與媒體進行京東廣告投放業務場景中,基於媒體側大量的數據(例如,媒體興趣標籤)、京東側大量的用戶商業興趣及商品標籤數據,雙方使用聯邦學習平臺聯合建模,來優化廣告的觸發召回、CTR\/CVR模型等多個模塊,最終成功上線,取得了大概15%的收入提升。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2. 9N-FL項目時間軸"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/37\/370535f6df3f17999cc61c87ddd05335.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這個是9N-FL的一個時間軸,2017和2018年做聯邦學習的比較多,像微衆銀行、騰訊、百度、阿里,它們相對來說比較早。京東是在2019年11月正式開始進行聯邦學習平臺的開發,當時是基於業務爲出發點進行開發;在2020年4月份,完成了平臺的開發落地,雙方開始聯合建模;在2020年中做出了業務效果,並且進行了上線。在2020年9月,進行了平臺的開源,在github上搜9N-FL就可以搜到。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"3. 京東開源聯邦學習解決方案9N-FL"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/66\/663287acbb80859d53fbf3fba2a2393a.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對於聯邦學習來說,它是一個全新的多交叉的領域知識,主要需要以下幾個方面的能力:"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"數據隱私:同態加密、可信計算、祕密分享、混淆電路爲聯邦學習奠定了一個堅實的基礎。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"抽象異構資源限制:聯邦學習不光要構建在不同公司,兩個公司的技術棧、技術能力、基礎設施都不一樣,可以用雲平臺K8S進行一些抽象,另外還需要跨網,比如在聯合訓練的過程中、在大規模樣本匹配中,需要大量跨網的交互,而且整個交互過程非常複雜、異常情況比較多。我們抽象了一些網絡代理,自研了基於應用層的一些高效的網絡協議。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"高性能、高可靠:高效的網絡協議、可靠的容錯機制 failover。比如在聯合訓練過程中,兩邊集羣可能是若干臺機器,但如果有一臺機器宕機,整個模型訓練就停止了,需要重新進行訓練。最開始我們有些優化沒有做的很完整,模型訓練時間較長,大概是七八天,在fail的情況下重新訓練就有很大的問題,整個研發進度無法保障。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"聯合建模:聯邦學習平臺對模型結構不做限制。在聯邦學習過程中,大家都是獨立建模,也就是我和另一家公司在建模的過程中,我們可以互不感知對方的模型結構,只關注上層連接之後的反向梯度的傳輸。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"聯邦學習是一個跨多個領域的技術,它包含了大數據、實時計算、雲平臺、機器學習、深度學習、高併發架構、密碼學等方面的一些知識,整體要求比較高。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"4. 9N-FL具體工作"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/60\/60c1db0647f776ea193a0fc6efd30f05.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"具體工作分爲以下幾個方面:"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"組件化:平臺的一些策略、一些組件都是可以任意組合。比如有的公司數據體量比較大,可以用hadoop做數據存儲;有的公司數據體量比較小,可能是一個本地文件,也可能是數據庫這種方式,都可以支持。9N-FL平臺可以從大、中、小方面進行一個全方位的覆蓋,另外可支持策略的熱插拔。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"高可靠:第一是虛擬化技術,這種虛擬化技術有底層團隊在維護。第二是failover機制,比如節點故障的恢復。第三是高效、高容錯的網絡協議。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大數據、大算力:擁有橫向水平擴展能力,整個系統支持分佈式以及大數據的一些外圍工具:HDFS、分佈式文件系統、實時數據kafka等。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"高性能:自研的分佈式異步框架、高效自研網絡傳輸應用協議,實現儘可能的併發。大部分模塊採用C++來編寫,包括訓練器,訓練器基於tensorflow,並沒有重複造輪子。"}]}]}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"5. 9N-FL聯邦學習模型"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/0a\/0a236a1993bc8bb991e10227ef9c0169.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"整體架構圖中公司A和公司B的數據是無法打通的,其實這就是一個超大規模的樣本匹配工作,爲下一步建模做準備。在傳統的聯邦學習過程中,一條樣本就是一個完整的輸入,中間可能會進行拆圖,沒有在最開始的輸入過程中拆,只是在中間的某一步進行了拆圖。但是聯邦學習從縱向上來看,把一個用戶的樣本數據一下子拆成了兩部分,聯邦學習的基礎就是一個超大規模樣本匹配的過程。接着往上就是大規模跨域聯合建模,藍色和紫色模型互不感知,只是在上層進行了數據連接,算一下loss作爲反向梯度傳輸。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"聯邦學習主要解決數據跨域問題,保證數據不出域,也就是計算資源向數據資源靠攏,保證數據安全隱私、安全合規。聯邦學習之前,只能用左邊的一路或者右邊的一路數據進行建模,其實模型能力也是可以的,但兩個數據如果結合在一起,從直觀或者理論上來說,這個模型能力肯定是有一些顯著的增強,我們通過實踐證明了這一點。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們將9N-FL的應用場景瞄準了大數據營銷這塊,當然金融領域也在考慮範疇之內。金融對數據隱私性要求比較高,但對實時性要求不高,所以一般採用加密或比較簡單的模型,比如LR模型或者樹模型,它的數據量也比較小,大概幾十萬,離線可能跑幾個小時。大數據營銷這塊的場景就比較多。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"6. 9N-FL分層架構"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/5f\/5f7dc9a8c0f5f4af91dff7f2b96f7cf8.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"基礎資源層:包括基礎硬件資源、網絡"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"算計資源層:改造TensorFlow、op、加密模塊"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"計算調度層:Coordinator、Sample Matching、Union Training"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"UI層:待完善"}]}]}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"7. 9N-FL總體架構"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/43\/433d8c6633442f7598ec2908f3b91fc7.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"9N-FL的整體架構圖是一個對稱的結構,服務部署在兩家公司,每家公司都有一套完整的服務。比如Coordinator:它是整個系統的總控;Proxy:涉及到跨網,可以理解成gateway;Resource Manager:資源控制;Trainer:訓練器。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"詳細過程:Coordinator分爲leader、follower兩個角色。我們平時在機器學習平臺訓練的時候,只要開啓訓練就好,因爲不涉及跟別人的協調,但是對於聯邦學習來說,開啓訓練的時候涉及一個協調的問題,誰是主導者誰是跟隨者?主導發起訓練的就是主導者,比如圖的左側是主導者,它就是一個leader,右側就是跟隨者follower。所有的調度單元都是基於一個任務來調度,整個系統支持多任務的調度。首先左側的Coordinator通知對端,我要進行訓練,並且告訴對端我的樣本meta信息,包含樣本 ( 比如ctr、cvr樣本 ) 信息、時間信息,兩邊還有一些協商,就是針對這次任務,我要開啓多少個trainer,比如要開啓20個,那麼兩邊都開啓了20個trainer,但是怎麼調度起來呢?聯邦學習可以仿照傳統的機器學習,也就是現在的樣本分了兩個訓練器,一邊消費一半,這種情況下,我把樣本拼起來,把訓練器拼起來,我們就做了這麼一件事兒,把不同的訓練器做了個配對。配對完之後就涉及到訓練器的協商,左邊的訓練器會通知右側訓練器,告訴它我在我們這邊拿到了一條數據,這個數據的meta信息是什麼,同時會告訴對端也去拿相應的文件,兩邊都把相應文件拉下來之後,相當於做了消費同樣文件的動作。這樣兩邊就可以同時進行訓練,在訓練的過程中,不斷的交換這些梯度,把整個模型構建起來。Proxy的作用是路由控制,比如第一個trainer把梯度分發給對端proxy之後,對端proxy知道它是要發給第一個trainer而不是發給第二個trainer。整個proxy是一個無狀態的服務,它起到一個gateway的作用,是整個系統對外的暴露。我可能只監聽對外的一些端口,會有一些安全措施在裏面,裏面的服務包括Coordinator、Resource manager、Trainer,它們都是不對外的,保證了數據安全。Trainer主要包含兩個動作,一個就是兩邊取完數據後的協商,另一個就是在訓練過程中正向結果的傳輸和反向梯度的傳遞。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"整體調度:"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/ab\/ab7b1c1bc55fb6fe2a3c8eb5f0877d81.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"整體調度這塊是整個系統的總控,它控制整個系統的生命週期,比如任務的啓動、停止、監控;資源的申請,比如會給trainer申請資源;多任務的併發調度,比如我們進行聯邦學習的時候,是和多家公司進行合作,每家公司有不同的訓練目標,有的是訓練轉化的、有的是訓練召回的,建模方式可能不太一樣,所以說是多任務的並行併發調度。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"資源管理:"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/d6\/d68af316419239a723912899b76d4b4c.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"資源管理用的是K8S。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"加密訓練:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同態加密:滿足密文同態運算性質的加密算法,即數據經過同態加密之後,對密文進行特定的計算,得到的密文計算結果在進行對應的同態解密後的明文等同於對明文數據直接進行相同的計算,實現數據的“可算不可見”。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"假如有兩個整數A和B,要計算A+B的和C是多少。兩個數據對別人是不可見的,將這兩個數據拿給第三方計算,算之前同時先對A和B進行加密,再對密文計算結果,在整個計算過程中,原始數據A和B沒有暴露,得到密文結果後,再用同態解密的方式將密文解掉。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/b4\/b4fb26d8487ca37731f61ca885a82c16.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"線性迴歸模型的訓練步驟:例子是基於第三方的方式,第三方持有私鑰,他會把公鑰發給A和B,公鑰進行加密,私鑰進行解密。算loss和算梯度的整個過程是加密的,之前未加密的計算都對應着一個加密的計算。對於LR模型和樹模型都有公開的加密解決方案,計算速度偏慢,無法用在在線。京東在做對神經網絡加密方案的研究,目前已經在實驗階段,後續會有可用於實時的方案。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"8. 9N-FL開源解決方案"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/18\/18d7b6a1fa7f53600ad740f258f3d399.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這塊是京東9N-FL開源的情況,大家有問題可以提issue。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"業務效果"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/de\/dec077dc7e21aea1e7fa6ae987721a0f.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如圖是基於媒體側廣告的投放的基本流程,雙方收入累計提升20%+。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"未來思考"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/86\/86b80873ce8cf24ad41f622de75ecaa0.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"京東9N-FL起步於2019年11月,團隊比較精簡,以下幾個方面待完善:"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"平臺功能:UI界面化,減少使用成本"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"部署便捷性:實現一鍵部署,簡單快捷、方便"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"監控報警完善化:完善報警機制、完成監控機制"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"分享嘉賓:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"杜寶坤"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"京東 | 資深算法專家"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"京東商業提升事業部-廣告質量部-資深算法專家,主要負責營銷端的聯邦學習以及站外的觸發算法。擁有十多年的互聯網工作經驗,曾經供職於百度、360等多家知名互聯網公司。在互聯網搜索、推薦與廣告等方向的架構與算法方面,有多年的一線開發與項目管理經驗,並且成功主導過多個大型項目。2020年在京東零售數據算法通道委員會的指導下,作爲項目技術與業務負責人帶領團隊完成京東超大規模聯邦學習框架9N-FL的落地,並且進行技術賦能,與營銷媒體端進行合作,取得了不俗的成績;同時9N-FL也於2020年9月進行開源,回饋社區。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本文轉載自:DataFunTalk(ID:dataFunTalk)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"原文鏈接:"},{"type":"link","attrs":{"href":"https:\/\/mp.weixin.qq.com\/s\/933nA30Xg_GBbjKtDRuBnQ","title":"xxx","type":null},"content":[{"type":"text","text":"京東超大規模聯邦學習探索實踐"}]}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章