[Feature] Add COMA multi-agent objective - #4151
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4151
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New Failures, 1 Unrelated FailureAs of commit 35879da with merge base b0eab87 ( NEW FAILURES - The following jobs have failed:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @Iliamsou! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
vmoens
left a comment
There was a problem hiding this comment.
Thanks for adding a dedicated COMA objective. I found several issues that need to be addressed before this can merge:
-
[P1] Shift the actual time dimension. In
compute_value_target,next_value[:, :-1] = value_target[:, 1:]only shifts time for exactly[B, T, ...]inputs. A standard collector over an unbatched environment returns[T, n_agents, 1], in which case this shifts the agent dimension. Multiple environment batch dimensions also shift the wrong axis. Please resolve the named/final TensorDict time dimension and add a[T]regression case. -
[P1] Bootstrap rollout boundaries and truncations correctly. Zero-filling shifted values makes the last
n_steptransitions of every non-terminal fixed-length rollout use incomplete returns. Masking withdonealso suppresses a valid bootstrap at truncation; TorchRL return semantics distinguish this withterminated. The target critic needs to evaluate the transition next observation at boundaries rather than treating the end of the sampled batch as terminal. -
[P1] Honor collector validity masks. Direct
.mean()andF.mse_loss(...)reductions bypassLossModule._reduce_loss, so("collector", "mask")andshifted_validdo not exclude padded transitions. COMA commonly consumes episodic sequences, so this can train both actor and critic on padding. Please keep losses elementwise and reduce through_reduce_loss(..., tensordict=tensordict). -
[P2] Preserve flat
NestedKeyvalues.("next",) + tuple(self.tensor_keys.reward)works for tuple keys but turnsreward="reward"into("next", "r", "e", "w", "a", "r", "d"). Please use the repository nested-key normalization pattern for both reward and termination keys.
The test volume is proportionate, but the current target tests only use synthetic [1, T] batches, which hides the time-axis failure. Please cover [T], a truncated boundary, automatic loss masking, and both flat and nested set_keys() values.
The public API integration also needs the repository-required documentation: a complete Sphinx-style class docstring with runnable example and paper reference, an entry in docs/source/reference/objectives_multiagent.rst, and the applicable tutorial/SOTA recipe. Since this is a new test file, please also add the executable if __name__ == "__main__": pytest.main(...) block.
What
Adds a dedicated
COMALossobjective for multi-agent reinforcement learning. The loss implements the COMA counterfactual baseline with a decentralised actor and a centralised Q-value network, including n-step Q-value targets and optional advantage normalisation.Contents
torchrl/objectives/multiagent/coma.py:COMALossimplementation and helpers to construct the joint observation, joint action without the current agent, and masked joint action inputs used by the centralised critic.torchrl/objectives/multiagent/__init__.pyandtorchrl/objectives/__init__.py: exposeCOMALoss.test/objectives/test_coma.py: tests for the counterfactual baseline, Q-value targets, n-step returns, input construction helpers, advantage normalisation, and diagnostics.Tests
Ran:
python -m pytest test/objectives/test_coma.py8 passed.