Skip to content

[Feature] InterventionModule for human or scripted takeovers - #4772

Open
theap06 wants to merge 4 commits into
pytorch:mainfrom
theap06:pr/intervention-module
Open

theap06 wants to merge 4 commits into
pytorch:mainfrom
theap06:pr/intervention-module

Conversation

@theap06

@theap06 theap06 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds InterventionModule, a post-policy module used as TensorDictSequential(actor, InterventionModule(intervener)) like EGreedyModule: where the intervener raises its flag its action is executed, and the policy's action and the flag are kept for replay. It works for continuous and scalar discrete actions, and it is skipped under deterministic, mode or mean exploration, so evaluation never includes help.

Motivation and Context

Human-in-the-loop RL such as HIL-SERL (arXiv 2410.21845) stores the executed action and an intervention flag, and an env inverse transform cannot do this because it runs on a copy.

Stack (merge in this order; #4771, #4772, #4773 and #4799 are independent of each other and each is based on main, #4774 needs all four):

  1. [BugFix] Run ModuleTransform on reset when it declares observations #4771 [BugFix] Run ModuleTransform on reset when it declares observations
  2. [Feature] InterventionModule for human or scripted takeovers #4772 [Feature] InterventionModule for human or scripted takeovers (this PR)
  3. [Feature] Mixed-source replay with ReplayBufferEnsemble #4773 [Feature] Mixed-source replay with ReplayBufferEnsemble
  4. [Feature] SACLoss backup_entropy option #4799 [Feature] SACLoss backup_entropy option
  5. [Algorithm] HIL-SERL in simulation #4774 [Algorithm] HIL-SERL in simulation
  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

  • New feature (non-breaking change which adds core functionality)
  • Documentation (update in the documentation)

Checklist

  • I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

A post-policy module, composed as TensorDictSequential(actor,
InterventionModule(intervener)) like EGreedyModule. The intervener runs on
every exploration step and proposes an action plus a take-over flag. Where
the flag is set the intervener's action is executed (optionally clipped to a
spec); elsewhere the policy's action is used unchanged. The policy's action
and the flag are saved so replay can route intervened steps. In
deterministic mode the intervener is not called. Used by HIL-SERL
(arXiv 2410.21845).
@pytorch-bot

pytorch-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4772

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures, 2 Unrelated Failures

As of commit ff99be7 with merge base df1db3d (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 23, 2026
@github-actions github-actions Bot added Feature New feature Documentation Improvements or additions to documentation Modules Integrations/torch_geometric Integrations labels Nov 23, 2026
@theap06 theap06 mentioned this pull request Nov 23, 2026
4 of 6 tasks
…policy dtype

Without this, removing the dtype cast passed every InterventionModule test.
…one flag per action

The intervener's outputs were listed in out_keys but are not written in deterministic mode, so a strict select of the policy's outputs failed during evaluation. The take-over flag was also reshaped to the tensordict's batch size, which broke actions with extra leading dims such as one action per agent; it now follows the action's shape.
… on the policy's device

The flag's batch shape is now the action's shape without its event dimension
only when the action has one, so a discrete action of shape [B] works in both
exploration and evaluation. The take-over flag is moved to the policy action's
device, the saved policy action is a copy in deterministic mode, and the
docstring says which exploration types call the intervener.
@theap06
theap06 marked this pull request as ready for review November 29, 2026 09:13

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Documentation Improvements or additions to documentation Feature New feature Integrations/torch_geometric Integrations Modules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant