Skip to content

[Tasks] Start Shadow handover episodes from a random hand and add an opt-in action-rate penalty - #8557

Merged
ooctipus merged 12 commits into
isaac-sim:mainfrom
hujc7:jichuanh/handover-mappo-entropy
Oct 19, 2026
Merged

ooctipus merged 12 commits into
isaac-sim:mainfrom
hujc7:jichuanh/handover-mappo-entropy

Conversation

@hujc7

@hujc7 hujc7 commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

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-Direct and Isaac-Shadow-Handover) for every library:

  • randomize_start_hand (default True): 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.
  • The object starts at the holding hand's hold point, the same hand-local offset used as the goal (hold_position_offset, renamed from the Direct goal_position_offset and the command's position_offset), 3 cm closer to the palm than before. HandoverGoal.start_position gives that point to both tasks.
  • The manager-based task now places the object in HandoverCommand._resample_command, after the goal reset, instead of the reset_object event, so it starts in the hand chosen by the goal command.
  • action_rate_penalty_scale (Direct, default 0.0, opt-in): each hand's reward is reduced by scale * sum((a_t - a_{t-1})^2). At 1e-3 it 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.

Library Physics develop (fixed start) this PR, seeds 42 / 43 / 44
SKRL MAPPO Kit PhysX not learned (holds after the first transfer) 3/3 learned, 7 / 2 / 6 drops
SKRL MAPPO OvPhysX learned, 39 drops 3/3, 14 / 7 / 23
SKRL MAPPO Newton not learned 3/3, 0 / 1 / 0
RSL-RL Kit PhysX learned, 8 3/3, 10 / 9 / 13
RSL-RL OvPhysX learned, 33 3/3, 13 / 21 / 8
RSL-RL Newton learned, 7 3/3, 0 / 2 / 2

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.

Physics develop: episodes ending in a drop / consecutive success this PR, seeds 42 / 43 / 44: drop share this PR mean
Kit PhysX 27.5% / 10.7 23.4% / 21.2% / 22.9% 22.5% / 11.7
OvPhysX 26.8% / 11.5 24.4% / 14.9% / 23.1% 20.8% / 12.1
Newton 12.0% / 12.8 8.2% / 8.9% / 6.4% 7.8% / 13.0

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

  • Breaking change (existing functionality will not work without user modification)

Release backport

  • Backport this pull request to the active release branch after it merges into develop

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with uv run isaaclab --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have validated the changed behavior with focused coverage and applied the test-audit criteria to any test changes
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump package versions — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

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.
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Oct 14, 2026
hujc7 added 3 commits October 15, 2026 14:27
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.
@hujc7 hujc7 changed the title [Tasks] Train Shadow handover MAPPO with an entropy bonus so it alternates [Tasks] Start Shadow handover episodes from a random hand and penalize action changes Oct 15, 2026
@hujc7 hujc7 changed the title [Tasks] Start Shadow handover episodes from a random hand and penalize action changes [Tasks] Start Shadow handover episodes from a random hand Oct 16, 2026
@hujc7

hujc7 commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

run-ci

@hujc7
hujc7 marked this pull request as ready for review October 16, 2026 16:39
@hujc7
hujc7 requested a review from a team October 16, 2026 16:39
@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Oct 16, 2026
@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[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.

Findings

  1. P2 New episodes inherit old penalties ▶
  2. P2 Random object starts lack coverage ▶

Summary

The 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.

  • Direct handover episodes start with the ball in either hand.
  • The Direct handover reward can penalize action changes between steps.

Acknowledged by hujc7: published fixed-start checkpoints no longer match the default and need replacement.

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
Loading

Reviews (1) · Last reviewed commit: "Disable the Shadow handover action chang..." · Reviewed by Greptile

Comment on lines +119 to +123
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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].

Comment on lines +50 to +54
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())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moved left above update in be444a5.

"""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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@hujc7

hujc7 commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator Author

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Oct 17, 2026
@hujc7 hujc7 changed the title [Tasks] Start Shadow handover episodes from a random hand [Tasks] Start Shadow handover episodes from a random hand and add an opt-in action-rate penalty Oct 17, 2026
@hujc7

hujc7 commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator Author

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Oct 17, 2026
@ooctipus
ooctipus merged commit 3a6656e into isaac-sim:main Oct 19, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants