Search

Search papers and lessons

Diffusion Models Are Real-Time Game Engines (GameNGen)

Dani Valevski, Yaniv Leviathan, Moab Arar et al. · 2024

GameNGen runs DOOM as a diffusion model at 20 frames per second on one TPU, predicting each frame from past frames and player actions, and stays stable over multi-minute play.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Architectures
  • Generative models
  • Neural network basics
  • Linear algebra
  • Sign in to see your progress

TL;DR

GameNGen is a neural model that plays the 1993 game DOOM by predicting one frame at a time. It is a Stable Diffusion model, conditioned on the last few frames and the player's key presses, and it runs at 20 frames per second on a single TPU. The paper reports that it stays stable over multi-minute sessions.

The paper's central claim is that a game loop can be a neural network instead of hand-written code.

Where you'll see it: research on neural game engines and on interactive world models, and as a demonstration that diffusion models can be fast enough for real-time use.

The problem

A game engine runs a loop: read the player's input, update the game state, then render the state to pixels. Engines are hand-written. Making a game means writing its rules, physics and graphics. A neural model could in principle learn all of this from recordings, but two things make it hard.

The first is speed. A player needs a new frame every fraction of a second. Diffusion models, the strongest image generators of the time, usually need dozens of denoising steps per image, and each step is a full network pass. Generating a frame that way is too slow for play.

The second is drift. A model trained on real frames sees real history during training. When it runs on its own output, small errors accumulate and the picture slides away from anything plausible. The paper names this gap between training and sampling Exposure Bias.

The paper asks whether a diffusion model can do both at once: be fast enough to play in real time and stable over long sessions. It answers yes for one complex game, DOOM, on existing hardware.

Key idea

Three choices make the approach work.

  1. Get training data from an agent, not from humans at scale. A reinforcement learning agent plays DOOM and its sessions are recorded. The recordings include the early random play, so the data covers a range of skill and situations.
  2. Condition the model on the history and the action. The past frames are encoded and concatenated with the noisy frame being denoised. Each key press becomes one learned token that the model attends to.
  3. Make the model robust to its own mistakes. During training the past frames are corrupted with noise at a random level, and the model is told that level. This teaches it to correct errors in its context instead of copying them.

With these in place, the paper reports that only 4 denoising steps are needed. Fewer steps mean faster frames, and the paper finds the quality is not hurt.

The method

The method has two training phases and one inference loop. The paper's Figure 3 shows the architecture.

Data collection by agent play

The agent is trained with PPO on a simple convolutional feature network, using Stable Baselines 3. Its reward is the only environment-specific part of the method. The goal is not a high game score. The paper wants data that resembles human play and covers many situations. The agent's trajectories are recorded throughout training, including its earliest random play. The paper trains the generative model on 70M examples drawn from those recordings.

Training the diffusion model

The base model is Stable Diffusion v1.4, a Latent Diffusion Model. It works on latents from a pretrained autoencoder, not on pixels. The paper removes the text conditioning. Actions are handled by learning an embedding for each key press, which replaces the text cross-attention. Past frames are encoded by the autoencoder and concatenated along the channel dimension with the noisy latent.

