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

Bug in MultiAgentPolicyManager - and Fix #967

Closed
5 of 8 tasks
FahmidMorshed opened this issue Oct 16, 2023 · 2 comments · Fixed by #968
Closed
5 of 8 tasks

Bug in MultiAgentPolicyManager - and Fix #967

FahmidMorshed opened this issue Oct 16, 2023 · 2 comments · Fixed by #968

Comments

@FahmidMorshed
Copy link
Contributor

FahmidMorshed commented Oct 16, 2023

  • I have marked all applicable categories:
    • exception-raising bug
    • RL algorithm bug
    • documentation request (i.e. "X is missing from the documentation.")
    • new feature request
  • I have visited the source website
  • I have searched through the issue tracker for duplicates
  • I have mentioned version numbers, operating system and environment, where applicable:
    import tianshou, gymnasium as gym, torch, numpy, sys
    print(tianshou.__version__, gym.__version__, torch.__version__, numpy.__version__, sys.version, sys.platform)

I tried running MARL with multiple SAC as internal policies for each agent for one of my custom-made petting zoo environments. After rigorous debugging, I realized that the MultiAgentPolicyManager in version 0.5.1 needs a train(self, mode: bool = True) method that iteratively sets all the internal policies to mode. Otherwise, the internal policies are never called in eval mode. I am not sure if this is also true when used with other types of internal policies.

The following function solves the issue if added to tianshou/policy/multiagent/mapolicy.py :

def train(self, mode: bool = True):
      """Sets each internal policy in training mode."""
      for agent_id, policy in self.policies.items():
          policy.train(mode)
      return self

I can do a pull-request to the main branch, if needed.

@Trinkle23897
Copy link
Collaborator

Oops sorry, and yeah good catch! Feel free to submit a PR.

@FahmidMorshed
Copy link
Contributor Author

Added a RP to fix the issue. Ty.

Trinkle23897 pushed a commit that referenced this issue Oct 17, 2023
The trained MARL policies were not performing as expected because the
parent class (MultiAgentPolicyManager) needed a train function.

Fixes #967
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants