Skip to content

[Feature] Add COMA multi-agent objective - #4151

Open
Iliamsou wants to merge 2 commits into
pytorch:mainfrom
Iliamsou:feature/marl-coma
Open

[Feature] Add COMA multi-agent objective#4151
Iliamsou wants to merge 2 commits into
pytorch:mainfrom
Iliamsou:feature/marl-coma

Conversation

@Iliamsou

Copy link
Copy Markdown

What

Adds a dedicated COMALoss objective 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: COMALoss implementation 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__.py and torchrl/objectives/__init__.py: expose COMALoss.
  • 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.py

8 passed.

@pytorch-bot

pytorch-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown

🔗 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 Failure

As of commit 35879da with merge base b0eab87 (image):

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.

@meta-cla

meta-cla Bot commented Aug 24, 2026

Copy link
Copy Markdown

Hi @Iliamsou!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 24, 2026
@meta-cla

meta-cla Bot commented Aug 24, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@vmoens vmoens left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a dedicated COMA objective. I found several issues that need to be addressed before this can merge:

  1. [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.

  2. [P1] Bootstrap rollout boundaries and truncations correctly. Zero-filling shifted values makes the last n_step transitions of every non-terminal fixed-length rollout use incomplete returns. Masking with done also suppresses a valid bootstrap at truncation; TorchRL return semantics distinguish this with terminated. The target critic needs to evaluate the transition next observation at boundaries rather than treating the end of the sampled batch as terminal.

  3. [P1] Honor collector validity masks. Direct .mean() and F.mse_loss(...) reductions bypass LossModule._reduce_loss, so ("collector", "mask") and shifted_valid do 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).

  4. [P2] Preserve flat NestedKey values. ("next",) + tuple(self.tensor_keys.reward) works for tuple keys but turns reward="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.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Feature New feature Objectives

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants