特別節目·中文精讀

克里斯·拉特納:編譯器、LLVM、Swift、TPU 與機器學習加速器

Chris Lattner: Compilers, LLVM, Swift, TPU, and ML Accelerators

LLVM 與 Swift 之父回顧編譯器設計歷程,並談 TPU 等機器學習加速器的工程取捨。

官方音訊00:00 / --:--
中文精讀由 AI 基於原始訪談改寫,非官方翻譯,可能存在偏差或錯誤;表述以原音訊與官方文稿為準。說明

2019 年,你手裡那部 iPhone 上的每一個 App,索尼用來渲染電影特效的機器叢集,Google 生產伺服器上跑的搜尋服務,PlayStation 4 裡的遊戲,這些看起來毫無關係的東西,編譯它們背後走的是同一套程式碼。

這套程式碼叫 LLVM。

它最初是伊利諾伊大學厄巴納香檳分校的一個研究生專案,只有幾個人在做。二十年後,它成了英特爾、AMD、英偉達、蘋果、Google 這些平時在市場上往死裡打的公司共同維護的公共地基。做這件事的人是克里斯·拉特納(Chris Lattner)。他還順手寫了 Clang,那個今天幾乎所有人都在間接使用的 C/C++/Objective-C 編譯器,然後在蘋果內部發起了 Swift。

這期 Lex Fridman 的訪談長達一小時十三分鐘,資訊密度極高。拉特納幾乎沒講什麼勵志故事,他講的都是具體的:一個 for 迴圈怎麼從語法樹變成控制流圖,暫存器分配為什麼是編譯器最硬的骨頭之一,bfloat16 為什麼把位元挪個位置就能讓 TPU 快起來,以及他在特斯拉那五個月到底看到了什麼。

一個只想讀一年碩士的人,寫出了二十年的基礎設施

拉特納的第一段程式是照著父母買的一本 Basic 教材敲進去的。他的回憶裡沒有什麼頓悟時刻,只有一件事:敲進去,跑起來,敲錯一個字元,然後盯著螢幕找原因。

“我開始的時候就是把書上的程式打出來,看看它們怎麼工作,然後打錯,再搞明白為什麼跑不起來。”(克里斯·拉特納)

這條路走得挺有意思。Basic 之後是 GW-Basic、QBasic、QuickBasic,都是微軟系的,一層層往上疊。然後是 Pascal,然後是彙編,然後才是 C++。中間他還摸過 Smalltalk。Fridman 在節目裡開玩笑說他走了黑魔法那條路,本來可以走 Lisp 那條更高層、更哲學、更嬉皮士的路線,結果一頭扎進了機器。

這個選擇很關鍵。Pascal 給了拉特納兩樣東西:字串型別、更強的抽象,以及第一次意識到“資源是要管理的”。真正改變他的卻是 C。用 Pascal 的時候你寫字串,不用想它在記憶體里長什麼樣。用 C 的時候你必須想:這些東西是怎麼被擺到記憶體裡的。

他後來做的所有事情,都發生在這一層。

編譯器在兩頭之間搭橋,兩頭都很麻煩

要理解拉特納做了什麼,得先理解編譯器是什麼。

他的定義很樸素:這是一道雙邊問題。一邊是寫程式碼的人,人不想寫二進位制,也不想為每一塊硬體重新想一遍;另一邊是跑程式的機器,機器的種類越來越多,x86、ARM、GPU,現在還有一堆專門為機器學習設計的加速器。編譯器做的事,就是讓人在想問題的抽象層級上思考,然後把他們寫下的東西變成某塊具體硬體能跑的東西。

“編譯器的藝術,是讓人類用他們想用的抽象層級去思考,然後讓他們寫的東西在某一塊具體的硬體上跑起來。”(克里斯·拉特納)

工程上的解法是把這個問題切成三段。前端負責解析某一種語言,C 的前端、C++ 的前端、JavaScript 的前端各不一樣。中間是最佳化器。最後是後端,負責針對具體硬體生成機器碼。

這樣切是為了複用。編譯器是極其龐大的軟體,如果每種語言、每種硬體都要從頭寫一遍,成本誰都扛不住。所以大家把中間和後端標準化,讓所有語言共用同一套最佳化和程式碼生成。LLVM 乾的就是這件事。

今天跑在 LLVM 上的語言有一長串:Swift、Rust、Julia,還有 Clang 處理的 C、C++、Objective-C。它們語法差別巨大,語義模型完全不同,JavaScript 裡“什麼算假值”這件事和 C 里根本不是一回事,但這些差異全部留在前端。到了中間,它們變成同一種東西。

從語法樹到控制流圖:一個 for 迴圈的變形記

這是整期訪談裡技術密度最高的一段,值得慢慢看。

前端解析完之後,程式碼變成一棵抽象語法樹(AST)。你寫了 a 加 b,樹上就有一個加號節點,下面掛著兩個子節點。你寫了一次函式呼叫,樹上就是一個 call 節點,掛著函式和引數。

然後開始“下降”(lowering)。語法樹被轉成中間表示,LLVM 用的那種叫控制流圖(control flow graph)。

這裡的差別用 for 迴圈最能說明。在語法樹裡,一個 for 節點下面掛著四個指標:初始化的表示式、條件的表示式、遞增的表示式、迴圈體。層層巢狀,像俄羅斯套娃。

到了控制流圖裡,它變成幾個基本塊。一個塊放初始化程式碼,一個塊放迴圈體和遞增,塊與塊之間用跳轉連線。迴圈體執行完跳到條件判斷,條件成立跳回迴圈體開頭,不成立跳到出口。

每個塊內部是一串直線排列的簡單操作:這個加法,那個乘法,這裡呼叫一次。沒有巢狀,只有順序和跳轉。

為什麼要費這麼大勁換一種形狀?因為這種形狀更接近彙編,也更語言無關。JavaScript 那套讓人抓狂的假值規則、Python 的隱式型別轉換,全部可以留在前端處理掉。到了中間表示這一層,剩下的是純粹的、乾淨的計算和跳轉,所有語言共享同一套最佳化器。

編譯器和神經網路圖,像是同一個念頭的兩個版本

Fridman 在節目裡問了一個很聰明的問題:你描述的這些東西,聽起來和神經網路的圖結構太像了。

拉特納的回答點出了一個區別。

神經網路是層層不同的表示。輸入進來是一層表示,經過一層變換變成另一種表示,越深層的表示越抽象。每一層都在做不同的事。

編譯器是一種表示,反覆變換。

同一個中間表示在編譯器裡被反覆揉搓。找出迴圈裡不隨迭代變化的表示式提到外面去,找出重複計算,把 2 乘 x 換成左移一位,把常量提前算出來。這些變換是迭代進行的,一輪最佳化完了再來一輪,有時候一個 pass 會跑幾十次。

兩者都在做“變換表示”這件事,方向與層次完全不同。做機器學習系統的人可以從中拿到一個有用的判斷:如果一層表示只被用一次,它大概是中間產物;如果一層表示被反覆打磨幾十輪,它才是真正的地基。

暫存器分配:編譯器替你打的最硬的一仗

問編譯器最佳化裡最值錢的是什麼,拉特納直接說:暫存器分配。

場景是這樣的。現代處理器裡,記憶體慢,暫存器快,但暫存器數量極其有限。x86 在某些模式下只有十六個暫存器。而你寫程式碼的時候隨手就是幾十個臨時變數,迴圈裡還套著迴圈,這段程式碼可能要執行幾百萬次。

如果迴圈裡每個值都要往記憶體裡讀寫一次,效能就廢了。如果能把迴圈裡所有活躍的值都塞進暫存器,速度會快一個數量級。

問題是怎麼塞。同一個變數在函式的不同位置,活躍狀態不一樣。你在第三行定義了 x,在第五行用了它,之後再也不碰,那 x 在第五行之後就是“死的”,它佔的暫存器可以給別人用。編譯器要做的事情,是把整個程式看成一個有時間維度的圖,然後在這個圖裡給每一個活著的值分配物理資源。

“你寫的是 x,編譯器看到的是四個不同的值,每一個都有它在整個函式里的生命週期,每一個都可能被放進暫存器、放進記憶體、或者在某些位置乾脆重新算一遍,而不是從記憶體裡讀出來。”(克里斯·拉特納)

這一步難在組合爆炸。可能的分配方案有無數種,而且這個決定會連鎖影響後面所有的最佳化。暫存器分配做砸了,前面所有的最佳化都白搭。

另一場硬仗是指令排程。RISC 架構把流水線塞進了處理器,處理器能同時處理多條指令,前提是指令之間的順序不能讓流水線卡住。編譯器的活是把指令重新排序,讓流水線一直有活幹。這一步的約束條件極其複雜,牽扯到各個指令的延遲、依賴關係、硬體埠數量。

這些技術都被研究了幾十年,教材裡都有。把一個演算法變成能在幾百人協作的程式碼庫裡穩定工作的實現,是另一回事。拉特納反覆強調,編譯器的難點落在軟體工程上。

讓死對頭坐到一張桌子上

LLVM 最了不起的地方,跟技術創新關係不大。

拉特納自己說得很清楚:LLVM 裡實現的各種演算法,大部分在學術界早就有了,教科書上都寫著。他的貢獻是標準化,是把中間表示和後端做成一個大家都能用的公共層,然後把這件事做對了。

對到什麼程度?Google 和蘋果在同一個程式碼庫上提交程式碼,AMD 和英特爾在同一個程式碼庫上提交程式碼,英偉達和 AMD 在圖形這部分提交程式碼。這些公司平時在法律訴訟和市場份額上打得不可開交。

它們為什麼願意合作?因為自己實現一遍太貴了,而且更缺的是人。編譯器工程師是極難招的一類人,就算是大公司,也沒辦法為一個內部專案湊出一支頂級團隊。共享基礎設施是唯一理性選擇。

更有意思的是這個基礎設施被用到了它從沒被設計過的地方。索尼把 LLVM 用在了電影製作的圖形編譯流程裡,用拉特納的話說,這讓他們能做更好的特效。這說明分層做對了,介面抽象做得乾淨,才會有人拿它去做原設計者完全沒想到的事。

反過來看 GCC。GCC 在它擅長的領域裡非常強,但它是一個 C 編譯器,一個基礎設施。它的程式碼裡塞滿了全域性變數,為特定用途設計,很難被複用到別的地方去。差別出在架構決策上,而這種差別要十年、二十年才顯現出來。

社群治理也是同一套邏輯。今天 LLVM 有幾百個貢獻者,靠的是一套“程式碼所有者”制度。硬體廠商擁有自己硬體相關的那些程式碼,負責確保補丁被及時 review,負責這個方向上的架構決策。拉特納名義上還在這個金字塔的頂端,他早就不 review 每一個補丁了,他做的事是調解技術分歧,保證整個社群在往前走。七年前還成立了 LLVM 基金會,管錢、管活動,不碰技術方向。

