擴散模型是實時遊戲引擎
作者: Dani Valevski(谷歌研究)、Yaniv Leviathan(谷歌研究)、Moab Arar(特拉維夫大學)、Shlomi Fruchter(谷歌 DeepMind)
ArXiv連結: https://arxiv.org/abs/2408.14837
項目網站: https://gamengen.github.io
摘要
我們介紹了GameNGen,這是第一個完全由神經模型驅動的遊戲引擎,能夠在長軌跡上與複雜環境進行高質量的實時交互。GameNGen 可以在單個 TPU 上以每秒超過 20 幀的速度交互模擬經典遊戲 DOOM。下一幀預測的 PSNR 為 29.4,與有損 JPEG 壓縮相當。在區分遊戲短片和模擬片段方面,人類評分員的表現僅略好於隨機概率。GameNGen 的訓練分為兩個階段:(1) 一個強化學習代理學習玩遊戲,並記錄訓練過程;(2) 訓練一個擴散模型,以過去的幀和動作序列為條件生成下一幀。條件增強技術可在長軌跡上實現穩定的自動回歸生成。
請參見 https://gamengen.github.io 獲取演示視頻。
1 介紹
計算機遊戲是圍繞以下「遊戲循環」手動製作的軟體系統:(1) 收集用戶輸入,(2) 更新遊戲狀態,(3) 將其渲染為屏幕像素。這個遊戲循環以很高的幀率運行,為玩家營造出一個交互式虛擬世界的假象。這種遊戲循環通常在標準計算機上運行,儘管也有許多在定製硬體上運行遊戲的驚人嘗試(例如,標誌性遊戲《毀滅戰士》曾在烤麵包機、微波爐、跑步機、照相機、iPod 上運行,甚至在 Minecraft 遊戲中運行——僅舉幾例,請參見 https://www.reddit.com/r/itrunsdoom/),但在所有这些情况下,硬件仍然是直接模拟手动编写的游戏软件。此外,尽管游戏引擎千差万别,但所有引擎中的游戏状态更新和渲染逻辑都是由一套手动编程或配置的规则组成的。
近年來,生成模型在根據文本或圖像等多模態輸入生成圖像和視頻方面取得了重大進展。在這一浪潮的前沿,擴散模型成為非語言媒體生成的事實標準,如 Dall-E(Ramesh 等人,2022)、Stable Diffusion(Rombach 等人,2022)和 Sora(Brooks 等人,2024)。乍一看,模擬視頻遊戲的交互世界似乎與視頻生成類似。然而,"交互式"世界模擬不僅僅是快速生成視頻。因為生成過程中需要以輸入動作流為條件,而輸入動作流只能在生成時獲取,這打破了現有擴散模型架構的一些假設。尤其是,它要求自回歸地生成幀,這往往是不穩定的,並導致採樣發散(見 3.2.1 節)。
有幾項重要研究(Ha & Schmidhuber,2018;Kim 等人,2020;Bruce 等人,2024)(見第6節)使用神經模型來模擬交互式視頻遊戲。然而,這些方法大多在模擬遊戲的複雜性、仿真速度、長時間的穩定性或視覺質量等方面存在局限性(見圖2)。因此,自然而然地會問:
一個實時運行的神經模型是否能夠以高質量模擬複雜的遊戲?
在這項工作中,我們證明答案是肯定的。具體來說,我們展示了一款複雜的視頻遊戲——標誌性遊戲《DOOM》,可以在神經網絡(開放式 Stable Diffusion v1.4 的增強版(Rombach 等人,2022))上實時運行,同時獲得與原始遊戲相當的視覺質量。儘管這不是精確仿真,該神經模型能夠執行複雜的遊戲狀態更新,例如統計生命值和彈藥、攻擊敵人、破壞物體、開門,以及在長軌跡上持續保持遊戲狀態。
GameNGen 回答了在通往遊戲引擎新範式的道路上一個重要的問題,即遊戲可以自動生成,就像近年來神經模型生成圖像和視頻一樣。仍然存在關鍵問題,例如如何訓練這些神經遊戲引擎,以及如何有效地創建遊戲,包括如何最佳地利用人類輸入。儘管如此,我們對這種新範式的可能性感到非常興奮。
2 互動世界仿真
一個交互環境由一個潛在狀態空間、一個潛在空間的部分投影空間、一個部分投影函數、一組動作,以及一個轉移概率函數,使得。
例如,在遊戲 DOOM 中, 是程序的動態內存內容, 是渲染的屏幕像素, 是遊戲的渲染邏輯, 是按鍵和滑鼠移動的集合,而 是基於玩家輸入的程序邏輯(包括任何潛在的非確定性)。
給定輸入交互環境 和初始狀態 ,一個「交互世界模擬」是一個「模擬分布函數」 。給定觀測值之間的距離度量 ,一個「策略」,即給定過去動作和觀測的代理動作分布 ,初始狀態分布 和回合長度分布 ,交互世界模擬的目標是最小化 ,其中 ,,以及 是在執行代理策略 時從環境和模擬中抽取的觀測值。重要的是,這些樣本的條件動作總是通過代理與環境 交互獲得,而條件觀測既可以從 獲得(「教師強迫目標」),也可以從模擬中獲得(「自回歸目標」)。
我們總是使用教師強迫目標來訓練我們的生成模型。給定一個模擬分布函數 ,可以通過自回歸地採樣觀測值來模擬環境 。
3 GameNGen
GameNGen(發音為「遊戲引擎」)是一個生成擴散模型,它能夠在第2節的設置下學習模擬遊戲。為了收集該模型的訓練數據,我們首先使用教師強制目標訓練一個獨立的模型與環境進行交互。這兩個模型(代理和生成模型)依次進行訓練。在訓練過程中,代理的全部行為和觀察語料 被保留下來,並在第二階段成為生成模型的訓練數據集。見圖 3。
3.1 通過代理進行數據收集
我們的最終目標是讓人類玩家與我們的仿真進行互動。為此,第2節中的策略即為「人類遊戲策略」。由於我們無法直接大規模地從中取樣,因此我們首先通過教一個自動代理來玩遊戲,以此來近似人類遊戲。與典型的強化學習設置不同,該設置旨在最大化遊戲得分,我們的目標是生成與人類遊戲類似的訓練數據,或者至少在各種場景下包含足夠多的多樣化示例,以最大化訓練數據的效率。為此,我們設計了一個簡單的獎勵函數,這是我們的方法中唯一與環境相關的部分(見附錄A.3)。
我們在整個訓練過程中記錄了代理的訓練軌跡,其中涵蓋了不同技能水平的遊戲。這組記錄的軌跡構成了我們的數據集,用於訓練生成模型(見第3.2節)。
3.2 訓練生成擴散模型
現在,我們訓練一個生成擴散模型,該模型以在前一階段收集的代理軌跡(行動和觀察)作為條件。
我們重新利用預訓練的文本到圖像擴散模型 Stable Diffusion v1.4(Rombach 等人,2022)。我們將模型 置於軌跡 的條件下,即在之前的動作 和觀察(幀) 的序列條件下,並移除所有文本條件。具體來說,為了以動作為條件,我們僅需學習將每個動作(例如按下特定按鍵)嵌入為單個標記的 ,並將文本的交叉注意力替換為該編碼動作序列。為了對觀察(即之前的幀)進行條件化,我們使用自動編碼器 將它們編碼到潛在空間中,並在潛在通道維度中將它們串聯到噪聲潛在空間中(見圖 3)。我們還嘗試通過交叉注意力對這些過去的觀察進行條件化,但沒有觀察到有意義的改進。
我們通過速度參數化訓練模型,使得擴散損失最小化(Salimans & Ho, 2022b):
Failed to parse (syntax error): {\displaystyle \mathcal{L} = {{\mathbb{E}}_{t,\epsilon,T}\left\lbrack {\|{v{(\epsilon,x_{0},t)}} - {v_{\theta^{\prime}}{(x_{t},t,\{{\phi{(o_{i < n})}}\},\{{A_{emb}{(a_{i < n})}}\}})}}\|}_{2}^{2} \right\rbrack}} (1)
其中 Failed to parse (syntax error): {\displaystyle T = {\{ o_{i \leq n},a_{i \leq n}\}} \sim \mathcal{T}_{代理}} ,,,,,,而 是模型 的 v預測輸出。噪聲調度 是線性的,與 Rombach 等(2022)類似。
3.2.1 使用噪聲增強緩解自回歸漂移
如圖4所示,教師強制訓練和自動回歸採樣之間的領域偏移會導致誤差積累和採樣質量的快速下降。為了避免由於模型的自動回歸應用而導致的這種偏差,我們在訓練時向編碼幀中添加不同程度的高斯噪聲來擾動背景幀,並將噪聲水平作為輸入提供給模型,仿效 Ho 等人(2021)的方法。為此,我們對噪聲水平 進行均勻採樣,直至最大值,然後對其進行離散化,並為每個區間學習一個嵌入(見圖3)。這使得網絡能夠糾正前幾幀中的採樣信息,對於長期保持幀質量至關重要。在推理過程中,可以控制添加的噪聲水平以最大化質量,儘管我們發現,即使不添加噪聲,結果也顯著改善。我們將在5.2.2部分分析這種方法的影響。
3.2.2 潛在變量解碼器微調
Stable Diffusion v1.4 的預訓練自動編碼器將 8x8 像素塊壓縮為 4 個潛通道,在預測遊戲幀時會導致有意義的偽影,影響小細節,尤其是底欄 HUD(「抬頭顯示」)。為了在提高圖像質量的同時利用預訓練的知識,我們僅使用針對目標幀像素計算的 MSE 損失來訓練潛在自動編碼器的解碼器。使用 LPIPS(Zhang 等人(2018))等感知損失可能會進一步提高質量,我們將其留待未來工作中研究。重要的是,請注意這個微調過程完全獨立於 U-Net 微調過程,而且自回歸生成不受其影響(我們僅對潛變量自回歸地進行條件設置,而非像素)。附錄 A.2 展示了對自動編碼器進行微調和不進行微調的生成示例。
3.3 推理
3.3.1 設置
我們使用DDIM採樣(Song等人,2022)。我們僅對過去觀測條件採用了無分類器指導(Ho & Salimans,2022)。我們發現對過去動作條件的指導無法提高質量。我們使用的權重相對較小(1.5),因為較大的權重會產生偽影,而我們的自動回歸採樣則會放大這些偽影。
我們還嘗試了同時生成 4 個樣本並合併結果,希望能防止罕見的極端預測被採納,並減少誤差累積。我們嘗試了對樣本進行平均和選擇最接近中位數的樣本。平均效果略遜於單幀,而選擇最接近中位數的樣本效果僅略有提升。由於這兩種方法都會將硬體需求提高到 4 個張量處理單元(TPU),因此我們決定不使用這些方法,但注意到這可能是未來研究的一個有趣領域。
3.3.2 去噪器採樣步驟
在推理過程中,我們需要運行 U-Net 去噪器(進行若干步)和自動編碼器。在我們的硬體配置(TPU-v5)下,一次去噪步驟和自動編碼器的評估各需 10 毫秒。如果我們以單步去噪器運行模型,設置中的最小總延遲為每幀 20 毫秒,即每秒 50 幀。通常情況下,生成擴散模型(如 Stable Diffusion)通過單次去噪步驟無法產生高質量結果,而是需要數十個採樣步驟才能生成高質量圖像。令人驚訝的是,我們發現只需 4 個 DDIM 採樣步驟,就能穩健地模擬 DOOM(Song 等人,2020)。實際上,我們觀察到使用 4 步採樣與使用 20 步或更多步採樣相比,模擬質量沒有下降(見附錄 A.4)。
僅使用 4 個去噪步驟導致 U-Net 總耗時為 40 毫秒(包括自動編碼器的推理總耗時為 50 毫秒),即每秒 20 幀。我們推測,在我們的案例中,較少步驟對質量影響可忽略不計,是由於以下因素的結合:(1) 受限的圖像空間,以及 (2) 前一幀的強條件作用。
由於我們在使用單步採樣時確實觀察到了質量下降,因此我們在單步設置中進行了類似於(Yin 等人,2024;Wang 等人,2023)的模型蒸餾實驗。蒸餾確實有很大幫助(使我們達到了上述的 50 FPS),但仍會對仿真質量造成一定影響,因此我們選擇在我們的方法中使用不帶蒸餾的 4 步版本(見附錄 A.4)。這是一個值得進一步研究的有趣領域。
我們注意到,類似於 NVidia 的經典 SLI 交替幀渲染(AFR)技術,通過在額外硬體上並行生成多個幀,可以顯著提高圖像生成速率。然而,與 AFR 類似,實際的仿真速率不會提高,輸入延遲也不會減少。
4 實驗設置
4.1 代理訓練
代理模型使用 PPO(Schulman 等人,2017)進行訓練,採用簡單的 CNN 作為特徵網絡,基於 Mnih 等人(2015)的方法。在 CPU 上使用 Stable Baselines 3 基礎架構(Raffin 等人,2021)進行訓練。代理接收縮小後的幀圖像和遊戲地圖,每個解析度為 160x120。代理還可以訪問其最近執行的 32 次動作。特徵網絡為每幅圖像計算出大小為 512 的表示。PPO 的 actor 和 critic 是基於圖像特徵網絡輸出和過去動作序列連接的兩層 MLP 頭。我們使用 Vizdoom 環境(Wydmuch 等人,2019)訓練代理來玩遊戲。我們並行運行了 8 個遊戲,每個遊戲的回放緩衝區大小為 512,折扣因子為 ,熵係數為 。在每次迭代中,我們使用批量大小為 64 的數據進行 10 個時代的訓練,學習率為 1e-4。我們總共執行了 1000 萬個環境步驟。
4.2 生成模型訓練
我們使用 Stable Diffusion 1.4 的預訓練檢查點訓練所有仿真模型,解凍所有 U-Net 參數。我們使用的批量大小為 128,恆定學習率為 2e-5,採用無權重衰減的 Adafactor 優化器(Shazeer & Stern,2018),以及梯度剪切為 1.0。我們將擴散損失參數化更改為 v預測(Salimans & Ho 2022a)。我們以 0.1 的概率去掉上下文幀條件,以便在推理過程中使用 CFG。我們使用 128 台 TPU-v5e 設備進行數據並行化訓練。除非另有說明,本文中的所有結果均為 700,000 步訓練後的結果。對於噪聲增強(第3.2.1節),我們使用的最大噪聲水平為 0.7,並設有 10 個嵌入桶。在優化潛在解碼器時,我們使用的批次大小為 2,048;其他訓練參數與去噪器的參數相同。在訓練數據方面,除非另有說明,我們使用了代理在強化學習訓練期間的所有軌跡以及訓練期間的評估數據。總體而言,我們生成了 9 億幀用於訓練。所有圖像幀(在訓練、推理和條件期間)的解析度均為 320x240,並填充為 320x256。我們使用的上下文長度為 64(即向模型提供其自身的最後 64 次預測以及最後 64 次操作)。
5 結果
5.1 仿真質量
總體而言,從圖像質量來看,我們的方法在長軌跡上實現了與原始遊戲相當的仿真質量。對於短軌跡,人類評估者在區分仿真片段和實際遊戲片段時,僅比隨機猜測略勝一籌。
圖像質量。 我們使用第2節中描述的教師強迫設置來測量LPIPS(Zhang 等人,2018)和PSNR。在該設置中,我們對初始狀態進行採樣,並根據地面實況的過去觀察軌跡預測單幀。在對5個不同級別的2048條隨機軌跡進行評估時,我們的模型實現了的PSNR值和的LPIPS值。PSNR值與質量設置為20-30的有損JPEG壓縮相似(Petric & Milinkovic,2018)。圖5展示了模型預測和相應地面實況樣本的示例。
視頻質量 我們使用第2節中描述的自回歸設置,按照真實軌跡所定義的動作序列對幀進行迭代採樣,同時將模型自身的過往預測作為條件。自回歸採樣時,預測軌跡和真實軌跡常常在幾步後發生偏離,這主要是由於不同軌跡的幀間積累了少量不同的運動速度。因此,如圖6所示,每幀的PSNR和LPIPS值分別逐漸降低和增加。預測的軌跡在內容和圖像質量方面仍與實際遊戲相似,但每幀指標在捕捉這一點的能力上有限(自動回歸生成的軌跡樣本見附錄A.1)。
因此,我們對512個隨機保留的軌跡計算FVD(Unterthiner等人,2019),測量預測軌跡分布與真實值軌跡分布之間的距離,仿真的長度為16幀(0.8秒)和32幀(1.6秒)。對於16幀,我們的模型獲得的FVD為。對於32幀,我們的模型獲得的FVD為。
人類評估。 作為評估仿真質量的另一項標準,我們向 10 名評測員提供了 130 個隨機短片段(長度為 1.6 秒和 3.2 秒),並排展示我們的仿真和真實遊戲。評測員的任務是識別真實遊戲(見附錄A.6中的圖14)。評測員在 1.6 秒和 3.2 秒的片段中,選擇真實遊戲而非仿真的比例分別為 58% 和 60%。
5.2 消融實驗
為了評估我們方法中不同組件的重要性,我們從評估數據集中採樣軌跡,並計算真實值與預測幀之間的 LPIPS 和 PSNR 指標。
5.2.1 上下文長度
我們通過訓練使用的模型來評估改變條件上下文中過去觀測值數量的影響(請注意,我們的方法使用)。這影響了歷史幀和動作的數量。我們在解碼器保持凍結的情況下訓練模型200,000步,並在5個級別的測試集軌跡上進行評估。結果見表1。正如預期的那樣,我們發現生成質量隨著上下文長度的增加而提高。有趣的是,我們觀察到,儘管最初(例如在1到2幀之間)提升較大,但很快就接近一個漸近線,進一步增加上下文長度只能帶來微小的質量提升。這有些令人驚訝,因為即使在我們使用的最大上下文長度下,模型也只能訪問略多於3秒的歷史。值得注意的是,我們觀察到大部分遊戲狀態會持續更長時間(見第7節)。雖然條件上下文長度是一個重要的限制,但表1提示我們可能需要改變模型的架構,以有效支持更長的上下文,並更好地選擇過去的幀作為條件,這將是我們未來的工作。
表 1:歷史幀數量。我們在來自 5 個級別的 8912 個測試集示例中分析了用作上下文的歷史幀數量。更多的幀通常會改善 PSNR 和 LPIPS 指標。
歷史上下文長度 | PSNR | LPIPS |
---|---|---|
64 | ||
32 | ||
16 | ||
8 | ||
4 | ||
2 | ||
1 |
5.2.2 噪聲增強
為了消除噪聲增強的影響,我們訓練了一個不添加噪聲的模型。我們對標準噪聲增強模型和不添加噪聲的模型(經過 200,000 步訓練後)進行自回歸評估,並計算在隨機保留的 512 條軌跡上預測幀與真實幀之間的 PSNR 和 LPIPS 指標。我們在圖 7 中報告了每個自回歸步驟的平均指標值,最多可達 64 幀。
在沒有噪聲增強的情況下,與真實值相比,LPIPS 距離迅速增加,而 PSNR 下降,這表明仿真結果與真實值的偏差加大。
5.2.3 代理執行
我們將代理生成的數據訓練與使用隨機策略生成的數據訓練進行比較。對於隨機策略,我們根據與觀測結果無關的均勻分類分布對動作進行採樣。我們通過對兩個模型及其解碼器進行
總體而言,我們觀察到在隨機軌跡上訓練模型的效果出奇地好,但受到隨機策略探索能力的限制。在比較單幀生成時,代理的效果稍好,PSNR 為 25.06,而隨機策略為 24.42。在比較 3 秒自回歸生成後的幀時,差距增大到 19.02 對 16.84。在手動操作模型時,我們發現某些區域對兩者都很容易,而某些區域對兩者都很困難,而在某些區域,代理的表現要好得多。基於此,我們根據它們與遊戲起始位置的距離手動將 456 個例子分為三組:易、中等和難。我們觀察到,在簡單和困難集上,代理的表現僅略優於隨機,而在中等集上,正如預期的那樣,代理的表現要好得多(見表 2)。請參見附錄 A.5 中的圖 13,了解人類單次遊戲的得分情況。
表 2:不同難度級別的表現。 我們比較了使用代理生成數據和隨機生成數據訓練的模型在簡單、中等和困難數據集上的表現。簡單和中等數據集各有 112 個樣本,困難數據集有 232 個樣本。在 3 秒後的單幀上計算每個軌跡的指標。
難度級別 | 數據生成策略 | PSNR | LPIPS |
---|---|---|---|
簡單 | 代理 | ||
隨機 | |||
中等 | 代理 | ||
隨機 | |||
困難 | 代理 | ||
隨機 |
6 相關工作
交互式三維仿真
模擬二維和三維環境的視覺和物理過程,並允許對其進行交互式探索,是計算機圖形學中一個廣泛發展的領域(Akenine-Möller等人,2018)。像虛幻和Unity這樣的遊戲引擎是可以處理場景幾何表示並根據用戶交互渲染圖像流的軟體。遊戲引擎負責跟蹤所有世界狀態,例如玩家的位置和移動、物體、角色動畫和光照。它還負責跟蹤遊戲邏輯,例如完成遊戲目標所獲得的分數。電影和電視製作使用的光線追蹤變體(Shirley和Morley,2008),對於實時應用來說過於緩慢且計算密集。相比之下,遊戲引擎必須保持非常高的幀率(通常為30-60 FPS),因此依賴於高度優化的多邊形光柵化,並且通常由GPU加速。諸如陰影、粒子和光照等物理效果通常使用高效的啟發式方法來實現,而不是進行精確的物理仿真。
神經三維仿真
重建三維表示的神經方法在過去幾年中取得了重大進展。NeRFs(Mildenhall 等人,2020)使用深度神經網絡對輻射場進行參數化,該網絡針對從不同相機姿態拍攝的一組圖像的特定場景進行了專門優化。訓練完成後,可通過體積渲染方法對場景的新視角進行採樣。Gaussian Splatting(Kerbl 等人,2023)方法建立在 NeRFs 的基礎上,但使用三維高斯和改進的光柵化方法來表示場景,從而實現更快的訓練和渲染速度。儘管這些方法展示了令人印象深刻的重建結果和實時交互性,但通常僅限於靜態場景。
視頻擴散模型
Diffusion models achieved state-of-the-art results in text-to-image generation (Saharia et al., 2022; Rombach et al., 2022; Ramesh et al., 2022; Podell et al., 2023), a line of work that has also been applied for text-to-video generation tasks (Ho et al., 2022; Blattmann et al., 2023b; a; Gupta et al., 2023; Girdhar et al., 2023; Bar-Tal et al., 2024). Despite impressive advancements in realism, text adherence, and temporal consistency, video diffusion models remain too slow for real-time applications. Our work extends this line of work and adapts it for real-time generation conditioned autoregressively on a history of past observations and actions.
Game Simulation and World Models
Several works attempted to train models for game simulation with actions inputs. Yang et al. (2023) build a diverse dataset of real-world and simulated videos and train a diffusion model to predict a continuation video given a previous video segment and a textual description of an action. Menapace et al. (2021) and Bruce et al. (2024) focus on unsupervised learning of actions from videos. Menapace et al. (2024) converts textual prompts to game states, which are later converted to a 3D representation using NeRF. Unlike these works, we focus on interactive playable real-time simulation, and demonstrate robustness over long-horizon trajectories. We leverage an RL agent to explore the game environment and create rollouts of observations and interactions for training our interactive game model. Another line of work explored learning a predictive model of the environment and using it for training an RL agent. Ha & Schmidhuber (2018) train a Variational Auto-Encoder (Kingma & Welling, 2014) to encode game frames into a latent vector, and then use an RNN to mimic the VizDoom game environment, training on random rollouts from a random policy (i.e., selecting an action at random). Then a controller policy is learned by playing within the 「hallucinated」 environment. Hafner et al. (2020) demonstrate that an RL agent can be trained entirely on episodes generated by a learned world model in latent space. Also close to our work is Kim et al. (2020), which uses an LSTM architecture for modeling the world state, coupled with a convolutional decoder for producing output frames and jointly trained under an adversarial objective. While this approach seems to produce reasonable results for simple games like PacMan, it struggles with simulating the complex environment of VizDoom and produces blurry samples. In contrast, GameNGen is able to generate samples comparable to those of the original game; see Figure 2. Finally, concurrently with our work, Alonso et al. (2024) train a diffusion world model to predict the next observation given observation history, and iteratively train the world model and an RL model on Atari games.
DOOM
When DOOM was released in 1993, it revolutionized the gaming industry. Introducing groundbreaking 3D graphics technology, it became a cornerstone of the first-person shooter genre, influencing countless other games. DOOM was studied by numerous research works. It provides an open-source implementation and a native resolution that is low enough for small-sized models to simulate while being complex enough to be a challenging test case. Finally, the authors have spent countless youth hours with the game. It was a trivial choice to use it in this work.
7 Discussion
Summary. We introduced GameNGen and demonstrated that high-quality real-time gameplay at 20 frames per second is possible on a neural model. We also provided a recipe for converting an interactive piece of software such as a computer game into a neural model.
Limitations. GameNGen suffers from a limited amount of memory. The model only has access to a little over 3 seconds of history, so it’s remarkable that much of the game logic is persisted for drastically longer time horizons. While some of the game state is persisted through screen pixels (e.g., ammo and health tallies, available weapons, etc.), the model likely learns strong heuristics that allow meaningful generalizations. For example, from the rendered view, the model learns to infer the player’s location, and from the ammo and health tallies, the model might infer whether the player has already been through an area and defeated the enemies there. That said, it’s easy to create situations where this context length is not enough. Continuing to increase the context size with our existing architecture yields only marginal benefits (Section 5.2.1), and the model’s short context length remains an important limitation. The second important limitation is the remaining differences between the agent’s behavior and those of human players. For example, our agent, even at the end of training, still does not explore all of the game’s locations and interactions, leading to erroneous behavior in those cases.
Future Work. We demonstrate GameNGen on the classic game DOOM. It would be interesting to test it on other games or more generally on other interactive software systems. We note that nothing in our technique is DOOM specific except for the reward function for the RL-agent. We plan on addressing that in future work. While GameNGen manages to maintain game state accurately, it isn’t perfect, as per the discussion above. A more sophisticated architecture might be needed to mitigate these issues. GameNGen currently has a limited capability to leverage more than a minimal amount of memory. Experimenting with further expanding the memory effectively could be critical for more complex games/software. GameNGen runs at 20 or 50 FPS22Faster than the original game DOOM ran on some of the authors』 80386 machines at the time! on a TPUv5. It would be interesting to experiment with further optimization techniques to get it to run at higher frame rates and on consumer hardware.
Towards a New Paradigm for Interactive Video Games. Today, video games are programmed by humans. GameNGen is a proof-of-concept for one part of a new paradigm where games are weights of a neural model, not lines of code. GameNGen shows that an architecture and model weights exist such that a neural model can effectively run a complex game (DOOM) interactively on existing hardware. While many important questions remain, we are hopeful that this paradigm could have important benefits. For example, the development process for video games under this new paradigm might be less costly and more accessible, whereby games could be developed and edited via textual descriptions or example images. A small part of this vision, namely creating modifications or novel behaviors for existing games, might be achievable in the shorter term. For example, we might be able to convert a set of frames into a new playable level or create a new character just based on example images, without having to author code. Other advantages of this new paradigm include strong guarantees on frame rates and memory footprints. We have not experimented with these directions yet and much more work is required here, but we are excited to try! Hopefully, this small step will someday contribute to a meaningful improvement in people’s experience with video games, or maybe even more generally, in day-to-day interactions with interactive software systems.
Acknowledgements
We’d like to extend a huge thank you to Eyal Segalis, Eyal Molad, Matan Kalman, Nataniel Ruiz, Amir Hertz, Matan Cohen, Yossi Matias, Yael Pritch, Danny Lumen, Valerie Nygaard, the Theta Labs and Google Research teams, and our families for insightful feedback, ideas, suggestions, and support.
Contribution
- Dani Valevski: Developed much of the codebase, tuned parameters and details across the system, added autoencoder fine-tuning, agent training, and distillation.
- Yaniv Leviathan: Proposed project, method, and architecture, developed the initial implementation, key contributor to implementation and writing.
- Moab Arar: Led auto-regressive stabilization with noise-augmentation, many of the ablations, and created the dataset of human-play data.
- Shlomi Fruchter: Proposed project, method, and architecture. Project leadership, initial implementation using DOOM, main manuscript writing, evaluation metrics, random policy data pipeline.
Correspondence to shlomif@google.com
and leviathan@google.com
.
References
- Akenine-Möller et al. (2018) Tomas Akenine-Möller, Eric Haines, and Naty Hoffman. Real-Time Rendering, Fourth Edition. A. K. Peters, Ltd., USA, 4th edition, 2018. ISBN 0134997832.
- Alonso et al. (2024) Eloi Alonso, Adam Jelley, Vincent Micheli, Anssi Kanervisto, Amos Storkey, Tim Pearce, and François Fleuret. Diffusion for world modeling: Visual details matter in Atari, 2024.
- Bar-Tal et al. (2024) Omer Bar-Tal, Hila Chefer, Omer Tov, Charles Herrmann, Roni Paiss, Shiran Zada, Ariel Ephrat, Junhwa Hur, Guanghui Liu, Amit Raj, Yuanzhen Li, Michael Rubinstein, Tomer Michaeli, Oliver Wang, Deqing Sun, Tali Dekel, and Inbar Mosseri. Lumiere: A space-time diffusion model for video generation, 2024. URL: [1](https://arxiv.org/abs/2401.12945).
- Blattmann et al. (2023a) Andreas Blattmann, Tim Dockhorn, Sumith Kulal, Daniel Mendelevitch, Maciej Kilian, Dominik Lorenz, Yam Levi, Zion English, Vikram Voleti, Adam Letts, Varun Jampani, and Robin Rombach. Stable video diffusion: Scaling latent video diffusion models to large datasets, 2023a. URL: [2](https://arxiv.org/abs/2311.15127).
- Blattmann et al. (2023b) Andreas Blattmann, Robin Rombach, Huan Ling, Tim Dockhorn, Seung Wook Kim, Sanja Fidler, and Karsten Kreis. Align your latents: High-resolution video synthesis with latent diffusion models, 2023b. URL: [3](https://arxiv.org/abs/2304.08818).
- Brooks et al. (2024) Tim Brooks, Bill Peebles, Connor Holmes, Will DePue, Yufei Guo, Li Jing, David Schnurr, Joe Taylor, Troy Luhman, Eric Luhman, Clarence Ng, Ricky Wang, and Aditya Ramesh. Video generation models as world simulators, 2024. URL: [4](https://openai.com/research/video-generation-models-as-world-simulators).
- Bruce et al. (2024) Jake Bruce, Michael Dennis, Ashley Edwards, Jack Parker-Holder, Yuge Shi, Edward Hughes, Matthew Lai, Aditi Mavalankar, Richie Steigerwald, Chris Apps, Yusuf Aytar, Sarah Bechtle, Feryal Behbahani, Stephanie Chan, Nicolas Heess, Lucy Gonzalez, Simon Osindero, Sherjil Ozair, Scott Reed, Jingwei Zhang, Konrad Zolna, Jeff Clune, Nando de Freitas, Satinder Singh, and Tim Rocktäschel. Genie: Generative interactive environments, 2024. URL: [5](https://arxiv.org/abs/2402.15391).
- Girdhar et al. (2023) Rohit Girdhar, Mannat Singh, Andrew Brown, Quentin Duval, Samaneh Azadi, Sai Saketh Rambhatla, Akbar Shah, Xi Yin, Devi Parikh, and Ishan Misra. Emu video: Factorizing text-to-video generation by explicit image conditioning, 2023. URL: [6](https://arxiv.org/abs/2311.10709).
- Gupta et al. (2023) Agrim Gupta, Lijun Yu, Kihyuk Sohn, Xiuye Gu, Meera Hahn, Li Fei-Fei, Irfan Essa, Lu Jiang, and José Lezama. Photorealistic video generation with diffusion models, 2023. URL: [7](https://arxiv.org/abs/2312.06662).
- Ha & Schmidhuber (2018) David Ha and Jürgen Schmidhuber. World models, 2018.
- Hafner et al. (2020) Danijar Hafner, Timothy Lillicrap, Jimmy Ba, and Mohammad Norouzi. Dream to control: Learning behaviors by latent imagination, 2020. URL: [8](https://arxiv.org/abs/1912.01603).
- Ho & Salimans (2022) Jonathan Ho and Tim Salimans. Classifier-free diffusion guidance, 2022. URL: [9](https://arxiv.org/abs/2207.12598).
- Ho et al. (2021) Jonathan Ho, Chitwan Saharia, William Chan, David J Fleet, Mohammad Norouzi, and Tim Salimans. Cascaded diffusion models for high fidelity image generation. arXiv preprint arXiv:2106.15282, 2021.
- Ho et al. (2022) Jonathan Ho, William Chan, Chitwan Saharia, Jay Whang, Ruiqi Gao, Alexey A. Gritsenko, Diederik P. Kingma, Ben Poole, Mohammad Norouzi, David J. Fleet, and Tim Salimans. Imagen video: High definition video generation with diffusion models. ArXiv, abs/2210.02303, 2022. URL: [10](https://api.semanticscholar.org/CorpusID:252715883).
- Kerbl et al. (2023) Bernhard Kerbl, Georgios Kopanas, Thomas Leimkühler, and George Drettakis. 3d gaussian splatting for real-time radiance field rendering. ACM Transactions on Graphics, 42(4), July 2023. URL: [11](https://repo-sam.inria.fr/fungraph/3d-gaussian-splatting/).
- Kim et al. (2020) Seung Wook Kim, Yuhao Zhou, Jonah Philion, Antonio Torralba, and Sanja Fidler. Learning to Simulate Dynamic Environments with GameGAN. In IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Jun. 2020.
- Kingma & Welling (2014) Diederik P. Kingma and Max Welling. Auto-Encoding Variational Bayes. In 2nd International Conference on Learning Representations, ICLR 2014, Banff, AB, Canada, April 14-16, 2014, Conference Track Proceedings, 2014.
- Menapace et al. (2021) Willi Menapace, Stéphane Lathuilière, Sergey Tulyakov, Aliaksandr Siarohin, and Elisa Ricci. Playable video generation, 2021. URL: [12](https://arxiv.org/abs/2101.12195).
- Menapace et al. (2024) Willi Menapace, Aliaksandr Siarohin, Stéphane Lathuilière, Panos Achlioptas, Vladislav Golyanik, Sergey Tulyakov, and Elisa Ricci. Promptable game models: Text-guided game simulation via masked diffusion models. ACM Transactions on Graphics, 43(2):1–16, January 2024. doi: [10.1145/3635705](http://dx.doi.org/10.1145/3635705).
- Mildenhall et al. (2020) Ben Mildenhall, Pratul P. Srinivasan, Matthew Tancik, Jonathan T. Barron, Ravi Ramamoorthi, and Ren Ng. Nerf: Representing scenes as neural radiance fields for view synthesis. In ECCV, 2020.
- Mnih et al. (2015) Volodymyr Mnih, Koray Kavukcuoglu, David Silver, Andrei A. Rusu, Joel Veness, Marc G. Bellemare, Alex Graves, Martin A. Riedmiller, Andreas Kirkeby Fidjeland, Georg Ostrovski, Stig Petersen, Charlie Beattie, Amir Sadik, Ioannis Antonoglou, Helen King, Dharshan Kumaran, Daan Wierstra, Shane Legg, and Demis Hassabis. Human-level control through deep reinforcement learning. Nature, 518:529–533, 2015. URL: [13](https://api.semanticscholar.org/CorpusID:205242740).
- Petric & Milinkovic (2018) Danko Petric and Marija Milinkovic. Comparison between cs and jpeg in terms of image compression, 2018. URL: [14](https://arxiv.org/abs/1802.05114).
- Podell et al. (2023) Dustin Podell, Zion English, Kyle Lacey, Andreas Blattmann, Tim Dockhorn, Jonas Müller, Joe Penna, and Robin Rombach. Sdxl: Improving latent diffusion models for high-resolution image synthesis. arXiv preprint arXiv:2307.01952, 2023.
- Raffin et al. (2021) Antonin Raffin, Ashley Hill, Adam Gleave, Anssi Kanervisto, Maximilian Ernestus, and Noah Dormann. Stable-baselines3: Reliable reinforcement learning implementations. Journal of Machine Learning Research, 22(268):1–8, 2021. URL: [15](http://jmlr.org/papers/v22/20-1364.html).
- Ramesh et al. (2022) Aditya Ramesh, Prafulla Dhariwal, Alex Nichol, Casey Chu, and Mark Chen. Hierarchical text-conditional image generation with clip latents. arXiv preprint arXiv:2204.06125, 2022.
- Rombach et al. (2022) Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, and Björn Ommer. High-resolution image synthesis with latent diffusion models. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, pp. 10684–10695, 2022.
- Saharia et al. (2022) Chitwan Saharia, William Chan, Saurabh Saxena, Lala Li, Jay Whang, Emily L Denton, Kamyar Ghasemipour, Raphael Gontijo Lopes, Burcu Karagol Ayan, Tim Salimans, et al. Photorealistic text-to-image diffusion models with deep language understanding. Advances in Neural Information Processing Systems, 35:36479–36494, 2022.
- Salimans & Ho (2022a) Tim Salimans and Jonathan Ho. Progressive distillation for fast sampling of diffusion models. In The Tenth International Conference on Learning Representations, ICLR 2022, Virtual Event, April 25-29, 2022. OpenReview.net, 2022a. URL: [16](https://openreview.net/forum?id=TIdIXIpzhoI).
- Salimans & Ho (2022b) Tim Salimans and Jonathan Ho. Progressive distillation for fast sampling of diffusion models, 2022b. URL: [17](https://arxiv.org/abs/2202.00512).
- Schulman et al. (2017) John Schulman, Filip Wolski, Prafulla Dhariwal, Alec Radford, and Oleg Klimov. Proximal policy optimization algorithms. CoRR, abs/1707.06347, 2017. URL: [18](http://arxiv.org/abs/1707.06347).
- Shazeer & Stern (2018) Noam Shazeer and Mitchell Stern. Adafactor: Adaptive learning rates with sublinear memory cost. CoRR, abs/1804.04235, 2018. URL: [19](http://arxiv.org/abs/1804.04235).
- Shirley & Morley (2008) P. Shirley and R.K. Morley. Realistic Ray Tracing, Second Edition. Taylor & Francis, 2008. ISBN 9781568814612. URL: [20](https://books.google.ch/books?id=knpN6mnhJ8QC).
- Song et al. (2020) Jiaming Song, Chenlin Meng, and Stefano Ermon. Denoising diffusion implicit models. arXiv:2010.02502, October 2020. URL: [21](https://arxiv.org/abs/2010.02502).
- Song et al. (2022) Jiaming Song, Chenlin Meng, and Stefano Ermon. Denoising diffusion implicit models, 2022. URL: [22](https://arxiv.org/abs/2010.02502).
- Unterthiner et al. (2019) Thomas Unterthiner, Sjoerd van Steenkiste, Karol Kurach, Raphaël Marinier, Marcin Michalski, and Sylvain Gelly. FVD: A new metric for video generation. In Deep Generative Models for Highly Structured Data, ICLR 2019 Workshop, New Orleans, Louisiana, United States, May 6, 2019, 2019.
- Wang et al. (2023) Zhengyi Wang, Cheng Lu, Yikai Wang, Fan Bao, Chongxuan Li, Hang Su, and Jun Zhu. Prolificdreamer: High-fidelity and diverse text-to-3d generation with variational score distillation. arXiv preprint arXiv:2305.16213, 2023.
- Wydmuch et al. (2019) Marek Wydmuch, Michał Kempka, and Wojciech Jaśkowski. ViZDoom Competitions: Playing Doom from Pixels. IEEE Transactions on Games, 11(3):248–259, 2019. doi: [10.1109/TG.2018.2877047](http://dx.doi.org/10.1109/TG.2018.2877047).
- Yang et al. (2023) Mengjiao Yang, Yilun Du, Kamyar Ghasemipour, Jonathan Tompson, Dale Schuurmans, and Pieter Abbeel. Learning interactive real-world simulators. arXiv preprint arXiv:2310.06114, 2023.
- Yin et al. (2024) Tianwei Yin, Michaël Gharbi, Richard Zhang, Eli Shechtman, Frédo Durand, William T Freeman, and Taesung Park. One-step diffusion with distribution matching distillation. In CVPR, 2024.
- Zhang et al. (2018) Richard Zhang, Phillip Isola, Alexei A. Efros, Eli Shechtman, and Oliver Wang. The unreasonable effectiveness of deep features as a perceptual metric. In CVPR, 2018.
Appendix A Appendix
A.1 Samples
Figs. [8](https://arxiv.org/html/2408.14837v1#A1.F8), [9](https://arxiv.org/html/2408.14837v1#A1.F9), [10](https://arxiv.org/html/2408.14837v1#A1.F10), [11](https://arxiv.org/html/2408.14837v1#A1.F11) provide selected samples from GameNGen.