The training objective is the diffusion loss with velocity parameterisation. The network vθ′v_{\theta'} predicts the velocity v=αˉt ϵ−1−αˉt x0v = \sqrt{\bar\alpha_t}\,\epsilon - \sqrt{1-\bar\alpha_t}\,x_0 from the noisy latent xt=αˉt x0+1−αˉt ϵx_t = \sqrt{\bar\alpha_t}\,x_0 + \sqrt{1-\bar\alpha_t}\,\epsilon, the time step tt, the past frame latents and the past action embeddings. Here ϵ\epsilon is standard Gaussian noise, αˉt\bar\alpha_t is a noise schedule that the paper says is linear, and x0x_0 is the latent of the next frame. The loss is the squared error between the predicted and true velocity, averaged over steps, noise and training examples. The network is a U-Net inside the diffusion model, see Diffusion Model.

Noise augmentation

The paper's fix for drift is to corrupt the context frames during training. A noise level α\alpha is drawn uniformly up to a maximum of 0.7, discretised into 10 buckets, and each bucket gets a learned embedding that the network receives. The noise is added to the context latents only. Without this step, the paper's Figure 4 shows quality degrading after roughly 20 to 30 steps on a simple trajectory. With it, the model recovers. The paper reports that even zero added noise at inference gives much better results than no augmentation at training.

Decoder fine-tuning

The pretrained autoencoder compresses 8x8 pixel patches into 4 latent channels. The paper finds this introduces artifacts, especially in the heads-up display at the bottom of the screen. It fine-tunes only the decoder, using an MSE loss against the target pixels. This happens separately from the U-Net training. Auto-regression still runs on latents, so the fine-tuning does not change the model's own predictions.

Inference

At play time the player's action is embedded, the previous frames are encoded, and the model denoises the next frame's latent with DDIM sampling (see DDIM Sampler). The paper uses classifier-free guidance only on the past-observation condition, with a small weight of 1.5, because larger weights create artifacts under auto-regression. The past-action condition is not guided because it did not help. The paper's Table 1 shows the number of denoising steps versus quality, discussed below.

Example
Why four steps is the number that matters

The paper runs a single denoiser step and the autoencoder on one TPU-v5 in 10 ms each.

  1. One denoiser step plus one autoencoder pass is 10+10=2010 + 10 = 20 ms, which is 50 frames per second in the best case.
  2. Four denoiser steps cost 4×10=404 \times 10 = 40 ms for the U-Net, and 40+10=5040 + 10 = 50 ms in total including the autoencoder.
  3. A frame every 50 ms is 1000/50=201000 / 50 = 20 frames per second, which matches the paper's reported rate.
  4. Table 1 gives PSNR 25.47 for one step and 32.58 for four steps, with LPIPS 0.255 and 0.198. One step loses a lot. Four steps already gives the best value in the table, 32.58, against 32.55 at eight.
  5. More steps do not help: 8 steps score 32.55, and the paper reports no degradation in simulation quality from using 4 steps instead of 20 or more. So 4 steps buys the quality of a much slower sampler at a 50 ms frame budget, which is the basis of the real-time claim.

Interpretation: the real-time result comes from the step count, not from a smaller model. The paper also tries distillation to reach one step, which it says gives about 50 FPS, but at some cost to quality, so it keeps the four-step model.

Results

Image quality. On a holdout of 2048 trajectories from five levels, next-frame prediction with ground-truth past frames gives PSNR 29.43 and LPIPS 0.249. The paper compares the PSNR to lossy JPEG at quality 20 to 30. The abstract reports the same PSNR, rounded to 29.4. Table 1 uses a different evaluation, 2048 frames of 35 FPS data, and reports PSNR near 32.6 at four steps. The two sets of numbers come from different setups and should not be compared directly.

Video quality. When the model runs on its own predictions, the paper uses FVD, computed over 512 holdout trajectories. It reports FVD 114.02 for 16-frame (0.8 second) simulations and 186.23 for 32-frame (1.6 second) simulations. Per-frame PSNR drifts down over a long auto-regressive run, which the paper notes is partly due to small movement-speed differences that accumulate. It argues per-frame metrics do not capture that the simulated trajectory still looks like the game.

Human raters. Ten raters were shown 130 short clips of the simulation and the real game side by side. For 1.6-second clips they picked the real game 58% of the time, and for 3.2-second clips 60%. For 3-second clips taken after 5 to 10 minutes of auto-regressive play, from 150 comparisons, raters picked the real game 50% of the time, which is chance. The paper's point is that short clips can be told apart, but long auto-regressive ones were not separable in its test.

Ablations.

  • Context length (Table 2): with 64 history frames PSNR is 22.36 and LPIPS 0.295. With 2 frames it is 22.03 and 0.304. The jump from 1 frame (PSNR 20.94) to 2 is large, but beyond that the gains are small. This ablation used a different evaluation set of 8912 examples.
  • Noise augmentation (Figure 7): without it, LPIPS rises quickly over auto-regressive steps and PSNR drops. With it, the model stays close to the ground truth.
  • Agent data (Table 3, one frame after 3 seconds of auto-regressive generation, on 456 manually split examples): on the hard split, the agent-trained model gets PSNR 17.51 and LPIPS 0.60, against PSNR 15.39 and LPIPS 0.61 for random-policy data. On the medium split the gap is larger (20.21 against 16.50). On the easy split it is small (20.94 against 20.20).

Why it mattered

The paper's own framing is that a game could become a set of neural weights rather than a program, and that games might be developed through text or example images. It calls this a proof of concept for one part of that idea. It also names the limits: the model sees only a little over 3 seconds of history, and some game state is recovered from the screen, such as ammo and health tallies, while the rest is inferred heuristically.

The paper states that nothing in the technique is DOOM-specific beyond the reward function, and that the authors would like to test other games. The paper's future work also mentions modifying existing games as a nearer-term possibility. These are the paper's claims, not an account of what followed.

Reading guide

  1. Abstract and Introduction: the claim of 20 FPS on one TPU and multi-minute stability, and the two-phase training. Needs World Model.
  2. Section 2, interactive world simulation: the teacher-forcing objective and why the model is trained only on ground-truth context. Needs Teacher Forcing.
  3. Section 3.1, data collection: the reward and the agent. Needs Reinforcement Learning and Proximal Policy Optimization (PPO).
  4. Section 3.2, the diffusion training: the velocity loss and the action embedding. Needs Latent Diffusion Model, Diffusion Model and U-Net.
  5. Section 3.2.1, noise augmentation: why context is corrupted during training. Needs Exposure Bias.
  6. Section 3.2.2, decoder fine-tuning: why the autoencoder is tuned separately. Needs Variational Autoencoder.
  7. Section 3.3, inference and the step count: DDIM sampling and classifier-free guidance. Needs DDIM Sampler and Classifier-Free Guidance.
  8. Section 5, results and ablations: the metrics, the human study, and the tables. Needs Exposure Bias for the drift story.

Check yourself

QuestionRecall: what problem does noise augmentation solve, and how?Show answer

When a model is trained on real past frames but runs on its own predictions, errors compound. Noise augmentation adds a random amount of noise to the context frames during training and tells the model the noise level, so it learns to correct imperfect context. The paper says this is critical for preserving quality over time.

QuestionComputation: the paper's denoiser step takes 10 ms and the autoencoder takes 10 ms. What is the frame rate with 4 denoiser steps?Show answer

Total time is 4×10+10=504 \times 10 + 10 = 50 ms, so the rate is 1000/50=201000 / 50 = 20 frames per second. This matches the paper's reported 20 FPS.

QuestionWhy: the paper says larger classifier-free guidance weights create artifacts. Why would that matter more under auto-regressive generation than in a single image?Show answer

Each generated frame becomes context for the next. An artifact introduced by strong guidance is fed back in and can grow over the sequence. A single image has no such feedback, so the same artifact stays a single flaw. This is why the paper uses a small weight of 1.5.

QuestionApplied: a team wants a neural game engine for a new game. They see PSNR 29.4 in the abstract and PSNR near 32.6 in Table 1. Which should they quote as the quality of the model, and why?Show answer

Neither should be quoted alone. The paper uses different evaluation setups: the abstract figure is next-frame prediction with ground-truth context on a 2048-trajectory holdout, and the Table 1 figure is a different sampling-step study on 35 FPS data. The team should compare on one shared setup and also report long auto-regressive results such as FVD and the human study, since per-frame PSNR does not capture drift.

Sources

Read the full paper

Dani Valevski, Yaniv Leviathan, Moab Arar et al., 2024. arXiv:2408.14837