有意思的是,拉特納在研究生階段寫的第一版暫存器分配器,後來被一個“比他聰明得多的人”整個換掉了。他把這件事當成 LLVM 設計成功的證據:模組化的好處就是別人能替換你的程式碼。

Clang 的起點,只是想把報錯資訊寫清楚

2005 年拉特納加入蘋果。LLVM 在蘋果內部落地,趕上了好幾次大的架構遷移:轉向英特爾、轉向 64 位、iPhone 轉向 ARM。因為是模組化的,每次遷移的成本都低得驚人。

開發者體驗卻很糟糕。當時的 Objective-C 程式設計師面對的報錯資訊、編譯速度、工具鏈,都不怎麼樣。

然後他做了一件很拉特納的事:誰也沒告訴,下班之後自己寫一個 C 編譯器試試。

“我不會跟任何人承諾,也不告訴任何人。我就是晚上和週末開始寫。”(克里斯·拉特納)

寫著寫著他撞上了前處理器。這個東西人人都不喜歡,它極其複雜,裡面塞著一堆古怪的歷史包袱,比如三字元組(trigraph)這種鬼東西。而且它正是編譯效能問題的一個關鍵癥結。寫到這裡他發現,難和不可能之間有一道鴻溝,很多人一輩子沒跨過去。

他跟經理說了。經理的反應是:太好了,這個問題我們確實要解決,我再給你一個人。

Clang 的目標定得很務實:更好的報錯資訊,更快的編譯速度,還有 GCC 從來不支援的新的工具能力,比如重構工具和靜態分析。要做到這些,編譯器必須在內部維護大量額外的資訊,還要保證這些資訊不拖慢編譯。這是個很精細的平衡。

C++ 是這裡面最難啃的部分。規範文件厚得像磚頭,語義規則之間的相互作用極其複雜。拉特納的說法是:它幾乎不可能實現,差一點就真的不可能。

跨過去的辦法只有一個:一塊一塊地建,增量地做。還得招到真正懂各個子系統細節的工程師,一個人不可能同時精通模板推導、異常表、ABI 相容性這些完全不同的深水區。

Swift 真正的阻力來自會議室

C++ 支援剛做完第一版,拉特納腦子裡冒出來一個念頭:這語言有太多醜陋的地方,實現它的過程中你不可能不想到“一定存在更好的東西”。

於是他又一次開始了夜間專案。沒有承諾,沒有彙報,就是玩玩看。做完一些原型之後,他覺得這條路走得通,才去找當時的軟體高階副總裁伯特蘭·塞萊特(Bertrand Serlet)聊。塞萊特本身對語言有興趣,給了不少早期指導,也鼓勵他把這事推下去。之後才是告訴經理、告訴更多人。

技術上最難的部分已經過去了,剩下的是社會層面的阻力。

當時蘋果內部的共識是:iPhone 之所以成功,是因為 Objective-C。這話背後有真實的文化支撐。當年蘋果招軟體工程師,招的就是喜歡 Objective-C 的人;很多高層和骨幹工程師的文化記憶一路追溯到 NeXT 時代,那是 Objective-C 真正成型的年代。他們是“寫 Objective-C 長大的”。

在這種氛圍裡提“我們做個新語言”,接近於異端。

拉特納的觀察角度不太一樣。他覺得蘋果內部喜歡 Objective-C 的人確實很多,最敢說話的那批人也確實是真愛,還有一大批人每天都在被這門語言的尖角割傷。它難學,它有各種奇怪的邊界情況,它對新人不友好。

真正讓這件事從“異端”變成“必須做”的,是一個詞:記憶體安全。

Objective-C 的物件系統整個建立在 C 的指標之上,它本身就是 C 的一層擴充套件。指標不安全,這件事沒得商量。只要你保留指標,你就沒法在語言層面解決記憶體安全問題。你不能靠給 Objective-C 打補丁解決,因為指標就是它的地基。

這句話把討論從“要不要”變成了“怎麼做”。一旦承認 Objective-C 修不好,剩下的問題就是:新語言該長什麼樣?這完全是另一個階段的工作了。

漸進式披露:為什麼第一行程式碼必須能跑起來

Swift 的設計裡,拉特納最看重的一條原則來自 UI 設計:複雜度的漸進式披露。

它的意思是,一門語言應該允許人從最簡單的入口進來。Swift 的第一課是列印一行 hello world。一行,沒有 main 函式,沒有標頭檔案,沒有 Java 那句 public static void main。Python 也是這樣,這正是 Python 能成為程式設計第一課的原因。

然後往下走。加變數,寫一句 var x = 4,什麼叫變數,x 加 1 是什麼意思。加控制流,if 怎麼回事,for 怎麼回事,while 怎麼回事。加函式。加類。加泛型。加模組。每一層都比上一層複雜,每一層都能獨立地跑起來。

“這在編譯型語言裡非常不典型。”(克里斯·拉特納)

為什麼編譯型語言做不到這一點?因為它們必須在編譯期知道所有型別、所有邊界。這些資訊對效能、對重構工具、對一切都有好處,代價是初學者一進門就要面對一堆宣告和樣板程式碼。Swift 想做的是保留靜態型別的全部好處,同時把入口的門檻降到和 Python 一樣低。

這件事的另一面是給不同的人留不同的層級。寫庫的人想要能鑽到底層去摳細節,用庫的人只想在高層拼裝。一門語言如果只能服務其中一種人,它就廢掉了一半的生態。

還有一個容易被忽略的點:Swift 不只做靜態編譯。它在 Colab 和 Jupyter 裡被當作指令碼語言用。你敲一行程式碼,背後發生的事情是這樣的:先起一個 Unix 程序,然後每一行輸入都過一遍 Swift 編譯器前端、最佳化器、程式碼生成,最後把機器碼注入到那個正在跑的程序裡,邊跑邊替換。你在頁面上敲程式碼的時候,它在原地打補丁。

“它能做到這件事,是因為設計時就考慮到了。”(克里斯·拉特納)

拉特納對編譯這件事的看法也因此變得很不一樣:靜態編譯、動態編譯、解釋執行,這些選項處在一條光譜上,彼此之間沒有牆。把棧分好層,你就能在光譜上自由移動,不會把自己鎖死在某一頭。

一千二百行 Swift 程式碼,把 Python 拖了進來

Swift for TensorFlow 裡有一個看起來像魔術的功能:在 Swift 裡 import numpy,然後直接用。

拉特納解釋了實現原理,簡單得出人意料。

一個動態型別語言可以有兩種理解方式。大多數人會說 Python 沒有型別。另一種理解是:Python 只有一種型別,就是那個 python object,所有東西都是它,正因為只有一種,型別才是隱式的。

Swift 有很多型別,陣列、字串、各種類。現在給它加上第二種:python object。

於是 import numpy 拿回來的是一個 python object,也就是那個模組。你呼叫 np 點 exp,Swift 做的事情是:告訴 Python 直譯器“我要取這個物件上叫 exp 的成員”,拿回來又是一個 python object;再告訴直譯器“把這個物件用這些引數調一下”,拿回來還是 python object。每一次都只是動態查表加一次跨界呼叫。

這一層膠水,純 Swift 寫的,只有一千二百行左右。它建在 Swift 跟 C 的互操作能力之上,因為跟 Python 直譯器打交道本質上就是 C 層面的呼叫。

要讓這一千二百行能寫出來,Swift 語言本身必須先加兩個特性:動態成員查詢和動態呼叫。這兩個特性的提案、實現、標準化、進入語言,花了一年。

使用者看到的是一行 import。支撐這一行的是語言層面的新能力。這正是 Swift 這類有社群提案流程的語言能做到、純庫方案做不到的事。Python 那邊為了機器學習加過什麼語言特性?拉特納想了一下,說大概只有 @ 這個矩陣乘法運算子。

TensorFlow 本質上是一個編譯器,這句話值得展開

拉特納提了一個視角,理解 TF 生態的混亂局面很有幫助。

TensorFlow 乾的事情是:拿模型進來,讓它在硬體上跑得飛快。這就是編譯器乾的事。它有前端,有最佳化器,有多個後端。

按這個框架看,Swift for TensorFlow 只是又一個前端。它和 Python、Go、Rust、Julia 的繫結共享同一套圖表示、同一套執行時、同一套後端。

前端之間並不平等,它們分成三類。

第一類是 Python。它特殊,因為社群絕大部分的工程投入都在這邊,它有自己的自動微分方案,有自己的 API 層。它的天花板也被這個位置限死了:你只能在 Python 這個庫的邊界之內做最佳化,改不了語言本身。

第二類是其他語言的繫結。它們就是包裝層,呼叫 TF 的執行時 C API,沒有自動微分,沒有太多別的東西。

第三類是 Swift,只有它一個。它的思路是:既然我們可以改整條棧上的任何一個環節,那就從頭問一遍,人和編譯器之間的分工應該怎麼切?

切法的核心在兩處。第一處是型別系統。有了型別資訊,編譯器可以自動幫你構圖,你不用手動想這些。匯聚、融合、最佳化,全都是白送的。第二處是自動微分,拉特納認為這是 Swift for TensorFlow 最關鍵的貢獻之一。

自動微分這件事的歷史比大多數人想的要長。七十年代做數值計算的人寫 Fortran,那時候就有一類工具叫源到源翻譯器:你把自己的程式碼喂進去,它吐出來一份新的 Fortran 程式碼,裡面帶著你所有函式的導數。那是一整套技術積累,包括大量的最佳化技巧,包括怎麼處理數值不穩定的各種花招。

問題在於,這些技術很難搬到今天的執行模型裡。現代框架一次只能看到一個運算元,看到一個加法、一個矩陣乘,而七十年代那批工具需要看到整個函式才能推理。當語言本身整合了自動微分,你就能重新開啟這四十年的積累,把它們搬過來用。只是語言整合這件事本身也有一堆設計空間和複雜度要處理。

bfloat16:把位元挪個位置,效能就上去了

TPU 是軟硬體協同設計最典型的樣本,拉特納在訪談裡講得挺細。

當時已經是第三代 TPU,整塊液冷機箱的算力超過一百 petaflops。他的原話是“我們還沒把想法用完”。

關鍵是那個數字格式:bfloat16。

它是 16 位浮點,但不是 IEEE 那種 16 位。標準半精度浮點把更多的位給了尾數,犧牲了指數範圍。bfloat16 反過來,尾數更短,指數更長,和 32 位浮點一樣長。

代價是精度更低。收益是能表示的範圍和 float32 一樣大。

為什麼這個交換在機器學習裡划算?因為訓練過程中你會遇到極小的梯度,那些數字小到標準半精度直接下溢變成零,而它們恰恰是推動模型學習的東西。同時你也會遇到數量級很大的值。兩頭都要覆蓋,中間精度松一點沒關係。

更妙的是硬體成本。乘法器的面積和延遲跟尾數位數的平方成正比,跟指數位數是線性關係。把位從尾數挪到指數,硬體便宜了,模型效果沒掉。

甚至還有理論說,精度降低反而能提升泛化能力。這個說法未必站得住,結果擺在那裡:便宜、夠用、有效。

