Skip to content

[Algorithm] Add Transitive RL - #4579

Open
theap06 wants to merge 4 commits into
pytorch:mainfrom
theap06:algorithm/transitive-rl
Open

theap06 wants to merge 4 commits into
pytorch:mainfrom
theap06:algorithm/transitive-rl

Conversation

@theap06

@theap06 theap06 commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds Transitive RL (Park, Oberai, Atreya, Levine, "Transitive RL: Value Learning via Divide and Conquer", ICLR 2026, https://arxiv.org/abs/2510.22512) for offline goal-conditioned RL. The critic Q(s, a, g) lives in (0, 1] and is read as gamma^d(s, g); instead of a one-step backup, Q(s_i, a_i, s_j) is regressed toward Q(s_i, a_i, s_k) Q(s_k, a_k, s_j) through a subgoal k the dataset trajectory visited between i and j.

Validation against the reference implementation

Reference: the authors' JAX code (github.com/aoberai/trl @ adfec6f249), same hyperparameters (512x3 MLPs, batch 1024, discount 0.99, expectile 0.7, oracle distillation, rpg actor with alpha 1).

Numerical parity. On a fixed batch with identical weights, in float64: critic, oracle and actor losses match to 1e-16 relative error, gradient norms to 1e-7. The compiled + CUDA-graph update matches eager after 60 steps (2e-6 on the loss, 2e-7 on parameters).

Success rates, 1M gradient steps, 2 seeds, OGBench final score (per-seed mean of the 800k, 900k and 1M evaluations, 15 episodes x 5 tasks each):

Task TorchRL Reference (JAX) Paper
cube-single-play-oraclerep-v0 93.1 (91.1, 95.1) 88.7 (88.9, 88.4) 95
scene-play-oraclerep-v0 79.3 (71.1, 87.6) 75.3 (79.1, 71.6) 77

Both implementations land within seed spread of the paper, and of each other.

Throughput (A100-SXM4-40GB, scene-play shapes, batch 1024, it/s of sample + update):

Implementation it/s
Reference (JAX jit) 274
TorchRL eager 63
TorchRL compile + CudaGraphModule 630
TorchRL max-autotune + CudaGraphModule 686

Eager mode is Python and launch bound at these model sizes; the recipe exposes compile.compile=true compile.cudagraphs=true.

Known differences and follow-ups

  • An anchor sampled on the last record of its episode is moved one step back (documented); the reference samples anchors uniformly over non-final records, which only differs in giving penultimate records double weight.
  • Not included: flow-policy rejection-sampling extraction, mixing random and geometric policy goals (needed for the puzzle tasks), Trainer integration, and batched evaluation (scene evaluation is about a third of wall-clock).

Motivation and Context

Transitive RL is a recent offline goal-conditioned method with strong OGBench results whose two building blocks (in-trajectory subgoal sampling and a divide-and-conquer critic) are reusable beyond the paper's recipe.

  • 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)
  • Example (update in the folder of examples)

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.

…iveQLoss

Transitive RL (Park, Oberai, Atreya, Levine, ICLR 2026,
https://arxiv.org/abs/2510.22512) learns a goal-conditioned critic
Q(s, a, g) = gamma^d(s, g) with a divide-and-conquer update: Q(s_i, a_i, s_j)
is regressed toward Q(s_i, a_i, s_k) Q(s_k, a_k, s_j) for an in-trajectory
subgoal k in [i, j).

- SubgoalTriplet sample unit: expands each anchor into its state, subgoal,
  goal and policy-goal records, with geometric or uniform goal offsets
  truncated at the episode end and a per-record "step_offset" info entry.
- TransitiveQLoss: expectile-weighted BCE critic with exact gamma^offset base
  cases, optional distance re-weighting, optional oracle-representation critic
  distillation, and a reparameterized DDPG+BC actor; anchors flagged by
  validity_mask are excluded from every term.
- SubgoalTripletConfig and TransitiveQLossConfig Hydra configs, docs entries.
- sota-implementations/transitive_rl recipe on OGBench (compile + CUDA graphs
  optional), test_sota smoke entry on synthetic data, sota-check script.
@pytorch-bot

pytorch-bot Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 New Failure

As of commit 81bf4cb with merge base 264a3c2 (image):

NEW FAILURE - The following job has failed:

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 Oct 16, 2026
@github-actions github-actions Bot added new algo New algorithm request or PR Documentation Improvements or additions to documentation CI Has to do with CI setup (e.g. wheels & builds, tests...) Objectives sota-implementations/ ReplayBuffers Trainers and removed new algo New algorithm request or PR labels Oct 16, 2026
@theap06 theap06 changed the title [Algorithm] Add Transitive RL: SubgoalTriplet sample unit and TransitiveQLoss [Algorithm] Add Transitive RL Oct 16, 2026
…unit helpers

- TransitiveQLoss reduces through LossModule._reduce_loss with
  loss_mask_key defaulting to "validity_mask", replacing the custom masked
  mean and the validity_mask accepted key; masked anchors are now selected
  out rather than multiplied by zero. Critic inputs are built with
  TensorDict.select instead of a hand-assembled TensorDict.
- SampleUnit gains _check_storage, _repeat_info and _episode_boundaries,
  shared by Sequence and SubgoalTriplet instead of duplicated in both.
- Shorten the objectives_offline section, which repeated the class
  docstring.

Losses and gradients still match the JAX reference (worst relative error
1e-7), and a compiled + CUDA-graph OGBench run logs identical losses.
…recipe copy

- TransitiveQLossConfig sets _convert_="object" so a list of critic
  configs reaches TransitiveQLoss as a list rather than a ListConfig.
- TensorDictReplayBuffer reduces per-record priorities to anchors for
  SubgoalTriplet samples too, as it already did for Sequence; priorities
  were otherwise written onto subgoal and goal records.
- Document that TransitiveQLoss assumes uniform anchor sampling.
- The recipe extends the device storage from the host dataset directly
  instead of copying the dataset to the device first.
- Add ogbench to the sota-check setup.

Tests: the ordering test now also runs on a wrapped buffer whose newest
episode is still open (it does not catch a write-seam bug otherwise), the
loss config test instantiates a list of nested critic configs, and a new
test checks that a priority update lands on the anchor.
…stronger mask test

- SubgoalTriplet draws its offsets from the replay buffer's generator
  (set through generator= or set_rng) when it lives on the anchors' device,
  so seeding the buffer reproduces its batches like the other sample units.
- The recipe rejects loss.oracle_distill=false on datasets whose goals are
  oracle representations, which previously failed with a shape mismatch.
- The masking test now feeds a real flat SubgoalTriplet sample with
  single-record episodes and compares against the valid anchors indexed out
  independently; it replaces the flat-versus-unflattened test, which
  compared the loss's own reshape with itself.
- q_mean and target_mean exclude invalid anchors, oracle parameters are
  cleared for compile like the others, the actor_network docstring type
  matches its hint, a stale replay-buffer comment is corrected, and the
  test_sota override is quoted.
@theap06
theap06 marked this pull request as ready for review October 16, 2026 08:52

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

CI Has to do with CI setup (e.g. wheels & builds, tests...) 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 new algo New algorithm request or PR Objectives ReplayBuffers sota-implementations/ Trainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant