Git Product home page Git Product logo

Comments (9)

Aequatio-Space avatar Aequatio-Space commented on September 1, 2024

You can try overriding the postprocess_fn in PPOTOrchPolicy. In the MARLlib, such an example may be:

COMATorchPolicy = A3CTorchPolicy.with_updates(
name="COMATorchPolicy",
get_default_config=lambda: A2C_CONFIG,
postprocess_fn=centralized_critic_postprocessing,
loss_fn=central_critic_coma_loss,
extra_action_out_fn=coma_model_value_predictions,
mixins=[
CentralizedValueMixin
])

the signature for postprocess_fn is fixed, which is

postprocess_fn(
policy: Policy, sample_batch: SampleBatch, 
other_agent_batches: Optional[Dict[AgentID, SampleBatch]] = None, 
episode: Optional[MultiAgentEpisode] = None
) -> SampleBatch

As displayed in the build_policy_class in https://github.com/ray-project/ray/blob/55fc0710d8472a9abaf244ed6567eb3b13136531/rllib/policy/policy_template.py#L40-L43

You can manipulate the SampleBatch instance provided in the signature to add custom trajectories.

from marllib.

nikhil-pitta avatar nikhil-pitta commented on September 1, 2024

@Aequatio-Space Is this function called before or after both the policy gradient and value function gradient update in ippo or in between?

from marllib.

Aequatio-Space avatar Aequatio-Space commented on September 1, 2024

@nikhil-pitta it is called before both the policy gradient and value function gradient. The pipeline is basically: extra_action_out_fn → postprocess_fn → loss_fn → compute_gradients → apply_gradients.

from marllib.

nikhil-pitta avatar nikhil-pitta commented on September 1, 2024

@Aequatio-Space Thanks so much for the info! We would like to add counterfactual experience to DDPG before adding to the replay buffer or when pulling from the replay buffer to evaluate. Specifically, we want to augment our current step/collected experiences and add to the replay buffer for the algorithm to use. What callback function could we do to use this, and would it be the same for every offline policy? If not a callback, what would you suggest we do?

from marllib.

Aequatio-Space avatar Aequatio-Space commented on September 1, 2024

@nikhil-pitta You mentioned "augment our current step/collected experiences and add to the replay buffer", and it sounds exactly what postprocess_fn do, as our earlier discussion. This extra function applies to all MARLlib algorithms since the interface is identical.

from marllib.

nikhil-pitta avatar nikhil-pitta commented on September 1, 2024

@Aequatio-Space Thank you for the response, and yes that function is exactly what I need! I tried using it for PPO by overriding the postprocess_fn for the IPPOTorchPolicy (https://github.com/Replicable-MARL/MARLlib/blob/master/marllib/marl/algos/core/IL/ppo.py; line 31).

I wanted to do the same thing for IQL, and saw this file https://github.com/Replicable-MARL/MARLlib/blob/master/marllib/marl/algos/core/VD/iql_vdn_qmix.py, but I was unsure how to add a postprocess_fn or any other callback because it looks like a new policy is written up within this file that doesn't accept callback functions like the PPOTorchPolicy.

Do you know what I can do to add callback functionality for IQL?

from marllib.

Aequatio-Space avatar Aequatio-Space commented on September 1, 2024

@nikhil-pitta Note that JointQPolicy inherits the Policy class, which has a function postprocess_trajectory.
https://github.com/ray-project/ray/blob/55fc0710d8472a9abaf244ed6567eb3b13136531/rllib/policy/policy.py#L361-L366.
Directly overriding this function may help.

from marllib.

nikhil-pitta avatar nikhil-pitta commented on September 1, 2024

@Aequatio-Space Thanks for the response again! So now I am trying use IQL, but an issue I'm facing is that I want each of my agents to have separate policies, but I run into the exception ValueError("joint Q learning does not support individual function"), which comes from setting share_policy="individual."

This is not my desired behavior because I would like each agent to have their own policies, which is how I expected IQL to be implemented. Is there any way to get around this?

from marllib.

Aequatio-Space avatar Aequatio-Space commented on September 1, 2024

I remember joint Q learning supports share_policy=all, you can see the related logic at here.

elif exp_info["share_policy"] == "group":
groups = policy_mapping_info["team_prefix"]
if len(groups) == 1:
obs_space = Tuple([GymDict(space_obs)] * n_agents)
act_space = Tuple([space_act] * n_agents)
if not policy_mapping_info["all_agents_one_policy"]:
raise ValueError("in {}, policy can not be shared".format(map_name))
grouping = {"group_all_": agent_name_ls}
else:
raise ValueError("joint Q learning does not support group function")
elif exp_info["share_policy"] == "individual":
raise ValueError("joint Q learning does not support individual function")
else:
raise ValueError("wrong share_policy {}".format(exp_info["share_policy"]))

Try to adapt the code under this setting.

from marllib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.