這個格式的來歷也挺有意思。它最初來自研究側,那批人在想辦法壓縮網路傳輸中權重的體積,找各種壓縮方案,後來這個方案被直接燒進了矽片。從一個傳輸最佳化的小技巧,變成了 TPU 效能的核心組成部分。

這就是拉特納說的那個“只有 Google 能做的三合一”:底層編譯器和晶片設計、上層軟體框架、以及演算法本身,三層可以同時改動。演算法在變,硬體從設計到量產要幾年,你必須押注幾年後什麼演算法會流行,然後把電晶體花在最值的地方。

MLIR:LLVM 二十歲了,世界變了

訪談前三週,Google 在一個編譯器會議上公佈了一個新專案,MLIR(Multi-Level Intermediate Representation)。

背景是這樣:TF 這條棧裡嵌著一堆來自不同廠商的編譯器。Google 有 XLA,英偉達有 TensorRT,英特爾有 nGraph。它們各自解決一部分問題,都在重複造輪子,都在想辦法接進 TF。

MLIR 想做的是給這些子系統提供一層公共基礎設施。第一步是讓它們能插到一起,共享程式碼。更長遠的目標是讓整個行業開始協作,不要一遍一遍重新發明同樣的東西。這套邏輯在傳統編譯器領域已經被驗證過一次。

有人開玩笑說,MLIR 就是從 LLVM 學到的一切教訓的 LLVM 版本,是一次修正錯誤的機會。拉特納自己也承認這一點:LLVM 在它被設計出來要解決的問題上非常強,二十年過去,人們開始解決更高層的問題,需要新的技術。

這句話背後有一個很樸素的道理:一個好的抽象層會活得比它的設計者預期的更久,然後開始顯出老態。這不是失敗,成功的代價本來就是如此。

開源這件事,Google 和蘋果的差別在哪

Fridman 問了一個直接的問題:蘋果和 Google 在開源上的文化差異。

拉特納的回答沒有繞彎:他更認可 Google 的做法。他給了蘋果一個公道的解釋:蘋果的文化有它的歷史成因,那是三十五年前形成的路徑,蘋果也在適應。

他的論證是這樣的:一家公司關心賺錢,這完全理性。真正讓你賺錢的東西是什麼?是那個做得極好的產品、那個差異化的體驗,不是你的字串庫。把字串庫捂住不放,今天早就不是關鍵的那一層了。十五年前可能還是,今天的平臺競爭不在那兒。

Google 開源 TensorFlow 這件事,拉特納看來是一次“深刻的、極其聰明的洞察”。他特意設想了一個反事實的世界:一家公司說機器學習是我們的核心競爭力,我們不給別人。那個世界完全可能發生。TensorFlow 開源改變了整個機器學習領域,引發了一場獨立的革命,同時在很多層面回饋了 Google 自己。

特斯拉那五個月:他respect願景,不respect所有方法

2017 年前後,拉特納在特斯拉待了大約五個月,職位是自動駕駛軟體副總裁。他趕上的時間點是特斯拉從 Hardware 1 切到 Hardware 2,從第三方提供的視覺棧換成自研視覺棧。

他對這段經歷的評價很坦率,也很體面。

Hardware 1 最初的設計目標其實很簡單:交通感知巡航、車道保持這類功能。能在這個硬體上做到後來那種程度的輔助駕駛,他認為相當驚人。當時最大的挑戰,是從第三方視覺棧往自研棧上遷。這一步時間壓力很大,好在他可以沿用原來那支團隊的知識和經驗。

然後他說了一句很重的話:

我在特斯拉的時候,經歷了也目睹了我此前在任何公司見過的最高的離職率,這有點讓我吃驚。(克里斯·拉特納)

緊接著,他說他從這段經歷裡學到並開始尊重的一件事:馬斯克能吸引到極其優秀的人,因為他有非常清晰的未來圖景,並且能讓人相信那個圖景。街角隨便一個人都能喊“我們要去火星”,真正能讓別人買賬、並且真的把路徑搭出來的人,極少。他對這種願景的力量評價很高。

最後那句補充很關鍵:“我不認同他的所有方法,但我對這一點有極大的尊重。”(克里斯·拉特納)

什麼叫工作努力

Fridman 問了一個很少被認真回答的問題:工作努力到底指什麼?

拉特納先給了最常見的答案:很多小時。這是事實,他不否認。

他說真正難的是另一件事:同時保持短期交付的專注和長期的判斷。

如果你眼裡只有眼前這個任務,把它幹完,然後只想著下一步,你會錯過那個本該跳過去的下一個大坎。反過來,如果你天天只想著三年後的架構,你交付不出任何東西。在這兩端之間來回擺,是最消耗人的。

他承認自己在蘋果能做到這一點,靠的是搭起了團隊和領導結構,讓那些人能成長、能承擔責任,從而把自己解放出來去“稍微瘋一點”,去想下一件事。

還有一部分是經驗帶來的連線能力。做過足夠多的事情之後,你能看到別人看不到的關聯,那些關聯本身能省掉大量的試錯。他把這算作時間給的一筆複利:同樣一個問題,二十年前他得從頭推導,今天他能在幾秒鐘內認出這是哪一類坑。

底層還是大量的小時。他說自己對工作生活平衡有一套自己的理論,這理論是他對自己用的,不往團隊身上套。他的目標說得很直白:改變世界,讓它變好一點,這就是他的動力來源。

這段話裡有個容易被忽略的分寸感。他談的是自己願意怎麼活,沒有把它包裝成普適標準,更沒有暗示別人不夠努力。這種區分在技術圈其實挺稀缺。

那個龍

LLVM 的標誌是一條龍。官方說法是龍代表力量、速度、智慧,也能代表流暢、優雅、模組化。真實原因簡單得多:編譯器領域有一本很老很經典的教材,叫《龍書》(Compilers: Principles, Techniques, and Tools)。

當年在蘋果,大家做演示要放幻燈片,總得有個 LLVM 的圖示,但沒有。有人問,編譯器技術該配個什麼標誌?拉特納說,我不知道,龍大概是我們手上能拿到最好的東西了。蘋果的設計團隊把圖示做了出來,社群接受了它,後來越來越多的設計師參與改進,就成了今天的樣子。

有個細節挺有意思。拉特納的妻子也是編譯器工程師,她負責運營 LLVM 基金會,會去 Grace Hopper 大會發貼紙,想辦法讓更多女性對編譯器產生興趣。結果因為《權力的遊戲》,大家都喜歡那個龍的貼紙,搶著要。文化偶爾會用這種方式幫上忙,讓下一代工程師對編譯器多看兩眼。

一條原本只是為了填滿幻燈片角落的龍,最後變成了一個跨公司、跨國籍、二十年的合作符號。這件事本身挺說明問題:基礎設施的生命力來自被借用,不來自被保護。

把這一小時的資訊用起來

這期訪談最有價值的地方不在結論,在那種看問題的方式。拉特納反覆在做同一件事:把複雜系統拆成層,讓每一層都能被獨立替換,然後耐心等十年看結果。這套方法可以遷移到很多地方。

  • 設計任何長期系統時,先問“這一層會被誰替換”。拉特納第一版暫存器分配器被別人整個換掉了,他當成好事。如果你的架構不允許這種替換髮生,它就只能活到你的想法過時那天。
  • 別用“這不可能”結束討論,改成“這有多難”。Clang 和 Swift 都起於“我只是晚上寫寫看”。區別在於他撞牆之後去判斷的是難度等級,可行性壓根不是他問的問題。
  • 遇到僵局時,去找那個修不好的地基。Swift 能立項靠的是一個不可辯駁的限制條件:指標就是記憶體安全問題的根,打補丁永遠修不好。把爭論從“要不要”轉成“怎麼做”,只需要這一句話。
  • 把漸進式披露用到文件、API、產品上。第一行程式碼必須能跑起來,然後才是第二層複雜度。任何要求使用者一進門就理解全貌的設計,都會把大批人擋在門外。
  • 做軟硬體或跨層專案時,接受“押注”這件事。硬體從設計到量產要幾年,演算法幾個月就換一輪。bfloat16 之所以能成,是因為有人敢在不確定的情況下押注“指數比尾數更重要”,並且這個判斷在模型層面站得住。
  • 評估一個開源專案,先看它有沒有被用在設計之外的地方。索尼拿 LLVM 做電影特效的圖形編譯,這個訊號比任何效能基準都更能說明它的分層是對的。
  • 判斷一個基礎設施值不值得做,看重複成本。英特爾、AMD、英偉達、Google、蘋果願意在一個程式碼庫上合作,動力來自兩個硬約束:自己實現一遍太貴,招不到足夠的人。找到別人繞不過去的高成本,就是協作的入口。
  • 關於工作強度:不要只最佳化小時數。真正稀缺的能力是在短期交付和長期判斷之間來回切換。把執行層交給能成長的人,是唯一能讓自己騰出手去想下一件事的辦法。

最後留一句拉特納沒有明說、但整期訪談都在示範的事:他從研究生到 2019 年,做的所有專案都有一個共同點,起點小得幾乎不體面。一個夜間專案,一本教材上的程式,一個只想讀一年碩士就回去工作的人。值得做的事,往往一開始看起來不值得向任何人彙報。

