Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] CNN version of MultiAgentMLP #1479

Merged
merged 27 commits into from
Oct 4, 2023

Conversation

MarkHaoxiang
Copy link
Contributor

Description

Added a MultiAgentConvNet module, which wraps a ConvNet to work in the multiagent space.

Motivation and Context

This is an utility written for PettingZoo Multiagent environments which have pixel based observations.

Types of changes

What types of changes does your code introduce? Remove all that do not apply:

  • Bug fix (non-breaking change which fixes an issue)
  • [ x] New feature (non-breaking change which adds core functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)
  • Example (update in the folder of examples)

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • [ x] I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • [ x] I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

@facebook-github-bot facebook-github-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 Sep 1, 2023
@MarkHaoxiang
Copy link
Contributor Author

@matteobettini

@vmoens vmoens changed the title CNN version of MultiAgentMLP [Feature] CNN version of MultiAgentMLP Sep 1, 2023
Copy link
Contributor

@matteobettini matteobettini left a comment

Choose a reason for hiding this comment

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

This is incredible work, thanks so much! I was actually in need of a model like this.

I left some comments, but after those are addressed we should be there!

@matteobettini
Copy link
Contributor

also make sure you format the files and lint them.
we have a pre-commit hook, instructiuons on how to run it should be in the CONTRIBUTING file

@vmoens vmoens added the enhancement New feature or request label Sep 5, 2023
@MarkHaoxiang
Copy link
Contributor Author

Thank you for the review. I have updated the changes requested.

Copy link
Contributor

@matteobettini matteobettini left a comment

Choose a reason for hiding this comment

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

LGTM thanks for this

@vmoens can you have a pass?

@matteobettini
Copy link
Contributor

@vmoens I’m considering merging this as is and do the refactoring to vmap in a second time as in #1497, would that work for you? Unless @MarkHaoxiang wants to take care of it?

@MarkHaoxiang
Copy link
Contributor Author

@matteobettini Have you started implementing the common multiagent nn module? If not I'll take a shot at it this week.

@matteobettini
Copy link
Contributor

Nope, yo can take a shot!

So what we want is to do the exact same things but using vmap like #1497 (see that pr for context)

@matteobettini
Copy link
Contributor

matteobettini commented Sep 13, 2023

@MarkHaoxiang we are posticipating that refactoring a bit to wait for some features, so we can go ahead with this as is.
@vmoens could you have a look?

Copy link
Contributor

@vmoens vmoens left a comment

Choose a reason for hiding this comment

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

Great work! A couple of comments regarding formatting

@vmoens
Copy link
Contributor

vmoens commented Sep 14, 2023

Tests are not passing, presumably because we moved the scripts from .circleci to .github for the CI

@MarkHaoxiang
Copy link
Contributor Author

Thanks for the check - I've adjusted the formatting as requested

Copy link
Contributor

@vmoens vmoens left a comment

Choose a reason for hiding this comment

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

Almost there!

@MarkHaoxiang MarkHaoxiang requested a review from vmoens September 23, 2023 11:03
@matteobettini
Copy link
Contributor

CNN tests are failing

@MarkHaoxiang
Copy link
Contributor Author

Fixed a bug with reshaping the tensor step in the centralised/parameter sharing case.

output = (
                    output.view(*output.shape[:-1], self.n_agent_outputs)
                    .unsqueeze(-2)
                    .expand(*output.shape[:-1], self.n_agents, self.n_agent_outputs)
                )

@matteobettini whats the motivation behind expanding the tensor like this (for the MLP version) compared to

output = output.unsqueeze(-2)
output = output.expand(*output.shape[:-2], self.n_agents, n_agent_outputs)

@matteobettini
Copy link
Contributor

They seem equivalent, but in the first case the view acts as an implicit assert on the shape, so it is more readable in my opinion.

@matteobettini
Copy link
Contributor

matteobettini commented Oct 1, 2023

What was the problem with the previous way? Why was it a bug?

EDIT:

ah i see, when you broke it into multiline the modifications of each line was applied on different tensors

i would still keep the view before to make sure

@MarkHaoxiang
Copy link
Contributor Author

Sure, I've changed both to use the multi-line version but with the view

Copy link
Contributor

@vmoens vmoens left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for this

@vmoens vmoens merged commit a43612a into pytorch:main Oct 4, 2023
@MarkHaoxiang MarkHaoxiang deleted the multiagent-cnn branch October 4, 2023 14:10
vmoens added a commit to hyerra/rl that referenced this pull request Oct 10, 2023
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. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants