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

[RLlib] - Enable multi-learner setup for hybrid stack BC #46436

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion rllib/algorithms/bc/bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ def training_step(self) -> ResultDict:
self._counters[NUM_ENV_STEPS_SAMPLED] += len(train_batch)

# Updating the policy.
train_results = self.learner_group.update_from_batch(batch=train_batch)
train_results = self.learner_group.update_from_batch(
batch=train_batch.as_multi_agent(
module_id=list(self.config.policies)[0]
)
)
# TODO (sven): Use metrics API as soon as we moved to new API stack
# (from currently hybrid stack).
# self.metrics.log_dict(
Expand Down
13 changes: 10 additions & 3 deletions rllib/policy/sample_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ray.rllib.utils.framework import try_import_tf, try_import_torch
from ray.rllib.utils.torch_utils import convert_to_torch_tensor
from ray.rllib.utils.typing import (
ModuleID,
PolicyID,
TensorType,
SampleBatchType,
Expand Down Expand Up @@ -907,14 +908,20 @@ def get(self, key, default=None):
return default

@PublicAPI
def as_multi_agent(self) -> "MultiAgentBatch":
"""Returns the respective MultiAgentBatch using DEFAULT_POLICY_ID.
def as_multi_agent(self, module_id: Optional[ModuleID] = None) -> "MultiAgentBatch":
Copy link
Contributor

Choose a reason for hiding this comment

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

perfect!

"""Returns the respective MultiAgentBatch

Note, if `module_id` is not provided uses `DEFAULT_POLICY`_ID`.

Args;
module_id: An optional module ID. If `None` the `DEFAULT_POLICY_ID`
is used.

Returns:
The MultiAgentBatch (using DEFAULT_POLICY_ID) corresponding
to this SampleBatch.
"""
return MultiAgentBatch({DEFAULT_POLICY_ID: self}, self.count)
return MultiAgentBatch({module_id or DEFAULT_POLICY_ID: self}, self.count)

@PublicAPI
def __getitem__(self, key: Union[str, slice]) -> TensorType:
Expand Down