#3863·lerobot

Relative actions assume state[:action_dim] aligns with action — support explicit/name-based state→action mapping

Author: HariKrishnan06082kCreated Jun 23, 2026Updated Sep 27, 2026
Labelsbugenhancementpoliciesdatasetconfigurationprocessortrainingevaluation

Ticket Type

Feature Request / Improvement

Environment & System Info

bash
- LeRobot version: 0.5.2
- Platform: Linux-6.14.0-1020-oem-x86_64-with-glibc2.39
- Python version: 3.12.13
- Huggingface Hub version: 1.20.1
- Transformers version: 5.5.4
- Datasets version: 4.8.5
- Numpy version: 2.2.6
- FFmpeg version: 6.1.1-3ubuntu5
- PyTorch version: 2.10.0+cu128
- Torchcodec version: 0.10.0
- Is PyTorch built with CUDA support?: True
- Cuda version: 12.8
- GPU model: NVIDIA RTX 6000 Ada Generation
- Using GPU in script?: <fill in>
- lerobot scripts: ['lerobot-annotate', 'lerobot-calibrate', 'lerobot-dataset-viz', 'lerobot-edit-dataset', 'lerobot-eval', 'lerobot-find-cameras', 'lerobot-find-joint-limits', 'lerobot-find-port', 'lerobot-imgtransform-viz', 'lerobot-info', 'lerobot-record', 'lerobot-replay', 'lerobot-rollout', 'lerobot-setup-can', 'lerobot-setup-motors', 'lerobot-teleoperate', 'lerobot-train', 'lerobot-train-tokenizer']

Description

Summary

RelativeActionsProcessorStep (and the underlying to_relative_actions / to_absolute_actions) compute the relative-action base as state[..., :action_dim]. This silently assumes that the first action_dim channels of observation.state are positionally aligned with action (i.e. state[i] is the quantity that action[i] controls). That assumption only holds when the state is a prefix-aligned copy of the action, and breaks for almost any realistic observation layout.

Goal / use case

Make relative actions work correctly when observation.state is not a prefix copy of the action. This is the common case in real manipulation:

  • Interleaved [pos, vel] per joint — e.g. state = [j0p, j0v, j1p, j1v, ..., j5p, j5v, grip] (13) but action = [j0p..j5p, grip] (7). The relative base must pull the position channels [0, 2, 4, 6, 8, 10, 12], not state[:7] (which mixes in velocities and the wrong joints).
  • State augmented with force/torque, EE pose, contact flags, or joint currents — any extra proprioceptive channel shifts the alignment and corrupts the base.

When the layout doesn't match the implicit prefix assumption, the wrong state columns are subtracted (preprocess) and added back (postprocess), so the model trains on corrupted relative targets and eval produces wrong absolute actions — with no error and no warning.

Proposed change

Add an optional, explicit/name-based mapping from action dims to state columns, defaulting to the current state[:action_dim] behavior so it is fully backward compatible:

  • state_action_index_map: list[int] | None — entry i is the observation.state column that action dim i is relative to.
  • state_names / state_feature_names — when given alongside action_feature_names (and no explicit map), resolve the mapping by matching names.
  • A validation guard that raises on length/range mismatch instead of silently producing wrong offsets.

Used symmetrically by RelativeActionsProcessorStep (preprocess) and AbsoluteActionsProcessorStep (postprocess) so train and eval stay consistent.

Notes

  • Backward compatible: with no map and no names, behavior is identical to today.
  • I have a working implementation and can open a PR.

Context & Reproduction

Where it happens

src/lerobot/processor/relative_action_processor.py — both helpers hardcode the relative base as the first action_dim channels of the state:

python
def to_relative_actions(actions, state, mask):
    ...
    state_offset = state[..., :dims] * mask_t   # <-- assumes prefix alignment
    actions[..., :dims] -= state_offset
    return actions

def to_absolute_actions(actions, state, mask):
    ...
    state_offset = state[..., :dims] * mask_t   # <-- same assumption on the way back
    actions[..., :dims] += state_offset
    return actions

RelativeActionsProcessorStep.__call__ caches observation.state and calls to_relative_actions; AbsoluteActionsProcessorStep.__call__ reuses the cached state via to_absolute_actions. Neither offers a way to map an action dim to a non-contiguous / non-prefix state channel, and there is no validation when the layouts don't line up.

Minimal reproduction

State is interleaved [pos, vel] per joint + gripper (13), action is [j0p..j5p, grip] (7). The correct relative base is the position channels [0, 2, 4, 6, 8, 10, 12].

python
import torch
from lerobot.processor.relative_action_processor import (
    to_relative_actions, to_absolute_actions,
)

# state: [j0p, j0v, j1p, j1v, ..., j5p, j5v, grip]  (13)
state  = torch.tensor([[10., 0.1, 20., 0.2, 30., 0.3,
                        40., 0.4, 50., 0.5, 60., 0.6, 99.]])
# action: [j0p..j5p, grip]  (7), absolute joint targets
action = torch.tensor([[11., 22., 33., 44., 55., 66., 7.]])
mask   = [True] * 6 + [False]          # gripper kept absolute

# --- current behaviour: base = state[:7] = [j0p, j0v, j1p, j1v, j2p, j2v, j3p]
rel = to_relative_actions(action, state, mask)
print(rel.tolist())
# [[1.0, 21.9, 13.0, 43.8, 25.0, 65.7, 7.0]]
#        ^^^^        ^^^^        ^^^^  velocities / wrong joints leak into the base

Expected (base = position channels [0,2,4,6,8,10,12]): clean per-joint offsets [[1, 2, 3, 4, 5, 6, 7]]. Because the base is wrong, the model trains on corrupted relative targets, and at inference to_absolute_actions adds the same wrong base back — the policy ends up commanding the wrong joint positions (in our case, consistently missing grasps). No error or warning is raised.

Proposed fix (working locally)

Add an optional state_index_map so the base is selected explicitly, defaulting to the current prefix behaviour:

python
def _state_base_offset(state, mask_t, state_index_map):
    dims = mask_t.shape[0]
    if state_index_map is not None:
        idx = torch.as_tensor(list(state_index_map), dtype=torch.long, device=state.device)
        base = state.index_select(-1, idx)        # explicit per-action-dim base
    else:
        base = state[..., :dims]                  # legacy prefix (unchanged)
    return base * mask_t

Round-trip with the map is exact:

python
idx_map = [0, 2, 4, 6, 8, 10, 12]
rel  = to_relative_actions(action, state, mask, idx_map)   # [[1,2,3,4,5,6,7]]
back = to_absolute_actions(rel, state, mask, idx_map)      # == action
assert torch.allclose(back, action)

RelativeActionsProcessorStep / AbsoluteActionsProcessorStep expose this via:

  • state_action_index_map: list[int] | None — explicit action→state column map.
  • state_names + action_feature_names — resolve the map by matching names when no explicit map is given.
  • A guard that raises on length/range mismatch instead of silently mis-aligning.

For pi0 it's surfaced as PI0Config.relative_state_index_map (and state_feature_names), threaded through make_pi0_pre_post_processors. Fully backward compatible: with no map and no names, behaviour is identical to today.

Relevant logs or stack trace

bash

Checklist

  • I have searched existing tickets to ensure this isn't a duplicate.
  • I am using the latest version of the main branch.
  • I have verified this is not an environment-specific problem.

Additional Info / Workarounds

Production-level fix (proposed for upstream)

Name-based alignment as the default, with an explicit index map as an override. Because every action dim and every state channel already carry names in the dataset metadata, the base for action dim i should be resolved by matching names, not by position:

  • Default: match action_feature_names[i] to the identically named observation.state channel (e.g. action joint_0.pos → state joint_0.pos). Dims with no matching state channel (or listed in exclude_joints, like the gripper) stay absolute.
  • Override: an explicit state_action_index_map for layouts where names are unavailable or ambiguous.
  • Guard: raise on length/range mismatch so misalignment fails loudly instead of silently corrupting targets.

This generalizes to any observation layout — interleaved [pos, vel], or state augmented with force/torque, EE pose, contact flags, joint currents — without per-dataset hacks. The current state[:action_dim] becomes the special case where names happen to line up by position.

Local fix / workaround (works today)

If you can't wait for upstream, the minimal change is to make the relative base selectable and pass the position indices explicitly.

1. Make the base selectable (relative_action_processor.py):

python
def _state_base_offset(state, mask_t, state_index_map):
    dims = mask_t.shape[0]
    if state_index_map is not None:
        idx = torch.as_tensor(list(state_index_map), dtype=torch.long, device=state.device)
        base = state.index_select(-1, idx)   # explicit per-action-dim base
    else:
        base = state[..., :dims]             # legacy prefix (unchanged)
    return base * mask_t

to_relative_actions / to_absolute_actions take an optional state_index_map; RelativeActionsProcessorStep / AbsoluteActionsProcessorStep hold and forward it (explicit map, or name-resolved from state_names + action_feature_names).

2. Surface it on the policy config (PI0Config):

python
relative_state_index_map: list[int] | None = None
state_feature_names: list[str] | None = None

threaded into make_pi0_pre_post_processors → RelativeActionsProcessorStep.

3. Set the map for your dataset. For an interleaved [j0p, j0v, ..., j5p, j5v, grip] (13) state with [j0p..j5p, grip] (7) action:

yaml
# training config
policy:
  use_relative_actions: true
  relative_exclude_joints: ["gripper"]
  relative_state_index_map: [0, 2, 4, 6, 8, 10, 12]   # position channels only

Workaround without touching the processor (if you only need it to work, not to fix the library): re-layout the dataset so the first action_dim state channels are the absolute action quantities (e.g. store observation.state as [j0p..j5p, grip, j0v..j5v, ...] instead of interleaved). Then the legacy state[:action_dim] prefix is already correct and no code change is needed. This avoids the bug but requires regenerating/re-normalizing the dataset.

Important caveat

This only affects how relative actions are computed — it is a train/eval-consistency issue. A checkpoint trained with the wrong base learned against corrupted targets, so fixing the map requires retraining; it cannot be patched at eval time alone. Eval already builds its processors from policy.config, so once retrained with the correct relative_state_index_map, the eval side picks it up automatically.

Verification

Round-trip is exact with the map, and the legacy path is unchanged when it's unset:

python
idx_map = [0, 2, 4, 6, 8, 10, 12]
rel  = to_relative_actions(action, state, mask, idx_map)   # [[1,2,3,4,5,6,7]]
back = to_absolute_actions(rel, state, mask, idx_map)
assert torch.allclose(back, action)                         # passes