Files
cs249r_book/site/games/allreduce.qmd
Vijay Janapa Reddi 9d4732f4ff fix(games): module-relative imports across all 13 remaining games
The same path-prefix bug that broke Lander on dev preview affected the other
13 games too. Fixing all of them in one batch so the entire catalog works
on /cs249r_book_dev/, mlsysbook.ai/, and localhost equally.

Pattern applied:
  .qmd  include-in-header script:
    import "/assets/games/X.mjs"  →  import "../assets/games/X.mjs"
  .mjs  ES imports:
    from "/assets/games/runtime.mjs"          →  from "./runtime.mjs"
    from "/assets/games/vendor/pixi.min.mjs"  →  from "./vendor/pixi.min.mjs"

Files touched (10 .mjs + 13 .qmd):
  .mjs: allreduce, batch, cluster, kvcache, moe, oom, pipeline, prune,
        quantization, topology
  .qmd: allreduce, batch, checkpoint, cluster, kvcache, loader, moe, oom,
        pipeline, prune, quantization, roofline, topology
  (checkpoint, loader, roofline .mjs already used 'import * as runtime from
   ./runtime.mjs' — only their qmd files needed updating)

Verification: all 14 games rendered locally (quarto render games/), served
via python3 -m http.server, swept with Playwright headless Chromium.
Result: 14/14 pass — canvas mounted, MLSP runtime ready, game registered,
no JS errors, no 4xx network requests. Visual screenshots confirm each
game's HUD/title/content paints correctly.
2026-04-25 19:16:00 -04:00

73 lines
3.1 KiB
Plaintext

---
title: "All-Reduce Rhythm"
subtitle: "Keep the gradients flowing in a perfect ring."
description: "A browser mini-game from MLSysBook Playground. Synchronize your gradient communication across GPUs without pipeline stalls."
page-layout: article
format:
html:
include-in-header:
- text: |
<link rel="stylesheet" href="/assets/games/common.css">
<script type="module">
import "../assets/games/runtime.mjs";
import "../assets/games/allreduce.mjs";
</script>
---
```{=html}
<div class="mlsp-game-container" role="region" aria-label="All-Reduce Rhythm mini-game">
<canvas id="mlsp-canvas" class="mlsp-game-canvas" width="680" height="460"></canvas>
<div class="mlsp-game-hud">
<span class="mlsp-score">Combo <span id="mlsp-combo">0</span> · Score <span id="mlsp-score">0</span></span>
<span>Click GPUs or <kbd>1</kbd>-<kbd>4</kbd> on the beat · <kbd>R</kbd> retry</span>
<button type="button" class="mlsp-fullscreen-btn" onclick="this.closest('.mlsp-game-container').requestFullscreen()" title="Full Screen" aria-label="Full Screen">⛶</button>
</div>
</div>
<div id="mlsp-aha-slot"></div>
<script>
(function bootAllreduce(){
function tryBoot() {
if (!window.MLSP || !MLSP.games || !MLSP.games.allreduce) return setTimeout(tryBoot, 30);
var canvas = document.getElementById("mlsp-canvas");
var $combo = document.getElementById("mlsp-combo");
var $score = document.getElementById("mlsp-score");
var ahaSlot = document.getElementById("mlsp-aha-slot");
var pendingResult = null;
var resolvedApi = null;
Promise.resolve(MLSP.games.allreduce(canvas, {
onScoreChange: function(s) {
$combo.textContent = s.combo;
$score.textContent = s.score;
},
onGameOver: function(result) {
if (resolvedApi) attachAha(resolvedApi, result);
else pendingResult = result;
},
onRetry: function() { window.location.reload(); }
})).then(function(api) {
resolvedApi = api;
if (pendingResult) attachAha(api, pendingResult);
});
function attachAha(api, result) {
MLSP.showAhaCard(ahaSlot, api.ahaLabel, api.ahaText, api.ahaLink);
}
}
tryBoot();
})();
</script>
```
## How to play
GPUs are arranged in a ring. A visual metronome expands to hit the outer wire every second. Press <kbd>1</kbd>, <kbd>2</kbd>, <kbd>3</kbd>, or <kbd>4</kbd> exactly on the beat to fire a gradient chunk to the next GPU clockwise. Perfect timing keeps the pipeline full and increases your combo. Miss the beat, and the GPUs fall out of sync causing collisions!
## The Systems Concept
Ring All-Reduce synchronizes gradients across GPUs by passing chunks in a circle. In an ideal setup, each step is perfectly synchronous, ensuring maximum bandwidth utilization. When GPUs are delayed or fall out of sync (stragglers), collisions and pipeline stalls occur, cratering your distributed training throughput.
---
*Part of [MLSysBook Playground](/games/). Found a bug? [Report an issue](https://github.com/harvard-edge/cs249r_book/issues/new?labels=bug&title=Bug+in+Game).*