Multi-Agent RL and Sim-to-Real
CTDE, value decomposition, self-play, domain randomization and VLA action formats. Formulas, numbers and fixes.
- Concepts and terms
- Tasks and commands
- Annotated code
- Diagrams
- Comparisons
- Defaults and numbers
- Troubleshooting
- Questions and tips
MADDPG, QMIX, MAPPO#
| Factor | MADDPG | QMIX | MAPPO |
|---|---|---|---|
| Year | 2017 | 2018 | 2022 |
| Idea | Per-agent critic sees all obs and actions | Monotonic mix of per-agent Qs | PPO with a centralized value function |
| Setting | Cooperative, competitive, mixed | Cooperative only | Cooperative |
| Testbed | Particle World | SMAC | Particle-world, SMAC, Football, Hanabi, MPE |
| Learning | Off-policy, DDPG | Value decomposition | On-policy, PPO |
| Key trait | Critic grows with N, ~10 agents | Monotonic constraint is strict | Stable, minimal tuning |
| Status | Introduced CTDE | Dominant on SMAC | Default cooperative baseline |
Domain randomization in code#
slip_ep = rng.uniform(slip_low, slip_high)new sim each episodes_next, r, done = step(s, a, slip_ep, rng)slip moves perpendicularQ_fixed = train_fixed(0.0, rng=rng)policy A, no DRQ_dr = train_dr(0.0, 0.3, rng=rng)policy B, DRfor slip in (0.0, 0.1, 0.2, 0.3, 0.5, 0.7):0.5 and 0.7 are OOD r_fixed = evaluate(Q_fixed, slip) r_dr = evaluate(Q_dr, slip)Four VLAs side by side#
| Factor | RT-2 | OpenVLA | π0 | GR00T N1 |
|---|---|---|---|---|
| Action format | Text tokens, 256 bins | 256-bin tokens | Flow-matching action expert | System 1 action head |
| Backbone | PaLM-X VLM | 7B Llama, DINOv2 + SigLIP | VLM plus small action transformer | Large VLM plus small action head |
| Speed | 3-5 Hz | 4-5 Hz on an A100 | ~5 denoising steps, about 50 Hz | System 1 at 50-100 Hz, System 2 ~1 Hz |
| Detail | 10 tokens per step for 10-DOF | LoRA fine-tuning for new robots | 50-step action sequence | Joint commands, >30 DOF |
| Data | Web plus robot, ~1:1 | Open X-Embodiment, ~0.5:1 web-to-robot | Open X-Embodiment, similar ratio | Sim-to-real data from Omniverse |
Defaults in the lesson code#
| Setting | Default | Note |
|---|---|---|
alpha | 0.1 | MARL and DR toys |
gamma | 0.95 | MARL and DR toys |
epsilon, eps | 0.15 | ε-greedy exploration |
MARL episodes | 1500 | 3000 in the DR toy |
| DR slip range | Uniform[0.0, 0.3] | Policy B |
max_steps | 50 | CTDE pattern demo, 500 trials |
bins | 256 | Bin width 2/255 |
keep_coeff | 4 | Low-frequency DCT terms per dim |
Troubleshooting#
| Symptom | Cause | Fix |
|---|---|---|
| Agents chase each other | Each best response moves | Centralized critic, slow LR, freeze one |
| Replay makes it worse | Obsolete opponents in old data | Relabel, or weight by recency |
| No credit for shared reward | Credit assignment | COMA baseline or per-agent shaping |
| Self-play stuck in a cycle | Dominance cycle | League play with diverse opponents |
| DR policy too cautious | Too much randomization | Match the expected real distribution |
| DR does not help | Wrong parameter randomized | Profile the real robot first |
| Student cannot match teacher | Privileged info leakage | Keep the teacher realizable from obs |
| Policy breaks hardware | No safety envelope | Rate, torque and joint limits outside |
Core ideas and formulas#
- Markov game
- (S, A_1, \ldots, A_n, P, R_1, \ldots, R_n). Each agent has its own reward.
- Reward types
- identical is cooperative, zero-sum is adversarial, mixed is general-sum.
- Non-stationarity
- P(s' \mid s, a_i) depends on \pi_{-i}, and \pi_{-i} changes.
- CTDE
- critic Q(s, a_1, \ldots, a_n) in training. Policy \pi_i reads only o_i.
- QMIX
- Q_{\text{tot}} = f(Q_1, \ldots, Q_n) with \partial f / \partial Q_i \ge 0.
- COMA
- advantage is my Q minus the expected Q over my own action.
- Reality gap
- the shift between sim and real physics or sensing.
- Control budget
- a 30 Hz loop gives 33ms for each action.
CTDE: train central, act local#
Sim-to-real recipe (quadruped)#
Independent against joint Q#
a1 = epsilon_greedy(Q1, s, rng, epsilon)each agent picks alonea2 = epsilon_greedy(Q2, s, rng, epsilon)s_next, r, done = step(s, (a1, a2))joint step, shared rewardtarget1 = r + gamma * max(Q1[s_next].values())Q1[s][a1] += alpha * (target1 - Q1[s][a1])own Q tablereward = 10.0 if done else -1.0+10 when both arrivejoint_actions = [(a, b) for a in ACTIONS for b in ACTIONS]16 pairsja = max(joint_actions, key=lambda a: Q[s][a]) # one greedy joint pickTasks in code#
| Task | Code |
|---|---|
| Independent Q for two agents | independent_q(episodes= |
| One Q over 16 joint actions | joint_q_learning(episodes= |
| Train with DR | train_dr(0.0, |
| Zero-shot eval at one slip | evaluate(Q_dr, |
| Benchmark a CTDE pattern | bench(label, |
| Run the MARL pattern demo | python3 code/ |
| Action to 256 bins | discretize(action, |
| FAST-style compression | fast_compress(trajectory, |
Abbreviations#
- CTDE
- Centralized training, decentralized execution.
- IPPO
- Independent PPO. Each agent runs PPO alone.
- COMA
- counterfactual multi-agent. Isolates my contribution.
- DR
- domain randomization. Random sim parameters in training.
- SI
- system identification. Measure the real robot, fit the sim.
- ADR
- Automatic Domain Randomization. Widens DR as the policy improves.
- VLA
- vision-language-action. Image and instruction in, actions out.
- FAST
- Frequency-domain Action Sequence Tokenizer. DCT, then quantize.
Rules of thumb#
- Start with MAPPO for cooperative MARL.
- Use independent Q only for loosely-coupled tasks.
- Use self-play for zero-sum games. Use league play for strategy cycles.
- Log the observation and action stream of every agent.
- Test on a held-out sim variant before you deploy.
- Flag a DR range wider than 3× the measured real variability.
- Close a VLA domain gap with LoRA on 100-1000 task demos.
Questions#
- Where does independent Q fail?
- On tightly-coupled tasks, where one agent must wait.
- Why does QMIX allow local argmax?
- The mixer is monotonic in each per-agent Q.
- What does narrow training do?
- Slip 0.0 only drops hard as soon as real slip is above 0.
- Why co-fine-tune a VLA?
- Robot-only models fail on new instructions.
- Why the GR00T split?
- Slow planning does not block fast control.