https://github.com/19pine-ai/latent-bridge-games
A learned continuous slowβfast latent channel for real-time game agents: frozen MiniCPM-o 4.5 (fast) + Qwen3-VL-8B-Thinking (slow), 33M-param bridge. The latent helps iff slow reasoning helps (T>F). Paper: arXiv:2606.24470
https://github.com/19pine-ai/latent-bridge-games
agents arcade-learning-environment atari deep-learning fast-slow game-ai llava llm machine-learning multimodal pytorch real-time reasoning reinforcement-learning vlm
Last synced: 16 days ago
JSON representation
A learned continuous slowβfast latent channel for real-time game agents: frozen MiniCPM-o 4.5 (fast) + Qwen3-VL-8B-Thinking (slow), 33M-param bridge. The latent helps iff slow reasoning helps (T>F). Paper: arXiv:2606.24470
- Host: GitHub
- URL: https://github.com/19pine-ai/latent-bridge-games
- Owner: 19PINE-AI
- License: mit
- Created: 2026-05-15T08:57:47.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-06-29T09:32:31.000Z (about 1 month ago)
- Last Synced: 2026-06-29T11:17:25.443Z (about 1 month ago)
- Topics: agents, arcade-learning-environment, atari, deep-learning, fast-slow, game-ai, llava, llm, machine-learning, multimodal, pytorch, real-time, reasoning, reinforcement-learning, vlm
- Language: Python
- Homepage: https://01.me/research/latent-bridge-games
- Size: 76.6 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Citation: CITATION.cff
Awesome Lists containing this project
README
# The Latent Bridge: A Continuous SlowβFast Channel for Real-Time Game Agents
> π¬ **Deliverable: a working demo.** The fast/slow architecture is the means; the
> deliverable is a real-time agent you can watch play and replay. Recorded MP4 + live
> web playback + interactive website are the primary outputs; the experiments in
> [`docs/06_results.md`](docs/06_results.md) ground the demo's claims (roadmap:
> [`docs/07_next_steps.md`](docs/07_next_steps.md)).
>
> **Paper:** [arXiv:2606.24470](https://arxiv.org/abs/2606.24470) Β· **Website:**
We want agents that operate a computer like a person β read the screen, issue inputs, close
the loop β and **real-time games are the hardest case**: the agent must act every few tens of
milliseconds while pursuing a goal that needs planning over seconds. No single open multimodal
LLM does both: a **reasoning** VLM (Qwen3-VL-8B-Thinking, 8B) is ~1.5 s too slow for the ~15 Hz
control loop, while a **reactive** VLM (MiniCPM-o 4.5, 9B) has no deliberation. The fast/slow
split is the fix β Thinking Machines' [Interaction Models](https://thinkingmachines.ai/blog/interaction-models/)
make it explicit via shared text/context; we test an **open** alternative.
This project investigates whether a learned continuous-valued **latent bridge** β project the
slow model's residuals into the fast model's input-embedding space, LLaVA-style β beats the
standard **text channel** (the slow model writes a prompt suffix the fast model reads) between
two **frozen** models at matched ~8β9 B scale, so the *channel*, not a capability gap, is the
load-bearing variable. The 33 M-param bridge is the only trained component.
**Headline finding:** the latent bridge helps *if and only if* slow reasoning helps the task
(**T > F**) β `LβF` tracks `TβF` at **Pearson r = 0.93**. Tuned per channel, the latent is never
significantly worse than the text bridge and significantly better on **2 of 7** games; combining
both channels *interferes*, so couple via exactly **one**. Details below.
## π― Per-game scores β 8 Atari games, 12 episodes per cell (fixed-greedy view)
The best L vs T result per game (using whichever Stage A β bare or robust β
gave the higher L score):
| Game | F | T | **L** | L vs T |
|---|---|---|---|---|
| MsPacman | 256 Β± 24 | 408 Β± 88 | **628 Β± 341** | **+54 %** |
| Seaquest | 42 Β± 19 | 63 Β± 11 | **80 Β± 0** | **+26 %** |
| RoadRunner | 0 Β± 0 | 475 Β± 160 | **608 Β± 29** | **+28 %** |
| River Raid (robust SA) | 1033 Β± 19 | 337 Β± 77 | **612 Β± 297** | **+82 %** |
| SpaceInvaders (robust SA) | 107 Β± 60 | 18 Β± 18 | 15 Β± 0 | recovered from 0 |
| Enduro (robust SA) | 0.8 Β± 1.0 | 4.9 Β± 5.6 | **5.8 Β± 2.5** | +18 % |
| Q*bert (robust SA) | 25 Β± 0 | **125 Β± 0** | 50 Β± 0 | T > L (greedy; tie under tuned decoders) |
| Pong | β21 Β± 0 | β21 Β± 0 | β21 Β± 0 | reactive floor |
> β οΈ **These are fixed-*greedy*-decoder numbers.** The latent's advantage over
> text is decoder-specific: a full decoder sweep (greedy, Οβ{0.3β¦1.5}) shows it
> vanishes at every fixed sampling temperature. The honest comparison tunes the
> action decoder per channel on held-out seeds (*best-achievable*): there the latent
> is **never significantly worse than text and significantly better on 2 of 7**
> (MsPacman, RoadRunner); the other 5 are ties. See the [paper](https://arxiv.org/abs/2606.24470)
> for the decoder-robust tables. The continuous-vs-categorical hypothesis these
> per-game scores once motivated is **retired** β emission statistics do not predict
> sign(LβT) (lexical-diversity r=+0.05, n.s.).
**Current claim (decoder-robust)**: the latent bridge helps *if and only if* slow
reasoning helps the task (T > F) β `LβF` tracks `TβF` at **Pearson r = 0.93** across
7 Atari games + MetaDrive (the controlled negative). Whether to couple is a property
of the task, not the channel; if you couple, use exactly one channel (text+latent
together *interferes*, β96 % on RoadRunner).
The largest *greedy* LβT gap (+82 %) is on **River Raid** after robust Stage A (a tie
under tuned decoders). The cleanest qualitative demo is **RoadRunner**: F=0 vs L=608
(reproducible; an earlier run scored 967, but the F=0 baseline makes the magnitude
run-to-run-unstable β the L>T direction is robust).
### Stage A robustness recipe (the second-order finding)
Stage A trained on bare prompts becomes out-of-distribution when T appends a
text suffix or L prepends bridge tokens. We diagnosed this through three
SpaceInvaders interventions (random-T, expert-T, aggressive-prompt all gave
T=L=0) and confirmed by fixing it: `--suffix-prob=0.5` Stage A retraining
breaks the collapse.
**Targeted, not universal**: applying robust SA to games where L > T already
worked (MsPacman, Seaquest) *hurt* β the slight bare-prompt accuracy drop
dominated the suffix-robustness gain. The recipe is:
- Use robust SA when T/L collapse to ~0 (SI, RR-bare, Q*bert, Enduro)
- Don't use it when T/L already win (MsPacman, Seaquest)
- Surprise: RoadRunner F=0 under bare SA was overfitting, not policy
stuckness β robust SA recovered F to 958 and all three strategies tie (~925-1000)
### Detailed SpaceInvaders breakdown (diagnostic chain)
| Strategy | bare Stage A | robust Stage A |
|---|---|---|
| F | 105 Β± 0 | 107 Β± 60 |
| T | **0 Β± 0** | **18 Β± 18** |
| L | **0 Β± 0** | **15 Β± 0** |
The L=T=0 collapse was diagnosed across four interventions (random-T,
expert-T, aggressive-prompt, all gave 0; robust-Stage-A retry recovered both
T and L to nonzero). Bridge MI under expert-T was +0.024 nats β the bridge
*did* learn structure β but the deployed policy still collapsed because of
the action head's OOD-brittleness, not the bridge itself.
- L > T claim: under fixed greedy decoding, 4-of-7 games; under the
decoder-robust best-achievable comparison (tune decoder per channel on
held-out seeds), the latent significantly wins 2-of-7 (MsPacman, RoadRunner),
ties the other 5, and never significantly loses.
- SpaceInvaders diagnosis end-to-end validated: L=T=0 under bare Stage A;
L=15, T=18 under robust Stage A. The bridge mechanism was never broken;
Stage A OOD-brittleness was. PPO under deployment distribution
is the next step to close the F-L gap.
### Slow-only S baseline (MsPacman, n=3)
| Strategy | Score | Comment |
|---|---|---|
| **S (slow only, ~1 Hz)** | 113 Β± 24 | Just use the big model: 4 s/decision, too slow |
| F (fast only, 15 Hz) | 256 Β± 24 | Reactive, no planning |
| T (text bridge) | 408 Β± 88 | Slow guides fast via text |
| **L (latent bridge)** | **628 Β± 341** | Slow guides fast via latents |
On MsPacman the ordering is **S < F < T < L** β slow-only is too slow for real-time,
fast-only lacks planning, and both bridges help (the latent most, under greedy decoding).
This is *not* a universal law: whether either bridge beats fast-only is task-dependent
(the **T > F** predictor), and the latent's edge over text is decoder-specific (see the
caveat above).
The full story (v1 cross-attn β v2 LLaVA-style redesign) is in
[`docs/06_results.md`](docs/06_results.md).
## What works (v2)
The latent bridge is **LLaVA-style**: the slow model produces N=8 latent tokens in the
fast model's 4096-d input embedding space; they are **prepended to the fast model's
input sequence** so all 36 LLM layers attend over them through the standard causal
attention path. This is the same architectural pattern that LLaVA, BLIP-2, Flamingo,
and MiniCPM-o itself use for multimodal coupling.
```
slow model (Qwen3-VL-8B-Thinking)
ββ residuals at layer 24, last N=8 positions
ββ ThoughtProjection (4096 β 4096 β 4096 + LayerNorm, ~33M params trainable)
ββ N=8 latent tokens in fast model's embedding space
ββ PREPENDED to fast model's input embedding sequence
ββ fast model (MiniCPM-o 4.5) β all 36 LLM layers attend
ββ action_head on last hidden state β action logits
```
## What didn't work (v1)
The original design tried mid-layer cross-attention into a 256-d ring buffer at LLM
depths 12 & 24, with 71M trainable fast-side params. This **converged to KL=0.004 on
training data but failed at deployment** (L=225 vs F=256, bimodal with 4/12 catastrophic
episodes). Three architectural variants (ungated / gated / gated+head-tune) all failed.
Why v1 failed:
1. **No inductive bias** for arbitrary 256-d vectors β the LLM had no pretraining for
that format and ~5K Stage C samples wasn't enough to learn one from scratch.
2. **Information bottleneck** β only 2 of 36 layers saw the bridge; the rest had to
propagate it via the residual stream alone.
v2 solves both by matching the LLM's input-embedding pattern (text-like inductive bias)
and using the full attention stack.
## Hypotheses
- **H1**: Latent bridge β₯ text bridge on games needing both reflex + planning.
**β
Decoder-robust**: tuned per channel (held-out decoder selection), the latent is
never significantly worse than text and significantly better on 2/7 (MsPacman,
RoadRunner). The original greedy "L > T on 4/7" over-credited the latent β the
advantage is greedy-specific (see the decoder-sensitivity note above).
- **H2**: Latent-vs-text gap *grows* with strategic complexity. **β Refuted** β emission
statistics don't predict sign(LβT) (lexical-diversity *r* = +0.05, n.s.; the
continuous-vs-categorical hypothesis is retired). What *does* gate the bridge is the
behavioral predictor: it pays off iff slow reasoning beats reaction on the task (**T > F**).
- **H3**: A frozen base + a small trained channel recovers most of a unified upper bound.
**β
Confirmed**: only the ~33 M-param slow-projection bridge trains; both base models are
frozen. (The latent's ceiling is its text teacher β Stage C distills L toward T.)
## Repo layout
```
latent-bridge-games/
βββ README.md
βββ docs/
β βββ 01_framing.md # research thesis + scope
β βββ 02_related_work.md # surveyed prior art
β βββ 03_experiment_plan.md # experiment plan (updated for v2)
β βββ 04_architecture.md # v2 LLaVA-style bridge spec
β βββ 05_status.md # what was built + key empirical findings
β βββ 06_results.md # paper-style results summary
β βββ 07_next_steps.md # roadmap
βββ paper/ # LaTeX source + generated figures (main.pdf)
βββ web-react/ # interactive website source (Vite/React)
βββ src/
β βββ env/atari_wrapper.py # ALE wrapper + MsPacman/Frostbite/Seaquest RAM decoders
β βββ models/fast_model.py # MiniCPM-o + v2 bridge-token prepend + vision cache
β βββ models/slow_model.py # Qwen3-VL-8B-Thinking + trainable ThoughtProjection
β βββ bridge/ring_buffer.py # (v1 legacy; unused in v2)
β βββ training/
β β βββ stage_a_behavioral.py # Stage A imitation (frozen base + action_head only)
β β βββ stage_c_v2.py # v2 Stage C: trainable slow ThoughtProjection only
β β βββ stage_c_bridge.py # (v1 legacy: cross-attn KL training)
β β βββ prompts.py # per-game Stage B text prompts
β β βββ imitation_data.py # global 18-way action space + per-game maps
β βββ eval/
β βββ benchmark.py # multi-strategy multi-game eval harness
β βββ mi_diagnostic.py # bridge information-content diagnostic
βββ configs/ # YAML run configs
βββ scripts/
β βββ collect_trajectories.py # SB3-expert trajectory collection (CPU)
β βββ run_text_bridge_baseline.py # T-trajectory collection (saves v2 raw residuals)
β βββ aggregate_results.py # multi-eval comparison table
β βββ make_figures.py # paper-quality matplotlib figures
β βββ _pipeline.sh # per-game AβBβCβeval chains
β βββ README.md # guide to every script + canonical entry points
β βββ ...
βββ tests/ # 45 unit + integration tests (CPU-runnable)
βββ results/ # per-condition raw eval outputs
βββ checkpoints/ # Stage A + Stage C trained checkpoints
```
## Setup
```bash
git clone https://github.com/19PINE-AI/latent-bridge-games
cd latent-bridge-games
python -m venv .venv && source .venv/bin/activate
pip install -e . # core: Atari repro (experts, training, eval, figures)
# optional extras:
pip install -e ".[demo]" # narrated-demo build + Flask/SSE live server
pip install -e ".[metadrive]" # driving domain (the controlled negative)
```
The two frozen base models are **not** in the repo. Point the harness at local
weights via `LB_FAST_MODEL_PATH` / `LB_SLOW_MODEL_PATH` (or let `transformers`
pull `openbmb/MiniCPM-o-4_5` and `Qwen/Qwen3-VL-8B-Thinking` from the HF cache);
set `HF_HUB_OFFLINE=1` to force the local copies. See `scripts/README.md` for a
guide to every script and the canonical entry points.
## Reproducing the headline number
> Trained checkpoints and `results/` are **not shipped** (both are gitignored). Train the
> Stage A behavioral-cloning policy first (`python -m src.training.stage_a_behavioral ...`;
> the per-game `scripts/*_pipeline.sh` run the full AβCβeval chain end-to-end). The steps
> below assume `checkpoints/stage_a/` already exists.
```bash
# 1. Collect T-trajectories (45 min on GPU)
HF_HUB_OFFLINE=1 python scripts/run_text_bridge_baseline.py \
--game MsPacman --episodes 10 --ticks 750 \
--out-dir results/t_trajectories_v2
# 2. Train v2 Stage C bridge (12 min on GPU)
HF_HUB_OFFLINE=1 python -m src.training.stage_c_v2 \
--trace 'results/t_trajectories_v2/MsPacman_seed*.pt' \
--stage-a-ckpt checkpoints/stage_a/mspacman_sb3dqn_v2.pt \
--out checkpoints/stage_c/v2_mspacman.pt
# 3. F/T/L head-to-head eval (~60 min for 36 episodes)
HF_HUB_OFFLINE=1 python -m src.eval.benchmark \
--strategies F T L --games MsPacman --seeds 0 1 2 --episodes 4 \
--fast-ckpt checkpoints/stage_a/mspacman_sb3dqn_v2.pt \
--bridge-ckpt checkpoints/stage_c/v2_mspacman.pt \
--out results/eval_v2_mspacman.json
# 4. Aggregate + plot
python scripts/aggregate_results.py
python scripts/make_figures.py
```
## Hardware
NVIDIA RTX Pro 6000, 96GB VRAM. Joint inference of MiniCPM-o 4.5 (bf16, 18GB) and
Qwen3-VL-8B-Thinking (bf16, 17GB) leaves ~60GB headroom for training/PPO batches.
A single scaling ablation with Qwen3-30B-A3B-Thinking (~60GB) fits at inference with
~10GB headroom; would need activation checkpointing or AWQ-4bit for joint training.
## Status
- [x] Joint inference validation (34GB VRAM, ~270ms cold tick)
- [x] Stage A behavioral cloning + the **v2 Stage C latent bridge** (the core channel)
- [x] Stage B text-bridge baseline (T = +59 % over F on MsPacman)
- [x] Cross-game sweep: 7 Atari games + MetaDrive (the controlled negative)
- [x] Stage A robustness recipe (`--suffix-prob=0.5`) β validates the OOD-brittleness diagnosis
- [x] Decoder-sensitivity sweep + held-out **best-achievable** per-channel selection (2-of-7 sig. wins)
- [x] Combined-channel (T+L) experiment β *interferes*; couple via exactly one channel
- [x] **Behavioral predictor**: LβF tracks TβF, r = 0.93 (0.96 over all 16 cells)
- [x] Bridge-replacement control (learned content tracks T > F)
- [x] 30B-A3B cross-scale ablation (more slow-model capacity does **not** widen LβT)
- [x] Latent token-count (N) ablation N=4/8/16 (deploy-only N=16 best β no capacity ceiling)
- [x] MI diagnostic; vision-token cache (latency option)
- [x] Recorded MP4 demos + interactive website (`web-react` β `web-dist`)
- [ ] Stage D PPO (online RL; will it recover SpaceInvaders?)
- [ ] Slow-only S + Oracle O baselines tabulated for all games
- [ ] Scale to the motivating target: real-time computer-use / game agents on phone & desktop
## License
MIT License β see [`LICENSE`](LICENSE). Copyright (c) 2026 Pine AI.