[Doc] Document multi-agent _step TensorDict layout - #4232
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4232
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 15 Unclassified FailuresAs of commit 7ac9875 with merge base 1d3de3d ( UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Clarify that collectors and replay buffers preserve nested keys without plural-key arguments, and direct users to group policies and per-group loss key configuration.
Construct the placeholder reset observations on self.device so the documented environment satisfies EnvBase placement guarantees when callers pass device=.
vmoens
left a comment
There was a problem hiding this comment.
The TwoTeamEnv example runs and passes check_env_specs. Two statements in the new layout contract do not match the supported environment/spec behavior.
|
|
||
| * **Shared (root).** ``"done"``, ``"terminated"`` and (if used) | ||
| ``"truncated"`` at the root, shape ``(*batch, 1)``. This is the signal | ||
| TorchRL uses to reset the environment. A native env must write at least |
There was a problem hiding this comment.
[P2] Do not require a root done flag for every native env
EnvBase also supports environments whose done/terminated/reset keys are entirely nested; NestedCountingEnv(nest_done=True) and the existing nested StepCounter tests exercise that contract. Root shared flags are the convention for this example and some wrappers, not a universal native-env requirement. Qualify this paragraph so implementers are not told to add a second termination hierarchy unnecessarily.
There was a problem hiding this comment.
Addressed in 7ac9875. The paragraph now states that root done/terminated/truncated is the convention used by the TwoTeamEnv sketch and wrappers such as VMAS, not a native-env requirement. EnvBase already resets from nested done/_reset keys (NestedCountingEnv(nest_done=True, has_root_done=False) and the nested StepCounter tests), so the text no longer tells implementers to add a second termination hierarchy.
| * **One group per agent.** With | ||
| :attr:`~torchrl.envs.MarlGroupMapType.ONE_GROUP_PER_AGENT` each group | ||
| has a single agent, so ``(agent_name, "done")`` has shape | ||
| ``(*batch, 1)`` and there is no extra agent dimension. |
There was a problem hiding this comment.
[P2] Keep the singleton agent dimension for one-agent groups
ONE_GROUP_PER_AGENT changes group membership, not the group TensorDict layout. PettingZoo constructs each group Composite with shape [n_agents] and each done leaf with [n_agents, 1], so a one-agent group still has trailing shape [1, 1] (or [*batch, 1, 1] with an env batch). Saying there is no agent dimension will make readers build incompatible specs/policies. Retain that singleton dimension in the documented shape.
There was a problem hiding this comment.
Addressed in 7ac9875. ONE_GROUP_PER_AGENT is documented as a grouping change only. PettingZoo still builds each group Composite with shape [n_agents] and each done leaf with [n_agents, 1], so a one-agent group keeps trailing shape [*batch, 1, 1]. The previous "no extra agent dimension" wording is gone.
Root done flags are a convention, not a native-env requirement, and ONE_GROUP_PER_AGENT keeps the singleton agent dimension.
|
Updated the layout contract in 7ac9875 for the two CHANGES_REQUESTED items:
The TwoTeamEnv sketch is unchanged and still uses shared root done flags. |
vmoens
left a comment
There was a problem hiding this comment.
Re-reviewed 7ac9875. The text now allows nested-only done specs instead of requiring a root done universally, and the one-group-per-agent example retains the required singleton done dimension.
I reran the TwoTeamEnv example and check_env_specs successfully. The revised examples and shape descriptions are consistent. No remaining actionables.
Description
Extends
docs/source/reference/envs_multiagent.rstwith a Multiple agent groups section so a nativeEnvBase._step()is documented beyond the single"agents"group used by VMAS.The new section:
_step()must write for several groups ("red"/"blue", or"agents"/"adversaries"): per-group nested tensordicts with a stacked agent dimension.TwoTeamEnv(EnvBase)sketch (not a PettingZoo wrapper) that reads(group, "action")and returns observations, rewards, and shared done flags without a"next"wrapper.The existing VMAS single-group example is kept as the simple case. The intro now treats
"agents"as one group name, not a required key.Code example
Example return value from a custom
_step: two groups with different agent counts and shared environment termination. EnvBase.step adds the outer"next"key.Motivation and Context
close #2425
The current multi-agent env page only documented the single
"agents"group. Matteo Bettini agreed it needed a more general multi-group description; a later comment pointed at the competitive DDPG tutorial rollout as the pattern.Types of changes
Checklist