文稿由本站用語音識別模型(基於官方釋出音訊)機器轉寫,可能有識別錯誤,人名與數字請以音訊為準。
[00:00:00] The following is a conversation with Chris Flattener, currently he's a senior director at Google working on several projects, including CPU, GPU, GPU accelerators for for swift returns to flow and all kinds of machine learning compiler magic going on behind the scenes. He's one of the top experts in the world on compiler technologies, which means he deeply understands the intricacies of how hardware and software come together to create efficient code. He created that allow VM Compiler Infrastructure Project and the clang compiler. [00:00:33] He led major engineering efforts at Apple, including the creation of the swift programming language. He also briefly spent time at Tesla as vice president of Autopilots Software during the transition from auto pilot hardware one to hardware to when Tesla essentially started from scratch to build an in-house software infrastructure for autopilot. I could have easily talked to Chris for many more hours. Compiling code down across the levels of abstraction is one of the most fundamental and fascinating aspects of what computers do. [00:01:05] And he is one of the world experts in this process, its rigorous science and its messy, beautiful art. This conversation is part of the Artificial Intelligence podcast, if you enjoy it. Subscribe on YouTube, iTunes or simply connect with me on Twitter at Lux. Friedman spelled Frid. And now here's my conversation with Chris Laettner. What was the first program you've ever written? Our first program back and when was it I think I started as a kid and my parents got a basic programming book, and so when I started it was typing out programs from a book and seeing how they worked and then typing them in wrong and trying to figure out why they were not working. [00:02:08] Right. That kind of stuff. [00:02:10] So basically, what was the first language that you remember yourself maybe falling in love with? Like really connecting with? I don't know. [00:02:17] I mean, I feel like I've learned a lot along the way and each of them have a different special thing about them. So I started in Basic and then went like GW Basic, which was the thing back in the dark days and then upgraded to Kubasik. And eventually Quick Basic, which are all slightly more fancy versions of Microsoft, basically made the jump to Pascall and started doing machine language programming and assembly and Pasko, which was really cool through Pasko. [00:02:43] It was amazing for its they're eventually going to see C++ and then kind of did lots of other weird things. [00:02:50] So I feel like it took the dark path, which is the you could, you could have gone lisp. Yeah. [00:02:57] You get a higher level sort of functional philosophical hippy root. Instead you went into like the dark arts of the straight into the machine. [00:03:07] So started with Basic Pasko and then assembly and then wrote a lot of assembly and y eventually eventually did small talk and other things like that. But that was not the starting point. [00:03:19] But so what, what is this journey to see is that in high school. Is that in college I was in high school. [00:03:25] Yeah. So and then that was, it was really about trying to be able to do more powerful things than what Pascall could do and also to learn a different world. So it was really confusing to me with pointers and the syntax and everything. And it took a while but. Pascale's much more. Principals in various ways seems more. I mean, it has its historical roots, but it's not as easy to learn with pointers. There's this memory management. [00:03:56] Thing they have to become conscious of is that the first time you start to understand that there's resources that you're supposed to manage well, so you have that in Pascal as well. [00:04:05] But in Pasko, these like the carrot and sort of the star. And there's some small differences like that, but it's not about point or arithmetic. And and C, you end up thinking about how things get laid out in memory a lot more. And so in Pascal, you have allocating and allocating and owning the memory. But just the programs are simpler and you don't have to. [00:04:27] Well, for example, Pascal has a string tape and so you can think about a string instead of an array of characters which are consecutive in memory. And so it's a little bit of a higher level abstraction. [00:04:37] So let's get into it. Let's talk about LVM ceiling and compilers. Sure. So can you tell me first what all the ceiling are and how is it that you find yourself the creator and lead developer or one of the most powerful compiler optimization systems in use today? [00:04:57] Sure. So. I guess they're different things, so. Let's start with what is the compiler it's a good place to start. What are the phases of a compiler where the parts. Yeah, what is it? So what does even a compiler used for? [00:05:10] So the way the way I look at this is you have a two sided problem of humans that need to write code and then you have machines that need to run the program that the human wrote. And for lots of reasons, the humans don't want to be writing in binary and want to think about every piece of hardware. And so at the same time that you have lots of humans, you also have lots of kinds of hardware. And so compilers are the art of allowing humans to think of the level of abstraction that they want to think about and then get that program, get the thing that they wrote to run on a specific piece of hardware. [00:05:43] And the interesting and exciting part of all this is that there's now lots of different kinds of hardware, chips like X 86 and her PC and arm and things like that. [00:05:53] But also High-Performance accelerators for machine learning and other things like that are also just different kinds of hardware, GPS. These are new kinds of hardware. [00:06:00] And at the same time, on the programming side of it, you have your basic you have C, you have JavaScript, you have Python, you Swift. You have like lots of other languages that are all trying to talk to the human in a different way to make them more expressive and capable and powerful. And so. Compilers are the thing that goes from one to the other now and then from the very beginning to the end to end, and so you go from what the human wrote and programming languages end up being about, expressing intent not just for the compiler and the hardware, but the programming languages job is really to to capture an expression of what the programmer wanted that then can be maintained and adapted and evolved by other humans, as well as by the interpreter, by the compiler. [00:06:46] So so when you look at this problem, you have on the one hand, humans, which are complicated, you have hardware which is complicated. [00:06:53] And so compilers typically work in multiple phases. [00:06:56] And so the software engineering challenge that you have here is try to get maximum reuse out of the the amount of code, the right, because these compilers are very complicated. And so the way it typically works out is that you have something called a front end or a parser that is language specific. And so you have a C parser and that's what Clangers or C++ or JavaScript or Python or whatever. That's the front end. Then you'll have a middle part, which is often the optimizer, and then you have a late part, which is hardware specific. [00:07:30] And so compilers end up there's many different layers often, but these three big groups that are very common and compilers and what LVM is trying to do is trying to standardize that middle and last part. And so one of the cool things about LVM is that there are a lot of different languages that compile through to it. And so things like Swift, but also Julia Rust. Clang for c c++ subjective c like these are all very different languages, and they can all use the same optimization infrastructure which gets better performance and the same cogeneration infrastructure for hardware support. [00:08:05] And so LVM is really that that layer that is common that all these different specific compilers can use. [00:08:12] And is it is it a standard like a specification or is it literally an implementation set implementation? [00:08:19] And so it's I think there's a couple of different ways of looking at it. [00:08:23] Right, because it depends on which angle you're looking at it from. LVM ends up being a bunch of code. OK, so it's a bunch of code that people reuse and they build compilers with. [00:08:33] We call it a compiler infrastructure because it's kind of the underlying platform that you build a concrete compiler on top of. [00:08:39] But it's also a community. And the Muslim community is hundreds of people that all collaborate. And one of the most fascinating things about LVM over the course of time is that we've managed somehow to successfully get harsh competitors in the commercial space to collaborate on shared infrastructure. And so you have Google and Apple, you have AMD and Intel, you have Invidia and AMD. On the graphics side, you have Quray and everybody else doing these things. [00:09:09] And like all these companies are collaborating together to make that shared infrastructure really, really great. [00:09:15] And they do this not out of the goodness of their heart, but they do it because it's in their commercial interests of having really great infrastructure that they can build on top of and facing the reality that it's so expensive that no one company, even the big companies, no one company really wants to implement it all themselves, expensive or difficult? [00:09:33] Both. That's a great point, because it's also about the skill sets. Right. And these are the skill sets are very hard, hard to find. [00:09:43] How big is the LVM? It always seems like with open source projects, the kind of open source. [00:09:50] Yes, it's open source. It's about it's 19 years old now. So it's fairly old. [00:09:55] It seems like the magic often happens in a very small circle of people. Yes, I'd like at least the early birth and whatever. [00:10:03] Yes. So LVM came from a university project, and so I was at the University of Illinois and there it was myself and my advisor and then a team of two or three research students in the research group. And we built many of the core pieces initially. I then graduated and went to Apple and an apple brought it to the products, first in the open geographic stack, but eventually to the C compiler rom and eventually built clang and eventually built Swiftian. [00:10:30] These things along the way, building a team of people that are really amazing compiler engineers that helped build a lot of that. And so as it was gaining momentum and as was using it being open source and public and encouraging contribution, many others, for example, at Google came in and started contributing. And in some cases, Google effectively owns Clanged now because it cares so much about C++ and the evolution of that that ecosystem. And so it's investing a lot in the C++ world and the tooling and things like that. [00:11:00] And so likewise, Invidia cares a lot about Khuda. And so Kuda uses clang and uses LVM for for graphics and GPP. [00:11:12] And so when you first started as a massive project, I guess, do you think is going to go as far as it went where you crazy ambitious about it now? Seems like a really difficult undertaking. A brave one. [00:11:26] Yeah, no, it was nothing like that. So I mean, my goal when I went to the University of Illinois was to get in and out with a non thesis masters and a year and get back to work. [00:11:35] So I was not I was not planning to stay for five years and and build this massive infrastructure. I got nerds sniped into staying and a lot of it was because all of it was fun. I was building cool stuff and learning really interesting things and facing both software engineering challenges, but also learning how to work on a team and things like that. [00:11:57] I had worked at many companies as interns before that, but it was really a different a different thing to have a team of people that were working together and trying to collaborate and version control. And it was it was just a little bit different. [00:12:09] Like I said, I just talked to Don Knuth and he believes that two percent of the world population have something weird with their brain, that they're geeks. They understand computers, the connected computer, he put it exactly two percent. [00:12:21] OK, so this specific guy is very specific. He says I can't prove it, but it's very empirically there. [00:12:30] Is there something that attracts you to the idea of optimizing code? And it seems like that's one of the biggest, coolest things about all of you. [00:12:38] Yeah, that's one of the major things that does. So I got into that because of a person, actually. So when I was in my undergraduate, I had an advisor or a professor named Steve Victo, and he I went to this little tiny private school, the. The seven or nine people in my computer science department, students in my in my class, so it's a very tiny, very small school, it was kind of a work on the side of the math department kind of thing at the time. [00:13:08] I think it's evolved a lot in the many years since then. [00:13:10] But but Steve Ragdoll was a compiler guy and he was super passionate and he has passion rubbed off on me. And one of the things I like about compilers is that they're large, complicated software pieces. [00:13:26] And so one of the culminating classes that many computer science departments, at least at the time, did, was to say that you take algorithms and data structures and all these core classes. But then the compilers class was one of the last classes you take because it pulls everything together and then you work on one piece of code over the entire semester. And and so you keep building on your own work, which is really interesting, is also very challenging because in many classes, if you don't get a project done, you just forget about it and move on to the next one and get your, you know, your B or whatever it is. [00:13:58] But here you have to live with the decisions you make and continue to reinvest in it. [00:14:02] And I really like that. And and so I did an extra study project with them the following semester and he was just really great. And he was also a great mentor and a lot of ways. And so from from him and from his advice, he encouraged me to go to graduate school. I wasn't super excited about going to grad school. [00:14:20] I wanted the master's degree, but I didn't want to be an academic. [00:14:24] And but like I said, I kind of got tricked into saying and was having a lot of fun, and I definitely do not regret it. [00:14:31] What aspects of compilers were the things you connected with? So LVM, there's also the other part. [00:14:39] This is really interesting. If you're interested in languages parsing and yeah. Just analyzing like. Yeah, analyzing language, breaking it up, parsing and so on. Was that interesting to you? Were you more interested in optimization? For me it was more so. [00:14:52] I'm not really a math person. I could do math. I understand some bits of it when I get into it. But math is never the thing that that attracted me. And so a lot of the parser, part of the compiler has a lot of good formal theories that Don, for example, knows quite well. Still waiting for his book on that. [00:15:08] But but the but I just like building a thing and and seeing what it could do and exploring and getting to do more things and then setting new goals and reaching for them and and with in the case of in the case of LVM, when I started working on that, my research advisor that I was working for was a compiler guy. And so he and I specifically found each other because we're both interested in compilers. And so I started working with them and taking this class. [00:15:36] And a lot of LVM initially was it's funny implementing all the standard algorithms and all the other things that people had been talking about and were well known. And they were in the the curricula for advanced days and compilers. And so just being able to build that was really fun. And I was learning a lot by sort of reading about just building. And so I enjoyed that. [00:15:57] So he said composing these complicated systems. Q Even just with language, try to describe, you know, how you turn a C++ program. Yes. [00:16:08] Into code like what are the hard parts, why is it so hard? [00:16:11] So I'll give you examples of the hard parts along the way. So C++ is a very complicated programming language is something like 400 pages in the spec. So C++ by itself is crazy. [00:16:23] Can you just say pause? What makes a language complicated in terms of what's syntactically like us? [00:16:30] So it's what they call syntax. So the actual how the characters are arranged. Yes, it's also semantics how it behaves. It's also in the case of C++, there's a huge amount of history. [00:16:40] C++ built on top of C, you play that forward and then a bunch of suboptimal in some cases decisions were made and they compound and then more and more and more things keep getting added to C++ and it will probably never stop. [00:16:54] But the language is very complicated from that perspective. And so the interactions between subsystems is very complicated. There's just a lot there. And when you talk about the front end, one of the major challenges which playing as a project, the C C++ compiler that I built, I and many people built all the challenges we took on was. [00:17:13] We looked at Jesse, Jesse at the time was like a really good industry standardized compiler that had really consolidated a lot of the other computers in the world and was was a standard, but it wasn't really great for research. [00:17:27] The design was very difficult to work with and it was full of global variables and other other things that made it very difficult to reuse in ways that it wasn't originally designed for. And so with closing, one of the things that we want to do is push forward on better user interface. So make error messages that are just better than Jinx's. And that's actually hard because you have to do a lot of bookkeeping in an efficient way to do that. [00:17:50] We want to make compile time better. And so compile time is about making it efficient, which is also a really hard way of keeping track of extra information. [00:17:57] We wanted to make new tools available, so refactoring tools and other analysis tools that the GCSE never supported. Also leveraging the extra information we kept, but enabling those new classes are tools that then get built into ideas. [00:18:13] And so that's been one of the one of the areas that clangers really helped push the world forward in is in the tooling for C and C++ and things like that. [00:18:22] But C++ and the front end pieces complicated. And you have to build syntax trees and you have to check every rule in the spec and you have to turn that back into an error message to the human human that the human can understand when they do something wrong. [00:18:34] But then you start doing the what's called lowering. So going from C++ in the way that it represents code down to the machine. And when you do that, there's many different phases you go through. [00:18:46] Often there are, I think, Alabama, something like 150 different what are called passes and the compiler that the code passes through and these get organized in very complicated ways which affect the generate code in the performance and compile time and many of the things. [00:19:03] What are they passing through? So after you do the the clang parsing, what's what's the graph? [00:19:11] What does it look like? What's the structure here. [00:19:13] Yeah. So in, in the parser it's usually a tree and it's called an abstract syntax tree. And so the idea is you, you have a node for the plus that the human wrote in their code or the function call. You'll have a node for call with the function that they call in the arguments they pass, things like that. This then gets lowered into what's called an intermediate representation, and intermediate representations are like LVM has one and there it's a it's what's called a control photograph. [00:19:44] And so you represent each operation in the program as a very simple like this is going to add two numbers. This is going to multiply two things. [00:19:53] Maybe we'll do a call, but then they get put in what are called blocks. And so you get blocks of these straight line operations where instead of being nested like in a tree, it's straight line operations. And so there's a sequence and we're going to these operations and then in the block or outside, that's within the block. [00:20:10] And so it's a straight line sequence of operations within the block. [00:20:12] And then you have branches like additional branches between blocks. And so when you write a loop, for example, in a syntax tree, you would have a four node like four for statement in a C language for node. And you have a pointer to the expression for the initialize are appointed to the expression, for the incremental pointer, to the expression for the comparison appointer to the body. OK, and these are all nested underneath it. In a controller graph, you get a block for the code that runs before the loop. [00:20:43] So the initialized code and you have a block for the body of the loop. And so the the body of the loop code goes in there, but also the increment, other things like that. [00:20:52] And then you have a branch that goes back to the top and a comparison and branch that goes out. And so it's more of an assembly level kind of representation. But the nice thing about this level of representation is it's much more language independent. [00:21:05] And so there's lots of different kinds of languages with different kinds of, you know, JavaScript has a lot of different ideas of what is false, for example, and all that can stay in the front end. [00:21:17] But then that middle part can be shared across all of those. [00:21:21] How close is that intermediate representation to a 10 year old network, for example? Are they? Because everything you describe is a kind of echoes of neural network graph. Yes, we are. [00:21:34] The neighbors are what they're quite different in details, but they're very similar in idea. So one of the things that all networks do is they learn representations for data at different levels of abstraction and then they transform those through layers. Right. [00:21:51] So the compiler does very similar things. But one of the things the compiler does is it has relatively few different representations where a neural network, often as you get deeper, for example, you get many different representations and each, you know, layer or set of ops is transforming between these different representations. In a compiler, often you get one representation and they do many transformations to it. And these transformations are often applied iteratively. [00:22:16] And for programmers that are familiar types of things, for example, trying to find expressions inside of a loop and pulling them out of a loop so they execute four times or find redundant computation or find a constant folding or other simplifications turning, you know, to times ex into shift left by one. And things like this are all of all the examples of the things that happen. [00:22:40] But compilers end up getting a lot of things improving and other kinds of algorithms that try to find higher level properties of the program that then can be used by the optimizer. [00:22:49] So what's the biggest bang for the buck with optimization? What's today? Yeah, well, no, not even today at the very beginning, the 80s, I don't know, but yeah. [00:23:00] So for the 80s, a lot of it was things like register allocation. [00:23:03] So the idea of in in a modern like a microprocessor, what you'll end up having is you'll end up having memory which is relatively slow, and then you have registers relatively fast, but registers, you don't have very many of them. [00:23:17] And so when you're writing a bunch of code, you're just saying like compute this put in temporary variable computers, computers, computers, put in temporary variable over a loop. I have some other stuff going on. Well, now you're running on an X eighty six like a desktop PC or something. Well, it only has in some cases, some modes it registers. Right. And so now the compiler has to choose what values get put in, what registers at one points in the program. [00:23:41] And this is actually a really big deal. So if you think about you have a loop and an inner loop, the excuse millions of times, maybe if you're doing loads in stores inside that loop, then it's going to be really slow. But if you can somehow fit all the values inside that loop in registers, now it's really fast. And so getting that right requires a lot of work because there's many different ways to do that. And often what the compiler ends up doing is it ends up thinking about things in a different representation than what the human wrote. [00:24:09] Right. You wrote into X while the compiler thinks about that is for different values, each which have different lifetimes across the function that it's in. And each of those could be put in a register or memory or different memory or maybe in some parts of the code recompute it instead of extraordinarily loaded. And there are many of these different kinds of techniques that can be used so that adding almost like a time. [00:24:31] Dimensioned is trying to trying to optimize across time, so it's considering when when you're programming, you're not thinking. [00:24:39] Yeah, absolutely. And so the risk error. Made the risk so so risk gips risc the risk risk chuffs as opposed to the risk chips, made things more complicated for the compiler because what they ended up doing is ending up adding pipelines to the processor or the processor can do more than one thing at a time. But this means that the order of operations matters a lot. [00:25:04] And so one of the classical compiler techniques that you use is called scheduling. And so moving the instructions around so that the processor can keep its pipelines full instead of stalling and getting blocked. And so there's a lot of things like that that are kind of bread and butter. A compiler techniques have been studied a lot over the course of decades now, but the engineering side of making them real is also still quite hard. And you talk about machine learning. This is this is a huge opportunity for machine learning because many of these algorithms are full of these like hokey handwrote heuristics, which work well on specific benchmarks that don't generalize and full of magic numbers. [00:25:41] And, you know, I hear there's some techniques that are good at handling that. [00:25:45] So what would be the if you were to apply machine learning to this? What's the thing you try to optimize is ultimately the running time? [00:25:55] Of course, you can pick your metric and there's there's running time, there's memory use. There's there's lots of different things that you can optimize for. A good size is another one that some people care about in the embedded space. [00:26:05] Is this like the thinking into the future or somebody's actually been crazy enough to try to have machine learning based parameter tuning for the optimization of composers? [00:26:18] So this is something that is, I would say, research right now. There are a lot of research systems that have been applying search in various forms and using reinforcement learning as one form, but also for search has been tried for quite a while. [00:26:31] And usually these are small, small problem spaces. [00:26:35] So find the optimal way to generate a matrix multiplier for a GPU, something like that, where you say there there's a lot of design space of do you unroll loops a lot? Do you execute multiple things in parallel? [00:26:49] And there's many different confounding factors here because graphics cards have different numbers of threads and registers and execution parts and memory bandwidth and many different constraints to interact and nonlinear ways. And so search is very powerful for that and. It gets used in in certain ways, but it's not very structured. This is something that we need. We as an industry need to fix these set 80s, but they. So have there been like big jumps in improvement and optimization? Yes. [00:27:19] Since then. What? [00:27:21] Yeah. So it's largely been driven by hardware. So Heartwell hardware and software. [00:27:27] So in the mid 90s, Java totally changed the world and I'm still amazed by how much change was introduced, by the way, or in a good way. So like reflecting back, Java introduced things like it all at once, introduced things like compilation. [00:27:43] None of these were novel, but it pulled it together and made it mainstream and and made people Envestnet compilation, garbage collection, portable code, safe code, like memory, safe code, like a very dynamic dispatch execution model. [00:27:58] Like many of these things which had been done in research systems and had been done in small ways and various places really came to the forefront, really changed how things worked and therefore changed the way people thought about the problem. JavaScript was another major world change based on the way it works, but also on the hardware side of things. [00:28:19] Multicore and vector instructions really change the problem space and are very they don't remove any of the problems the Campo's faced in the past, but they they add new kinds of problems of how do you find enough work to keep a four wide vector busy? Or if you're doing a matrix multiplication, how do you do different columns? Are that matrix and at the same time? And how do you maximally utilize the the arithmetic compute that one core has? And then how do you take it to multiple cores? [00:28:50] And how did the whole virtual machine thing change the computation pipeline. The yeah. So, so what the Java virtual machine does is it splits just like I was talking about before, where you have a front end that passes the code and then you have an intermediate representation that gets transformed, which I ever did, was they said we will pass the code and then compile to what's known as Java bytecode, and that bytecode is now a portable code representation that is industry standard and lock down and can't change. [00:29:19] And then the the back part of the compiler, the does optimization and co-generation can now be built by different vendors and Java bytecode can be shipped around across the wire. [00:29:30] It's memory safe and relatively trusted. [00:29:33] And because of that it can run in the browser and that's why it runs in the browser. Right. And so that way you can be in, you know, again back in the day you write Java applet and you'd use a as a as a web developer, you'd build this mini app to run a webpage. Well, a user of that is running a Web browser on their computer. You download that that Java bytecode, which can be trusted, and then you do all the compiler stuff on your machine. [00:29:58] So you know that you trust that that was a good idea. [00:30:00] A bad idea. It's a great idea. I mean, it's a great idea for certain problems. And I'm very much a believer that technology is itself neither good nor bad. [00:30:07] It's how you apply it. [00:30:10] You know, this would be a very, very bad thing for very low levels of the software stack. [00:30:14] But but in terms of solving some of these software portability and transparency or portability problems, I think it's been really good. [00:30:21] Now, Java ultimately didn't win out on the desktop and like there are good reasons for that, but it's been very successful on servers. And in many places it's been a very successful thing over over decades. [00:30:33] So what has been low VMS and ceilings, improvements in optimization, that is throughout its history. [00:30:45] What are some moments we had set back and really proud of what's been accomplished? [00:30:50] Yeah, I think that the interesting thing about LVM is not the innovations and compiler research. It has very good implementations of various important algorithms, no doubt. [00:31:01] And and a lot of really smart people have worked on it. But I think that the thing that's most profound about LVM is that through standardization, it made things possible that otherwise wouldn't have happened. OK, and so interesting things that have happened with LVM, for example, Sony has picked up LVM and used it to do all the graphics compilation and their movie production pipeline. And so now they're able to have better special effects because of LVM. [00:31:26] That's kind of cool, that's not what it was designed for, right, but that's that's the sign of good infrastructure when it can be used in ways it was never designed for because it has good layering and software engineering and composable and things like that, which is where, as you said, it differs from JC. [00:31:43] Yes, Jesus is also great in various ways, but it's not as good as infrastructure technology. It's it's you know, it's really a C compiler or it's or it's a forgery compiler. It's not it's not infrastructure in the same way now, is it? [00:31:57] Now you can tell I don't know what I'm talking about because I keep saying cieling. [00:32:01] You can always tell when a person is close by the way you pronounce something. I don't think. [00:32:07] Have I ever used Klencke entirely possible. Have you? Well, so you've used code. It's generated probably. So Clang is in Alabama, used to compile all the apps on the iPhone effectively and the OS as it compiles Google's production server applications. It's used to build like Game Cube games and PlayStation four and things like that, as a user I have, but just everything I've done that I experienced to Linux has been, I believe, always geeky. [00:32:40] You know, I think Linux stole the hostages. This and is the reason for that. [00:32:45] There's a big I mean, it's a combination of technical and social reasons. Many, many Linux developers, D. D clone. But the distribution's for lots of reasons. Eustachy historically. [00:32:59] And they've not switched. No, because I just anecdotally online, it seems that LVM has either reached a level GGC or superceding different features or whatever. [00:33:10] And the way I would say it is that they're so close it doesn't matter. Yeah, exactly. Like they're slightly better in some ways slightly worse than other, but it doesn't actually really matter anymore that level. [00:33:20] So in terms of optimization, breakthrough's, it's just been solid, incremental work. Yeah. Yeah. [00:33:27] Which is which describes a lot of compilers. The hard thing about compilers in my experience, is the engineering, the software engineering, making it so that you can have hundreds of people collaborating on really detailed low level work and scaling that. [00:33:42] And that's that's really hard. And that's one of the things I think LVM has done well. And that kind of goes back to the original design goals with it to be modular and things like that, and incidentally, I don't want to take all the credit for this. Right. I mean, some of the the best parts about LVM is that it was designed to be modular. And when I started, I would write, for example, or register Elkader and then something much smarter than me would come in and pull it out and replace it with something else that they would come up with. [00:34:09] And because it's modular, they were able to do that. And that's one of the challenges with what you see, for example, is replacing subsystems is incredibly difficult. It can be done, but it wasn't designed for that. And that's one of the reasons that Alvin's been very successful in the research world as well. [00:34:25] But in the in a community sense, would of an Rassam right from Python, just retired from. [00:34:35] What does a benevolent dictator for life, right, so in managing this community of brilliant, compassionate folks is there I did it for a time at least following you to to approve things. [00:34:48] Oh, yeah. [00:34:49] So, I mean, I still have something like an order of magnitude more patches in LVM than anybody else. And many of those I wrote myself. [00:34:59] But you still write I mean, you still you still close to the to the I don't know what the expression is to the metal. You still write code. [00:35:08] Yeah. Sorry, I could not as much as I was able to in grad school, but that's an important part of my identity. But the way the LVM has worked over time is that when I was a grad student, I could do all the work and steer everything and review every patch and make sure everything was done exactly the way my opinionated sense felt like it should be done. And that was fine. [00:35:28] But as a scale, you can't do that. Right. And so what ends up happening is LVM has a hierarchical system of what's called owners. These code owners are given the responsibility not to do all the work, not necessarily to review all the patches, but to make sure that the patches do get reviewed and make sure that the right things happening architecturally in their area. [00:35:49] And so what you'll see is you'll see that, for example, hardware manufacturers end up owning the the the hardware specific parts of their their their hardware. That's very common. [00:36:02] Leaders in the community that have done really good work and actually become the de facto owner of something. And then usually something else is like, how about we make them the official code of honor? [00:36:12] And then and then we'll have somebody to make sure that the patches get reviewed in a timely manner. And then I was like, yes, that's obvious. And then it happens. Right. And usually this is a very organic thing, which is great. And so I'm nominally the top of that stack still. [00:36:25] But I don't spend a lot of time reviewing patches. [00:36:28] What I do is I help negotiate a lot of the the technical disagreements that end up happening and making sure that the community as a whole makes progress and is moving in the right direction and and doing that. So we also started a non-profit six years ago, seven years ago. [00:36:46] It's times gone away. And the nonprofit, the LVM Foundation nonprofit, helps oversee all the business sides of things and make sure that the events that the community has are funded and set up and run crackly and stuff like that. But the foundation is very much stays out of the technical side of where where the project is going. Right. [00:37:06] That sounds like a lot of it is just organic and just. [00:37:10] Yeah, well, and this is LVM is almost 20 years old, which is hard to believe. Somebody pointed out to me recently that LVM is now older than Jinksy was when LVM started. [00:37:21] All right, so time has a way of getting away from you, but the good thing about that is it has a really robust, really amazing community of people that are in their professional lives right across lots of different companies. But it's a it's a community of people that are interested in similar kinds of problems and have been working together effectively for years and have a lot of trust and respect for each other. And even if they don't always agree that, you know, we're able to find a path forward. [00:37:48] So then in a slightly different flavor of effort, you started Apple in 2005 with the task of making, I guess, LVM production ready and then eventually 2013 through 2017, leading the entire developer tools department. We're talking about LVM, Xcode, Objective C to Swift. [00:38:11] So in a quick overview of your time there, what were the challenges, first of all, leading such a huge group of developers, what was the big motivator dream mission behind creating Swift, the early birth of its from projects and so on, and Xcode? [00:38:31] So these are different questions. [00:38:33] I know, but I want to talk about the other stuff. I'll stay I'll stay on the technical side, then we can talk about the big team pieces. OK, sure. So it's to really oversimplify many years of hard work. [00:38:46] Alvin started, joined Apple, became a thing, became successful and became deployed. But then there's a question about how how do we actually past the source code? So LVM is the back part, the optimizer and the code generator. And LVM is really good for Apple. As it went through a couple of hundred transitions. I joined right at the time of the Intel transition, for example, and 64 bit transitions and then the transition to arm with the iPhone. [00:39:10] And so LVM was very useful for some of these kinds of things. But at the same time, there's a lot of questions around developer experience. [00:39:17] And so if you're a programmer pounding out at the time, Objective C-code, the error message, you get, the compile time, the turnaround cycle, the the tooling and the idea were not great or not as good as they could be. [00:39:30] And so, you know, as I occasionally do, I'm like, well, OK, how hard is it to write a C compiler? [00:39:37] Right. And so I'm not going to commit to anybody. And I could tell anybody. I'm just going to just do it on nights and weekends and start working on it. [00:39:44] And then, you know, I built up and see, there's this thing called the preprocessor, which people don't like, but it's actually really hard and complicated and includes a bunch of really weird things like try graphs and other stuff like that that are that are really nasty. [00:39:58] And it's the crux of a bunch of the performance issues in the compiler sort of working on the parser and kind of got to the point where I'm like, oh, you know what we can actually do? [00:40:06] This is everything that this is impossible to do, but it's actually just hard. It's not impossible. And I eventually told my manager about it and he's like, oh, wow, this is great. [00:40:16] We do need to solve this problem. Oh, this is great. We can get you one other person to work with you on this, you know, and so the team is formed and it starts taking off. [00:40:25] And C++, for example, huge, complicated language. People always assume that it's impossible to implement and it's very nearly impossible, but it's just really, really hard. [00:40:35] And the way to get there is to build it one piece at a time, incrementally. [00:40:39] And and there that was only possible because we were lucky to hire some really exceptional engineers that that new various parts of it very well and and could do great things. [00:40:49] Swift was kind of a similar thing. [00:40:51] So Swift came from we were just finishing off the first version of C++ support in Klang. [00:40:59] And C++ is a very formidable and very important language, but it's also ugly and of ways. And you can't implement C++ without thinking there has to be a better thing. Right. [00:41:11] And so I started working on Swift again with no hope or ambition that would go anywhere just to see what could be done. Let's play around with this thing. It was, you know, me in my spare time not telling anybody about it kind of a thing. And it made some good progress. I'm like, actually, it would make sense to do this. At the same time, I started talking with the senior VP of software at the time, a guy named Transfer there. [00:41:34] And Bertran was very encouraging. He was like, well, you know, let's let's have fun. Let's talk about this. And he was a little bit of a language guy. [00:41:40] And so he helped guide some of the early work and encouraged me and like, got things off the ground and eventually told my manager and told other people and and it started making progress. [00:41:56] The the complicating thing was swift, was that the idea of doing a new language is not obvious to anybody, including myself. [00:42:04] And the tone at the time was that the iPhone was successful because of Objective C. Right. Oh, interesting. In spite of or just because of and you have to understand that at the time Apple was hiring software people that loved Objective C, right. [00:42:22] And it wasn't that they came despite Objective C, they loved objectively, and that's why they got hired. [00:42:27] And so you had a software team that the leadership and in many cases went all the way back to next where Objective C really became real. [00:42:36] And so they, quote unquote grew up writing Objective C and many of the individual engineers all were hired because they love to see. [00:42:45] And so this notion of, OK, let's do new language was kind of heretical in many ways. Right. [00:42:51] Meanwhile, my sense was that the Alawite community wasn't really in love with objectivity. Some people were and some of the most outspoken people were. [00:42:57] But other people were hitting challenges because it has very sharp corners and it's difficult to learn. [00:43:03] And so one of the challenges of making swift happen that was totally non-technical is the the social part of what do we do? [00:43:14] Like if we do a new language, which at Apple, many things happen that don't ship. Right. So if we if we ship it, what what what is the metrics of success? [00:43:22] Why would we do this? Why wouldn't we make objectively better if objectively as problems, let's file off those rough corners and edges. And one of the major things that became the reason to do this was this notion of safety, memory, safety. [00:43:36] And the way Objective C works is that a lot of the object system and everything else is built on top of pointers and see objectively as an extension on top of C. [00:43:47] And so pointers are unsafe and if you get rid of the pointers, it's not objective C anymore. [00:43:53] All right. And so fundamentally, that was an issue that you could not fix safety or memory safety without fundamentally changing the language. [00:44:02] And so once we got through that part of the the mental process and the thought process, it became a design process of saying, OK, well, if we're going to do something new, what what is good? [00:44:13] Like, how do we think about this and what are we like and what are we looking for? [00:44:16] And and that that was a very different phase of it. [00:44:19] So. Well, what are some design choices early on and swift like we're talking about Brace's. [00:44:26] Are you making a type language? You know, all those kinds of things. Yeah. [00:44:30] So so some of those were obvious given the context. [00:44:33] So I type language, for example, objectiveness, a type language and going with another type of language wasn't really seriously considered. [00:44:41] We wanted we wanted the performance and we wanted refactoring tools and other things like that to go with type languages. [00:44:46] Quick dumb question. [00:44:48] Yeah. Was it obvious? I think this would be a dumb question, but was it obvious that the language has to be a compiler language? Not a yes. [00:44:57] That's not a dumb question. Earlier, I think late 90s, Apple is seriously considering moving its development experience to Java. But that's what started in 2010, which was several years after the iPhone, was when the iPhone was definitely on an upward trajectory and the iPhone was still extremely and is still a bit memory constrained. [00:45:18] And so being able to compile the code and then ship it and then have having standalone code that is not yet compiled is a very big deal and it's very much part of the apple value system. Now, JavaScript is also a thing. [00:45:34] I mean, it's not it's not that this is exclusive and technologies are good depending on how they're applied. Right. [00:45:41] But in the design of SWIFT saying, like, how can we make objectively better objectively of statically comp. And that was the contiguous natural thing to do. [00:45:49] Just skip ahead a little bit now, right back. Just just as a question, as you think about today in 2019 in your work at Google and so on, is again, compilations, static compilation. The right the still the right thing. Yeah. [00:46:06] So the funny thing, after working on compilers for a really long time, is that and this is one of the things that LVM has helped with is that I don't look as a compilation as being static or dynamic or interpreted or not. This is a spectrum. [00:46:24] And one of the cool things about Swift is that Swift is not just statically compiled, it's actually dynamically compiled as well. And it can also be interpreted that nobody's actually done that. And so what what ends up happening when you use Swift in the workbook, for example, and Coolabah and Jupiter is it's actually dynamically compiling the statements as you execute them. And so this gets back to the the software engineering problems, right. Where if you layer the stack properly, you can actually completely change how and when things get compiled because you have the right abstractions there. [00:46:58] And so the way that a CoLab workbook works was swift is that we start tapping into it. [00:47:04] It creates a process, a Unix process, and then each line of code you type in, it compiles it through the Swift compiler, the front end part and then sends it through the optimizer compiles machine code and then injects it into that process. And so as you're typing new stuff, it's putting it's like squirting a new code and overwriting and replacing and updating code in place, and the fact that it can do this is not an accident like it was designed for this. [00:47:32] But it's an important part of how the language was set up and how it's layered. And and this is a non obvious piece. And one of the things was swift. That was, for me, a very strong design point is to make it so that you can learn it very quickly. And so from a language design perspective, the thing that I always come back to is the UI principle of progressive disclosure of complexity. And so in Swift, you can start by saying print quote, hello, world quote. [00:48:00] Right. [00:48:01] And there's no solution. Just like Python. [00:48:03] One line of code, no man, no files, no header files, no. Public static, class void blah blah blah. String like Java has. Right. One line of code. Right. And you can teach that and great. [00:48:15] They can say, well, let's introduce variables and so you can declare variable far Savar X equals four. What is a variable. You can use X, X plus one. This is what it means. Then you can say, well how about contraflow. Well this is one if statement is this is what a fourth statement is. [00:48:29] This is what a wild statement is, then you can say let's introduce functions and and many languages like Python have had this this kind of notion of let's introduce small things and they can add complexity, they can introduce classes and they can add generics in the case as well. And then you can add modules and build out in terms of the things that you're expressing. But this is not very typical for compiled languages. And so this was a very strong design point. [00:48:55] And one of the reasons that Swift in general is designed with this factoring of complexity in mind so that the language can express powerful things. [00:49:03] You can write from Rantes if you want to, but it has a very high level feel, which is really this perfect blend, because often you have very advanced library writers that want to be able to use the the nitty gritty details. But then other people just want to use the libraries and work at a higher abstraction level. It's kind of cool there so that you can just interoperability. [00:49:26] I don't think I pronounce that word enough, but you can just drag in Python. It's just you can import like so this is the most important number, how do you make that happen? Yeah, let's say is that as easy as it looks or is it. Yes. [00:49:43] Look, that's not that's not a stage magic act or anything like that. [00:49:46] I don't mean from the user perspective, I mean from the implementation perspective to make it happen. [00:49:51] So it's easy once all the pieces are in place, the way it works. So if you think about it, dynamically typed language like Python, you can think about it in two different ways. You can say it has no type's right, which is what most people would say. Or you can say it has one type. Right. And you can say it has one type. And it's like the python object and the python object is passed around. And because there's only one type, it's implicit. [00:50:14] OK. And so what happens was Swift and Python talking to each other. [00:50:18] Swift has lots of types, has arrays and it has strings and all classes and that kind of stuff. [00:50:24] But it now has a python object type. So there is one python object type. And so when you say import Nampo, what you get is a python object, which is the module. [00:50:37] Then you say expeditor says, OK, hey, hey, python object. I have no idea what you are. [00:50:42] Give me your remember. OK, cool, and just it just uses dynamic stuff, talks to the Python interpreter and says, hey, Python, what's the daughter, remember, in that python object gives you back another python object. [00:50:54] And I say parentheses for the call and the arguments are going to pass. And so then it says, hey, a python object that is the result of expeditor call with these arguments again, calling into the python interpreter to do that work. [00:51:07] And so right now, this is all really simple. And if you if you dive into the code, what you'll see is that the the python module and swift is something like twelve hundred lines of code or something is written in pure swift. [00:51:19] It's super simple and it's and it's built on top of the C interoperability because it just talks to the Python interpreter. [00:51:26] But making that possible requires us to add two major language features to Swift to be able to express these dynamic calls and the dynamic member lookups. And so what we've done over the last year is we've proposed implement standardized and contributed new language features to the swift language in order to make it so it is really trivial. Right. And this is one of the things about Swift that is critical to the 10th floor work, which is that we can actually add new language features and the bar for adding those is higher. [00:51:56] But it's it's what makes it possible. [00:51:59] So, you know, Google doing incredible work on several things, including of so terms of Flow 2.0 or whatever, leading up to 2.0 has by default in 2.0, has Eger execution in. [00:52:14] Yet in order to make code optimized for GPU, ATP or some of these systems, computation needs to be converted to a graph. So what's that process like? What are the challenges there? [00:52:26] Yeah, so I'm tangentially involved in this, but the, the way that it works with autograph is that. [00:52:34] You mark your of your function with the decorator, and when Python calls it, that decorator is invoked and then it says, before I call this function, you can transform it. And so the way autograph works is, as far as I understand, is it actually uses the python parser to go past that, turn into a syntax tree and apply compiler techniques to again transform this down into sensible graphs. And so it you can think of it as saying, hey, I have an if statement I'm going to create and if node in the graph like you say, can't you have a multiply or I'll turn that into a multiplying node in the graph and that becomes this tree transformation. [00:53:14] So where does the swift photons come in, which is you know, Perla's for one Swifties interface, like Python is an interface. It has a flow, but it seems like there's a lot more going on and just a different language interface. There's optimization methodology. [00:53:32] So so the center of the world has a couple of different what I'd call front end technologies and so Swift and Python and Go and Rostand Julia and all these things share the tenth of the graphs and all the runtime and everything that's later on. [00:53:49] And so photons flow is merely another front end for tensor flow, just like any of these other systems. Or there's a major difference between, I would say, three camps of technology. There's Python, which is a special case because the vast majority of the community effort is going to the Python interface and Python has its own approaches for automatic differentiation, has its own APIs and all this kind of stuff there. Swift, which I'll talk about in a second, and then there's kind of everything else. [00:54:19] And so the everything else in our effectively language bindings. So they call into the tense flow runtime, but they're not they usually don't have automatic differentiation or they usually don't provide anything other than APIs that call the KPIs intense workflow. [00:54:33] And so they're kind of wrappers for that Swifties really kind of special. And it's a very different approach. [00:54:39] Swift returns for that is this is a very different approach because they're saying, let's look at all the problems that need to be solved in the full stack of the Tenterfield compilation process. [00:54:51] If you think about it that way, because Tenzer Flow is fundamentally a compiler, it takes models and then it makes them go fast on hardware. [00:54:59] Mm hmm. That's what a compiler does. And it has a front end, has an optimizer, and it has many backhands. And so if you think about it the right way or in and if you look at it in a particular way, like it is a compiler. [00:55:14] And and so swift is merely another front end. [00:55:19] But it's saying in the design principle saying, let's look at all the problems that we face as machine learning practitioners and what is the best possible way we can do that, given the fact that we can change literally anything in this entire stack in Python, for example, where the vast majority of the engineering and an effort has gone into is constrained by being the best possible thing you can do with the Python library, like there are no Python language features that are added because of machine learning that I'm aware of. [00:55:49] They added a matrix multiplication operator with that, but that's as close as you get. [00:55:55] And so with Swift, you can you it's hard, but you can add language features to the language and there's a community process for that. And so we look at these things and say, well, what is the right division of labor between the human programmer and the compiler? And Swift has a number of things that shift that balance. So because it's a because it has a type system, for example, it makes certain things possible for analysis of the code and the compiler can automatically build graphs for you without you thinking about them. [00:56:25] Like that's that's a big deal for a programmer. You just get free performance, you get clustering, infusion and optimization, things like that, without you as a programmer having to manually do it because the compiler can do it for you. UniMac differentiation. There's another big deal. And I think one of the key contributions of the Swift Flow Project. [00:56:45] Is that there's this entire body of work on automatic differentiation that dates back to the fourth trend is people doing a tremendous amount of numerical computing in Fortran used to rate these what they call source to source translators, where you where you take a bunch of code and shove it into a mini compiler and push out more Fortran code. But it would generate the bakradze passes for your functions, for you, the derivatives. Right. [00:57:10] And so in that work in the 70s, a tremendous number of optimizations, a tremendous number of techniques for fixing numerical instability and other other kinds of problems were developed. [00:57:22] But they're very difficult to port into a world where in your execution you get an update at a time like you need to be able to look at entire function and be able to reason about what's going on. And so when you have a language integrated automatic differentiation, which is one of the things that the Swift Project is focusing on, you can open up and all these techniques and reuse them in familiar ways. [00:57:45] But the language integration piece has a bunch of design room and it's also complicated. [00:57:50] The other piece of the puzzle here that's kind of interesting is to use a Google. Yes. So, you know, we're in a new world with deep learning. It's constantly changing. And I imagine without disclosing anything, I imagine, you know, you're still innovating. And the CPU front, too. Indeed. [00:58:06] So how much sort of interplay between software and hardware and trying to figure out how to together move towards an optimal solution? There's an incredible amount. So we're on our third generation of TVs, which are now 100 per teraflops and a very large liquid called box virtual box with no color. And as you might imagine, we're not out of ideas yet. The great thing about TPS is that they're a perfect example of hardware, software, code design. And so it's about it's about saying what hardware do we build to solve certain classes of machine learning problems? [00:58:41] Well, the algorithms are changing, like the hardware takes, you know, some cases years to produce. Right. And so you have to make bets and decide what is going to happen. And so and what is the best way to spend the transistors to get the maximum, you know, performance per watt or area cost or whatever it is that you're optimizing for. And so one of the amazing things about TV is, is this numeric format called Beefalo 16 before 16 is a compressed 16 bit floating point format. [00:59:11] But it puts the bits in different places in numeric terms. It has a smaller amount and a larger exponent. That means that it's less precise, but it can represent larger ranges values, which in the machine learning context is really important and useful because sometimes you have very small gradients you want to accumulate and very, very small numbers that are important to to move things as you're learning. But sometimes you have very large magnitude numbers as well. And before 16 is not as precise the a small but it turns out the machine learning algorithms actually want to generalize. [00:59:48] And so there's, you know, theories that this actually increases the ability for the network to generalize across datasets. And regardless of whether it's good or bad, it's much cheaper at the hardware level to implement because the area and time of a multiplier is and squared in the number of bits in the mantis. But it's linear with size of the exponent connected to solid efforts here, both on the hardware and software side. [01:00:14] Yeah, and so that was a breakthrough coming from the research side and people working on optimizing network transport of weights across the network originally and try and find ways to compress that. But then it got burned into silicon. And it's a key part of what makes Tipu performance so amazing and and and great now to so many different aspects of it that are important. [01:00:37] But the the code design between the low level compiler bits and the software bits and the algorithms is all super important. And it's this amazing trifecta that only Google can do. [01:00:50] Yeah, that's super exciting. [01:00:51] So can you tell me about LIRR project previously? This the secretive one? [01:00:58] Yeah, so am I. Is a project that we announced at a compiler conference. Three weeks ago or something, the Compilers for Machine Learning Conference, basically, again, if you look at tensor flow as a compiler stack has a number of compiler algorithms within it. [01:01:13] It also has a number of compilers that get embedded into it, and they're made by different vendors. For example, Google has Xolair, which is a great compiler system and video has 10 30. Intel has an Grauwe. There's a number of these different compiler systems and they're very specific and they're trying to solve different parts of the problems. But they're all kind of similar in a sense of they want to integrate with Tenzer. So that has an optimizer and it has these different cogeneration technologies built in the idea. [01:01:43] Volaris to build a common infrastructure to support all these different subsystems. And initially it's to be able to make it so that they all plug in together and they can share a lot more code and can be reusable. But over time, we hope that the industry will start collaborating and sharing code. And instead of reinventing the same things over and over again, that we can actually foster some of that, that, you know, working together to solve common problem energy that has been useful in the compiler field before. [01:02:11] Beyond that, I mean, there is some people have joked that it's kind of LVM to learn a lot about what LVM has been good and what LVM has done wrong. And it's a chance to fix that. [01:02:23] And also, there are challenges in the LVM ecosystem as well, where LVM is very good at the thing it was designed to do. But, you know, 20 years later, the world has changed and people try to solve higher level problems. And we need we need some new technology. [01:02:37] And what's the future of opensource in this context? Very soon. [01:02:42] So it is not yet open source, but it will be hopefully you will believe in the value of open source and because. Oh, yeah, absolutely. [01:02:49] And I think that the sense of the community at large fully believes in open source. [01:02:54] I mean, that there is a difference between Apple, where you were previously, and Google now in spirit and culture. And I would say the open source in terms of flow was a seminal moment in the history of software, because here's this large company releasing a very large code base, open sourcing. What are your thoughts on that? How happy or not were you to see that kind of degree of open sourcing between the two? [01:03:20] I prefer the Google approach, if that's what you're saying. The Apple approach makes sense given the historical context that Apple came from, but that's been 35 years ago and I think the apple is definitely adapting. And the way I look at it is that there's different kinds of concerns in the space. Right. [01:03:40] It is very rational for a business to to care about making money like that fundamentally is what the business is about. Right. But I think it's also incredibly realistic to say it's not your string library. That's the thing that's going to make you money. It's going to be the amazing UI product, differentiating features and other things like that that you built on top of your string library. And so keeping your string library proprietary and secret and things like that, maybe not the the important thing anymore. [01:04:11] Right. Well, before platforms where we're different. [01:04:14] Right. And even 15 years ago, things were a little bit different. But the world is changing. So Google strikes a very good balance, I think. And I think the potential for being open source really changed the entire machine learning field and it caused a revolution in its own right. [01:04:31] And so I think it's amazing for amazingly forward looking, because I could have imagined and I was at Google at the time, but I could imagine a different context in a different world where a company says machine learning is critical to what we're doing. We're not going to give it to other people. Right. And so that decision is a profound, profoundly brilliant insight that I think has really led to the world being better and better for Google as well and has all kinds of ripple effects. [01:04:59] I think it is really I mean, you can't understate Google deciding that how profound that is for software. It's awesome. Well, it has been. [01:05:08] And again, I can understand the the concern about if we release our machine learning software are our competitors could go faster. [01:05:17] But on the other hand, I think that open sourcing has been fantastic for Google. And I'm sure that obviously that that that decision was very non obvious at the time. But I think it's worked out very well. [01:05:28] So let's try this real quick. You were at Teszler for five months as the VP of Autopilot Software, you led the team during the transition from each hardware one hardware to have a couple questions or one. First of all, to me, that's one of the bravest engineering decisions undertaking sort of like undertaken undertaking really ever in the automotive industry. To me, software wise, starting from scratch. It's a really brave decision. So my one question is there is what was that like? [01:05:59] What was the challenge of that? [01:06:01] Do you mean the career decision of jumping from a comfortable, good job into the unknown or that combined with the at the individual level, you making that decision and then when you show up, you know, it's a really hard engineering process. [01:06:15] So you could just stay maybe slow down the hardware one or those kinds of decisions are just taking a full on. Let's do this from scratch. What was that like? [01:06:28] Well, so, I mean, I think Tesla has a culture of taking things slow and seeing how it goes. So, I mean, one of the things that attracted me about Tesla is it's very much a gung ho. Let's change the world, let's figure it out kind of a place. And so I have a huge amount of respect for that. Tesla has done very smart things with hardware, one in particular, and the hardware one design was originally designed to be very simple automation features in the car for like traffic workers, cruise control and things like that. [01:06:57] And the fact that they were able to effectively feature creep into landholding and a very useful driver assistance feature is pretty astounding, particularly given the details of the hardware hardware to build on that a lot of ways. [01:07:11] And the challenge there was that they were transitioning from a third party provided vision stack to an in-house built vision stack. And so for the first step, which I mostly helped with, was getting onto that new vision stack. And that was very challenging. And there it was, Time-critical for various reasons, and it was a big leap. But it was fortunate that it built on a lot of the knowledge and expertise and the team that had built hardware ones, driver's license features. [01:07:40] So you spoke in a collected and kind way about your time in Tesla, but it was ultimately not a good fit. Elon Musk, we've talked on this podcast several guess the course. Elon Musk continues to do some of the most bold and innovative engineering work in the world at times at the cost some of the members of the Tesla team. What did you learn about this working in this chaotic world that John? [01:08:03] Yeah, so I guess I would say that when I was at Tesla, I experienced and saw the highest degree of turnover I'd ever seen in a company, which was a bit of a shock. [01:08:15] But one of the things I learned when I came to respect is that he was able to attract amazing talent because he has a very clear vision of the future and he can get people to buy into it because they want that future to happen. [01:08:26] Right. And the power of vision is something that I have a tremendous amount of respect for. And I think that Elon is fairly singular in the world in terms of the things he's able to get people to believe in. And it's it's a very it's very there may be people that down the street corner and say, oh, we're going to go to Mars. [01:08:46] Right. [01:08:46] But then but then there are a few people that can get other others to buy into it and believe in build the path and make it happen. And so I respect that. [01:08:56] I don't respect all of his methods, but but I have a huge amount of respect for that. [01:09:02] You've mentioned a few places, including in this context, working hard. What does it mean to work hard? And when you look back at your life, what were some of the most brutal periods of having to really sort of put everything you have into something? [01:09:20] Yeah, good question. So working hard can be defined a lot of different ways, so a lot of hours. And so that's that is true. The thing to me that's the hardest is both being short term, focused on delivering and executing and making a thing happen while also thinking about the longer term. [01:09:40] And trying to balance that right, because if you are myopically focused on solving a task and getting that done and only think about that incremental next step, you will miss the next big hurdle you should jump over to. [01:09:52] Right. And so I've been really fortunate that. [01:09:56] I've been able to kind of oscillate between the two and historically at Apple, for example, that was made possible because I was able to work some really amazing people and build up teams and leadership structures and and allow them to grow in their careers and take on responsibility, thereby freeing up me to be a little bit crazy and thinking about the next thing. [01:10:20] And so it's a lot of that, but it's also about, you know, with experience, you make connections that other people don't necessarily make. And so I think that is that's a big part as well. But. The bedrock is just a lot of hours and. You know, that's OK with me. There's different theories on work life balance and my theory for myself, which I do not project under the team, but my theory for myself is that, you know, I want to love what I'm doing and work really hard and my purpose. [01:10:49] I feel like my goal is to change the world and make it a better place. And that's that's what I'm really motivated to do. [01:10:57] So last question, LVM logo is a dragon, yeah, you explain that this is because dragons have connotations of power, speed intelligence can also be sleek, elegant and modular. So you move the modular part. What is your favorite Dragon related character from fiction video or movies? So those are all very kind of ways of explaining that, you know, the real reason is the dragon. Yeah. So there is a seminal book on compiler design called The Dragon Book. [01:11:29] And so this is a really old now book on compilers. [01:11:33] And so the Dragon logo for LVM came about because at Apple we kept talking about LVM related technologies and there was no logo to put on a slide and sort of like, what do we do? [01:11:45] And somebody is like, well, what kind of logo should a compiler technology have? And I'm like, I don't know. I mean, the dragons are the dragon is the best thing that that we've got. [01:11:54] And, you know, Apple somehow magically came up with the logo and and it was a great thing and the whole community rallied around it. And then it got better as other graphic designers got involved. But that's that's originally where it came from. [01:12:06] The story is there dragons from fiction that you connect with for that Game of Thrones, Lord of the Rings, that kind of thing? [01:12:15] A lot of the rings is great. I also like roleplaying games and things like computer playing games. And some dragons often show up in there, but but really comes back to to to the book. [01:12:24] Oh, no, we need we need a thing. Yeah. And hilariously, one of the one of the the funny things about LVM is that my wife, who's amazing, runs the the LVM Foundation and she goes to Grace Hopper and is trying to get more women involved in the she's also a compiler engineer. [01:12:41] So she's trying to get other other women to get interested in compilers and things like this. And so she hands out the stickers and people like the Altium sticker because of Game of Thrones. And so sometimes culture has this helpful effect to get the next generation of engineers engaged with the cars. OK, awesome. Chris, thanks so much for your time. [01:13:01] It's been great talking with you.

本集資源與出處