Skip to content

Implement full DIAMOND Atari agent with pixel-space diffusion world model and RL in imagination#252

Open
ParamThakkar123 wants to merge 11 commits into
galilai-group:mainfrom
ParamThakkar123:diamond
Open

Implement full DIAMOND Atari agent with pixel-space diffusion world model and RL in imagination#252
ParamThakkar123 wants to merge 11 commits into
galilai-group:mainfrom
ParamThakkar123:diamond

Conversation

@ParamThakkar123

Copy link
Copy Markdown

Summary

Implements the complete DIAMOND algorithm (Alonso et al., NeurIPS 2024) — a pixel-space diffusion world model trained with REINFORCE + λ-return value baseline inside imagination, following the Atari 100k benchmark protocol.

Core components

  • Diffusion world model: EDM preconditioning (Karras et al. 2022) with Euler sampling, SimpleUNet with AdaptiveGroupNorm, conditioned on 4-frame history + action embeddings
  • Reward/termination model: Separate CNN-LSTM predicting scalar rewards and terminal probabilities from imagined frames
  • Actor-critic: Shared CNN-LSTM backbone with categorical policy head and scalar value head, trained via λ-return REINFORCE
  • CategoricalCEMSolver integration: DiamondCostModel wraps diffusion + reward LSTM as a Costable for MPC planning

Atari 100k protocol

  • NoopReset (max 30), FireReset, EpisodicLife, ClipReward ({-1, 0, 1})
  • Sticky actions (repeat_action_probability=0.25)
  • 64×64 RGB observations, reward clipping, full 18-action space

Training pipeline

  • 1000 epochs, each collecting 100 env steps then 400 gradient steps per component
  • Three optimizers: diffusion (+ action encoder), reward/term model, actor-critic
  • MPC evaluation via CategoricalCEMSolver (random shooting, single iteration)
  • 27 tests covering EDM preconditioners, cost model, agent rollout, λ-returns, RL losses

Cleanup

  • Removed legacy embedding-space Diamond class (dead code, replaced by pixel-space agent)
  • Atari wrappers moved from wrapper/ to envs/ale/
  • planner.py removed (dead code, CategoricalCEMSolver used instead)

Known issues

  • Hydra CLI OOM on Windows (runs fine standalone / Linux)
  • Evaluation docs need restructuring to be world-model-agnostic

…raining into EDM loss, add training/inference helpers
…tests for preconditioners, samplers, loss and predict
… with RL in imagination

- Add DiamondAgent with diffusion world model, reward/term LSTM, and actor-critic trained via REINFORCE + lambda-return baseline
- Add DiamondCostModel wrapping diffusion + reward LSTM for CategoricalCEMSolver integration (Costable protocol)
- Add ActorCritic (shared CNN-LSTM backbone), RewardTermModel, ConvEncoder, DiscreteActionEncoder
- Add EDM diffusion (Karras preconditioning, Euler/Heun sampling, U-Net with AdaptiveGroupNorm)
- Add Atari 100k wrappers (NoopReset, FireReset, EpisodicLife, ClipReward) in envs/ale/
- Add end-to-end training script (diamond_full.py) with Hydra config: buffer collection, diffusion/reward/RL training phases, MPC eval
- Add comprehensive tests: 5 EDM, 10 cost model, 12 agent tests
- Remove legacy embedding-space Diamond class (diamond.py)
- Fix: c_out preconditioner formula, LSTM warmup from zero state, action_encoder in optimizer, gradient flow through imagination rollout
- Merge 9 source files into two: module.py (models) and diamond.py (agent/logic)
- Delete: unet.py, edm.py, edm_sampling.py, edm_train.py, diffusion.py, agent.py, examples.py, diamond_agent.py, cost_model.py
- Update all imports in tests, scripts, configs, and wm/__init__.py
- All 27 tests pass
@lucas-maes

Copy link
Copy Markdown
Collaborator

hi! could you report some reward or success rate?

@lucas-maes

Copy link
Copy Markdown
Collaborator

Few comments:

  • I think the wrapper you added is already present in ale package. Is it necessary to rewrite the code here?
  • Please could you remove the claude # ---- helper comment?
  • Make sure to rely on hydra, we only support hydra and don't want a mix of argparse and hydra as you currently did

Thank you very much for the PR! It's sick!

@ParamThakkar123

Copy link
Copy Markdown
Author

Thank you so much @lucas-maes , yes I am working on these parts and will report with the metrics and fixes in a few hours 🫡

@ParamThakkar123

ParamThakkar123 commented Jun 10, 2026

Copy link
Copy Markdown
Author

Hi @lucas-maes , I am trying to run a smoke test on a few epochs for this but I am out of GPU credits right now and my laptop GPU is going OOM for even the smoke test (RTX 3050 4GB VRAM), Would it be possible for you to run a smoke test on your end with this command?

python scripts/train/diamond_full.py epochs=2 steps_per_epoch=5 train_steps=2 eval_every=1 log_every=1 max_episode_steps=100 2>&1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants