[Feature] MAPPOLoss + IPPOLoss + MultiAgentGAE + ValueNorm#3748
Open
theap06 wants to merge 2 commits into
Open
[Feature] MAPPOLoss + IPPOLoss + MultiAgentGAE + ValueNorm#3748theap06 wants to merge 2 commits into
theap06 wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3748
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below:
|
Contributor
|
I think you're right about making MA training more straightforward, but I have some concerns:
|
Contributor
Author
I think the layers of abstractions make sense. I think the value estimators would help because of the utilization of the collectors as well. For the compatibility issues, I can write up some test cases to ensure it doesn't impact existing algos. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Multi-agent RL is currently the weakest research surface in torchrl: the only multi-agent loss shipped is
QMixerLoss(DQN family, discrete actions). For cooperative continuous-control MARL — where most modern benchmarks live (SMAC, VMAS, PettingZoo MPE, Hanabi, Overcooked) — users have to hand-assembleClipPPOLoss+ manualset_keys(done=("agents", "done"), terminated=("agents", "terminated"))+ manualmake_value_estimator(GAE, ...). The existingsota-implementations/multiagent/mappo_ippo.pyrecipe shows what this boilerplate looks like.This PR adds MAPPO (Yu et al. 2022) and IPPO (de Witt et al. 2020) as first-class objectives, plus the two pieces of supporting infrastructure they need.
What's new
torchrl.objectives.multiagent.MAPPOLoss— centralised-critic, decentralised-actor PPO. SubclassesClipPPOLoss; defaults the value estimator toMultiAgentGAE, defaultsnormalize_advantage_exclude_dims=(-2,), and optionally accepts aValueNormfor the critic-stability trick from the paper.torchrl.objectives.multiagent.IPPOLoss— independent-learner counterpart. Each agent has its own local critic; no centralised state required.torchrl.objectives.value.MultiAgentGAE—GAEvariant that broadcasts team-sharedreward/done/terminated(shape[*B, T, 1]) across the agent dim before the vec-GAE recursion, so users don't have to manually replicate signals or overrideset_keys. NewValueEstimators.MAGAEenum entry.torchrl.modules.ValueNorm— PopArt-style running value normaliser (van Hasselt et al. 2019), used opt-in byMAPPOLoss. Yu et al. 2022 Table 13 credits this trick with the algorithm's strong SMAC results.Design notes
Two classes instead of a
centralized: boolflag. The structural code difference between MAPPO and IPPO is small (~20 lines), but I made them separate named classes rather than a single class with a flag because:from torchrl.objectives.multiagent import MAPPOLossis self-documenting; the docstring spells out the full recipe (centralised critic construction, etc.) for each algorithm independently.MAGAE dispatch in plain PPO / A2C / Reinforce. Adding
ValueEstimators.MAGAEto the enum would break every parent test that parametrises overlist(ValueEstimators)unless everymake_value_estimatorknows the new enum value. Two options: (a) update ~29 test parametrisations to skip MAGAE, or (b) have plain PPO / A2C / Reinforce dispatch MAGAE toMultiAgentGAE. I went with (b) — it's ~5 lines per file, leaves the enum exhaustive, and is the right thing semantically (any actor-critic with the right data shapes can use MAGAE).ValueNorm placement. Lives under
torchrl/modules/rather thantorchrl/objectives/utils/because it's a stateful learnable component that participates in.to(device)/state_dict(). Happy to move if reviewers prefer otherwise.Out of scope (follow-up)
sota-implementations/multiagent/mappo_ippo.pyto use the new classes — left untouched in this PR to keep the blast radius small; can be a one-line follow-up.Verification
pytest test/objectives/test_mappo.py— 16/16 passing. Synthetic-tensordict tests for forward shapes, backward, centralised-vs-decentralised critic semantics, share-params modes, ValueNorm convergence, and critic-loss bounded-ness under 10× reward inflation.pytest test/test_cost.py -k "ppo or qmixer or a2c or reinforce"— 2394/2394 passing (no regressions).test_cost.py— 8788 passing, 1 pre-existing unrelated failure (test_exploration_compile—torch.compile+torch.utils.mkldnndeprecation, no MAPPO involvement).examples/multiagent/mappo_vmas.py --algo mappo --frames 200_000provides a minimal end-to-end smoke recipe on VMAS Navigation.