Pages and contents
Pages
TL1 — Minigrid
MiniGrid Perceptual Encoding
For MiniGrid, the perceptual encoder transforms a partial RGB observation into a spatial latent representation .
Using an 8-pixel tile size, the agent observes an RGB image
A learned convolution with kernel size 8 and stride 8 divides the image into a grid and produces one feature vector for each visible cell:
Here, is a learned two-dimensional positional embedding. The shape changes as follows:
Flattening does not pool or discard spatial information. It only represents the grid as a sequence of 49 feature vectors.
The features are then processed by residual attention blocks. For block :
The final perceptual representation is
Thus, contains 49 contextualized latent vectors. Each vector begins with information from one visible grid cell, while the attention blocks allow it to incorporate information from the rest of the observation.
No global pooling or classification token is used. The complete spatial representation is preserved for latent dynamics, thought, and action selection.
Phase 1 Results
phase1.py collects episode-labelled one-step trajectory segments under a uniformly random policy, trains ZEncoder and LatentDynamics with prediction plus patch-wise VISReg, and evaluates on complete held-out episodes. Batches mix segments from training episodes; no transition from a held-out episode can appear in training.
The first diagnostics are:
• Improvement over identity: identity MSE minus dynamics prediction MSE. Positive values show that predicting a transition is better than returning the current latent unchanged.
• Action shuffle penalty: prediction MSE with shuffled actions minus normal prediction MSE. Positive values show that the predictor uses its action input. Actions are shuffled only during frozen evaluation.
• Latent spread: mean, minimum, and maximum per-dimension standard deviation across held-out observations, plus the fraction below 0.1. These use the same observation axis as patch-wise VISReg.
Training history records the VISReg center, scale, and shape components separately so a constant aggregate cannot hide movement between terms.
Run the default experiment with:
```bash
poetry run python -m mgrid.phase1
```
The research-sized defaults use CUDA, 32,768 transitions, batch size 256, 20 epochs, VISReg weight 1.0, and 32 shape projections. Pass --device cpu only for a smaller smoke run on a machine without CUDA.
Successful Phase 1 run
The default CUDA configuration was trained with seed 0. It used 26,557 training transitions and 6,211 validation transitions from complete held-out episodes. The final results were:
Metric | Result | |
|---|---|---|
| ⋮⋮ | Prediction MSE | 0.0547 |
| ⋮⋮ | Identity-predictor MSE | 0.5539 |
| ⋮⋮ | Improvement over identity | 90.1% |
| ⋮⋮ | Shuffled-action MSE | 0.8559 |
| ⋮⋮ | Action-shuffle penalty | 0.8012 |
| ⋮⋮ | Mean latent standard deviation | 0.9507 |
| ⋮⋮ | Latent standard-deviation range | 0.8371–1.0540 |
| ⋮⋮ | Dimensions below standard deviation 0.1 | 0% |
The dynamics model therefore predicts the next latent much more accurately than returning the current latent unchanged. Supplying a shuffled action is also worse than the identity predictor, showing that the model learned a
strong action-conditioned transition rather than ignoring its action input.
VISReg successfully prevented the contraction seen in the smoke baseline:
VISReg term | Epoch 1 | Epoch 20 | |
|---|---|---|---|
| ⋮⋮ | Center | 0.9870 | 0.0099 |
| ⋮⋮ | Scale | 0.9435 | 0.0026 |
| ⋮⋮ | Shape | 0.1519 | 0.0453 |
| ⋮⋮ | Total | 2.0824 | 0.0578 |
Prediction loss briefly rose when VISReg expanded the initially contracted representation at epoch 3, then recovered as the dynamics adapted. Final training prediction MSE was 0.0508, close to the held-out value of 0.0547, with no obvious generalization gap. These results support a non-collapsed, action-sensitive Phase 1 world model. They do not yet establish whether the latents retain object, color, and state semantics; a frozen symbolic linear probe is the next evaluation. The full metrics are in mgrid/results/phase1/MiniGrid-Empty-8x8-v0_n32768_visreg1_seed0.json, with the corresponding checkpoint beside them.
Four Rooms + GAE + PPO Results
The first two-million-step recurrent PPO run substantially improved over the seven-action A2C baseline, but did not solve FourRooms. On the final rolling 100 episodes:
Metric | A2C baseline | PPO + GAE | |
|---|---|---|---|
| ⋮⋮ | Success rate | 1% | 23% |
| ⋮⋮ | Mean return | 0.00118 | 0.13361 |
| ⋮⋮ | Mean episode length | 99.98 | 87.71 |
| ⋮⋮ | Policy entropy | 1.944 / log(7) | 0.176 / log(3) |
PPO reached a best rolling success rate of 31% at 782,336 environment steps. Mean return peaked at 0.20568 and mean episode length reached its minimum of 80.48 around 819,200 steps. Performance then plateaued and partially regressed rather than continuing toward reliable navigation. The working hypothesis is that exploration collapsed too early and some PPO updates were too aggressive. Entropy fell below 0.1 around 800k steps even though most episodes still failed. Approximate KL occasionally spiked to roughly 0.05–0.06; the final update had KL 0.0463 and a clip fraction of 0.116. These values indicate that clipping did not fully prevent occasional large policy changes. The encoder remained locally slow (1.28e-5 final per-update drift), but moved 0.1106 relative to its Phase 2 starting point, so representation nonstationarity may also have made the recurrent policy's input less stationary. The world model itself remained action-sensitive, but
its Phase 2 prediction MSE stayed around 0.10. The result supports PPO, GAE, and navigation-only actions over the original A2C setup. Likely next controls are a slower entropy decay or nonzero entropy floor, a lower policy learning rate or target-KL early stopping, and reduced encoder movement during policy optimization. A stronger exploration signal may still be necessary because the external FourRooms reward remains sparse.