Repository navigation
[Tasks] Start Shadow handover episodes from a random hand and add an opt-in action-rate penalty - #8557
Conversation
Since the handover alternates its goal between the hands, the SKRL MAPPO configuration without an entropy bonus learns the first transfer and then holds the object (about 0.86 goals per episode across eight seeds on the pre-merge branch). Each actor explores only its own hand's actions, and without an entropy bonus the two never find the return pass. An entropy bonus of 0.02 lets default training alternate like RSL-RL does, keeping the separate actor and centralized critic.
Replace the MAPPO entropy bonus with two Direct-env changes. Always starting with the object in the right hand gave every policy only the right-to-left transfer to learn first, and the entropy bonus that worked around it pinned the policy noise at its 7.39 cap, so trained policies drove every joint to its limit. A random start hand lets each episode begin with either transfer, so the develop agent config learns both, and a small penalty on action changes smooths the motion. HandoverGoal draws the first goal side itself when randomize_start is set; the environment reads it to place the object in the other hand.
|
run-ci |
[Medium impact] Adds randomization and penalty features to a robot handover task. The PR appears safe to merge with the penalty disabled, with non-blocking fixes needed for action history and test coverage. FindingsSummaryThe Direct handover task now randomly chooses the starting hand and puts the first goal at the other hand. It also adds an optional per-hand penalty for action changes.
Acknowledged by Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Reset selected environments] --> B[Choose first goal hand]
B --> C[Place object in opposite hand]
C --> D[Reset both hands]
D --> E[Apply policy actions]
E --> F[Reward distance minus optional action-change penalty]
F --> G{Goal reached enough times?}
G -- Yes --> H[Switch goal hand]
G -- No --> E
H --> E
Reviews (1) · Last reviewed commit: "Disable the Shadow handover action chang..." · Reviewed by Greptile |
| prev = getattr(self, "actions", None) | ||
| self._action_rate = { | ||
| agent: torch.zeros(self.num_envs, device=self.device) | ||
| if prev is None | ||
| else torch.sum(torch.square(act - prev[agent]), dim=-1) |
There was a problem hiding this comment.
New episodes inherit old penalties
With action_rate_penalty_scale enabled, the first action after a drop or timeout is compared with the last action from the previous episode. Neither _reset_idx clears self.actions, so the first reward includes a penalty for an unrelated movement before the reset. Clear the previous actions for reset environments, or skip this penalty on their first step.
Knowledge Base Used: Direct reinforcement learning tasks
There was a problem hiding this comment.
Fixed in be444a5. The previous actions are now owned buffers created in __init__; _reset_idx marks each episode's start and that step's action rate is zeroed, so a new episode is never penalized against the previous one. A probe with scale 1e-3 (actions 0.5, 0, reset env 0, 0.5) gives rates [0, 0], [5, 5], [0, 5].
| goal = HandoverGoal(poses, (0.0, 0.0, 0.0), randomize_start=True) | ||
| torch.manual_seed(0) | ||
| goal.reset(slice(None)) | ||
| assert 0 < int(goal.left.sum()) < num_envs | ||
| torch.testing.assert_close(goal.position[:, 0], goal.left.float()) |
There was a problem hiding this comment.
Random object starts lack coverage
The new test checks only HandoverGoal, while the existing environment test explicitly disables randomize_start_hand. Nothing checks the new object placement in _reset_idx, so reversing the selected hand or breaking the mirror could pass every test here. Add an environment test that covers both starting hands and resets only some environments. Check that the object starts opposite its goal and untouched environments stay unchanged.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Added test_handover_random_start_places_object_opposite_first_goal in be444a5 for both handover tasks with the default random start: 16 envs, each object starts at the hold point of the hand opposite its goal, and both hands occur. Disabling the random draw turns both cases red.
There was a problem hiding this comment.
Isaac Lab Review Bot
Needs attention: Scope and over-engineering (1), Compatibility and deprecation (1), Implementation (2), Style consistency (1). Other reviewed categories look good.
- PR description: The body matches the diff, but remove the separate penalty scope or name it in the title, and add exact revisions, commands, training environment counts, and action-change metric details.
- Design and architecture: Architecture looks good.
- Scope and over-engineering: Minimal implementation: extend HandoverGoal, HandoverEnv._reset_idx, and HandoverEnvCfg; no source modules were added. Delete the default-off penalty field, state, reward path, and .added fragment; keep random goal selection, mirrored reset, changed/minor fragments, and focused test. Replace with one smaller PR: those three owners, changelog fragments, and test_handover_env.py, validated at helper and Direct reset boundaries.
- API: API changes look good.
- Compatibility and deprecation: Breaking changes: defaulting randomize_start_hand to true changes registered-task resets and invalidates published checkpoints without deprecation; keep false for one release and warn before flipping.
- Implementation: Action-rate state crosses episode resets and runs while disabled, causing incorrect first-step penalties and needless per-step work; initialize and clear it explicitly, and gate computation.
- Style consistency: HandoverGoal.left violates the required member order by following update; move the property before public instance methods.
- Test quality: Test quality looks good.
Significant concerns. Posted 5 inline findings.
Automated review; human maintainers own approval decisions.
| torch.where(self._left.unsqueeze(-1), self._positions[1], self._positions[0], out=self.position) | ||
| return switched | ||
|
|
||
| @property |
There was a problem hiding this comment.
🟡 Warning · Style Consistency — Property placed after instance method
The contribution guide orders properties before public instance methods, but left sits between update and reset. Move it above update.
| """Start a new episode with the left-hand goal and no success steps or transfers.""" | ||
| """Start a new episode with no success steps or transfers, its first goal at the left or a random hand.""" | ||
| index_fill_(self._left, env_ids, True) | ||
| if self._randomize_start: |
There was a problem hiding this comment.
🟡 Warning · Implementation — Redundant fill overwritten by random draw
With randomize_start, index_fill_ writes True only to be overwritten, and self._left[env_ids].shape gathers just to read a shape. Make the fill the else branch.
There was a problem hiding this comment.
Fixed in be444a5: the draw and the fill are now an if/else, and the draw no longer gathers _left to read its shape.
| self.y_unit_tensor = torch.tensor([0, 1, 0], dtype=torch.float, device=self.device).repeat((self.num_envs, 1)) | ||
|
|
||
| def _pre_physics_step(self, actions: dict[str, torch.Tensor]) -> None: | ||
| prev = getattr(self, "actions", None) |
There was a problem hiding this comment.
🟡 Warning · Implementation — Action-rate state lacks owner and gating
Read via a getattr default, never cleared on reset so each episode's first step is penalized across the boundary, and computed even when the scale is zero. Initialize, clear, and gate it.
There was a problem hiding this comment.
Fixed in be444a5: the buffers are created in __init__, cleared at each episode's start in _reset_idx, and nothing is computed when the scale is 0 (the default).
| """Cumulative steps inside the success distance required to switch goals; must be positive.""" | ||
| goal_position_offset: tuple[float, float, float] = GOAL_POSITION_OFFSET | ||
| """Shared goal offset in each hand's local root frame [m], resolved once at initialization.""" | ||
| randomize_start_hand: bool = True |
There was a problem hiding this comment.
🟡 Warning · Compatibility — Default flip changes shipped task behavior
The registered task's default reset changes under the same ID and invalidates the published checkpoints; a changelog note is not a transition. Keep the fixed default for one release with a FutureWarning.
There was a problem hiding this comment.
Intentional: the fixed start is the defect this PR fixes (SKRL MAPPO never learns the return pass), so the random start is the default for every library. The PR is marked as a breaking change, randomize_start_hand=False restores the previous start, and the published checkpoints will be replaced.
| """Start each episode with the object in a random hand, the first goal at the other; else always right to left.""" | ||
| # reward-related scales | ||
| dist_reward_scale = 20.0 | ||
| action_rate_penalty_scale: float = 0.0 |
There was a problem hiding this comment.
🟡 Warning · Scope Complexity — Default-off penalty is separate scope
action_rate_penalty_scale ships disabled and is unrelated to the random-start fix; deleting the field, _action_rate bookkeeping, reward subtraction, and .added fragment leaves the stated behavior intact. Ship it separately with reward validation.
There was a problem hiding this comment.
Kept in this PR on purpose: it is part of the same handover training study, opt-in, and measured (results in the PR description). The PR title now names it.
|
run-ci |
|
run-ci |
Description
Since the Shadow Hand handover alternates its goal between the hands (#8361), every episode starts with the object in the right hand, so the right-to-left transfer is always learned first and the return pass has to be discovered from there. SKRL MAPPO with the shipped configuration never discovers it and holds the object after the first transfer.
This PR changes both handover tasks (
Isaac-Shadow-Handover-DirectandIsaac-Shadow-Handover) for every library:randomize_start_hand(defaultTrue): each episode starts with the object in a random hand and the first goal at the other, so both transfers are learned from the start.HandoverGoal(randomize_start=True)draws the first goal side.hold_position_offset, renamed from the Directgoal_position_offsetand the command'sposition_offset), 3 cm closer to the palm than before.HandoverGoal.start_positiongives that point to both tasks.HandoverCommand._resample_command, after the goal reset, instead of thereset_objectevent, so it starts in the hand chosen by the goal command.action_rate_penalty_scale(Direct, default0.0, opt-in): each hand's reward is reduced byscale * sum((a_t - a_{t-1})^2). At1e-3it smooths the motion but slowed RSL-RL learning (one of three Kit PhysX seeds learned only one direction), so it is off by default.Results
One L40 per run, each library's default agent configuration and training length. Develop is one seed.
Isaac-Shadow-Handover-Direct: each final checkpoint is scored with the policy mean action over 900 policy steps x 50 environments (about 100 episodes). A run has learned when both transfer directions complete; drops are non-timeout terminations, lower is better.Starting at the hold point lowers the drops of random start alone on every library and backend (summed over the three seeds, previous start pose vs this PR: SKRL 22 vs 15, 90 vs 44, 16 vs 1; RSL-RL 39 vs 32, 92 vs 42, 27 vs 4 for Kit PhysX, OvPhysX, Newton). In playback every learned policy hands the object back and forth in both directions. The action-rate penalty was measured with the previous start pose: it cuts the squared action change about 13-31x for RSL-RL; joint-velocity and joint-acceleration penalties were also tried and, at gains that visibly smoothed the motion, left some SKRL seeds dropping the object every episode.
Isaac-Shadow-Handover(RSL-RL): training curves, mean over the last 5% of training. A drop ends the episode when the object falls below 0.24 m; every other episode times out.All nine runs learned; a right-hand-only start with the hold point gave the same results within seed noise.
The published Direct handover checkpoints were trained with the fixed start and need to be replaced with checkpoints trained on this configuration.
Type of change
Release backport
developChecklist
pre-commitchecks withuv run isaaclab --formatsource/<pkg>/changelog.d/for every touched package (do not editCHANGELOG.rstor bump package versions — CI handles that)CONTRIBUTORS.mdor my name already exists there