opensi·si

SARM (Stage-Aware Reward Modeling) is a video-based reward modeling framework for long-horizon robot manipulation tasks. This guide covers how to train SARM reward models and…

SARM

SARM (Stage-Aware Reward Modeling) is a video-based reward modeling framework for long-horizon robot manipulation tasks. This guide covers how to train SARM reward models and optionally use them with Reward-Aligned Behavior Cloning (RA-BC).

Paper: SARM: Stage-Aware Reward Modeling for Long Horizon Robot Manipulation

Why Reward Models?

Standard behavior cloning treats all demonstration frames equally, but real-world robot datasets are messy. They contain hesitations, corrections, and variable-quality trajectories. Reward models solve this by learning a generalizable notion of task progress from demonstrations: given video frames and a task description, they predict how close the robot is to completing the task (0→1). This learned "progress signal" can be used in multiple ways, two promising applications are: (1) weighted imitation learning (RA-BC), where high-progress frames receive more weight during policy training, and (2) reinforcement learning, where the reward model provides dense rewards for online or offline policy improvement.

Overview

SARM has following features:

  1. Stage-aware architecture: Jointly predicts the high-level task stage and fine-grained progress within each stage
  2. Subtask annotations: Uses natural language subtask annotations to derive consistent progress labels
  3. Temporal proportions: Computes dataset-level priors (α̅_k) for each subtask to normalize progress across variable-length demonstrations

SARM trains on a compact stage+tau target for each frame:

  • stage: integer stage index k ∈ {0, ..., K-1}
  • τ (tau): within-stage progress τ ∈ [0, 1]
  • target encoding: y = k + τ (this is what the dataset processor produces)

At inference time (and in downstream RA-BC), SARM converts the raw k + τ value into a normalized progress in [0, 1] using dataset-level temporal proportions α̅_k (stored in meta/temporal_proportions_*.json).

This matches Formula (2) from the paper:

progress_t = P_{k-1} + α̅_k × τ_t

Where:

  • τ_t = (t - s_k) / (e_k - s_k) is within-subtask normalized time
  • P_{k-1} is cumulative prior (sum of previous subtask proportions)
  • α̅_k is the temporal proportion for subtask k

This ensures identical task states map to consistent progress values, even across demonstrations of different lengths.

Inputs and Targets (What the new code expects)

SARM is trained through its processor (src/lerobot/rewards/sarm/processor_sarm.py), which:

  • Encodes images and task text with CLIP (ViT-B/32) into video_features and text_features
  • Pads/truncates robot state into state_features (up to max_state_dim)
  • Builds targets as sparse_targets (and dense_targets in dense_only/dual) using the stage+tau encoding y = k + τ
  • Masks rewind frames using a per-sample lengths tensor (rewind is a training-time augmentation)

At minimum, each training sample needs:

  • task (string): task description
  • reward_model.image_key images and reward_model.state_key states from the dataset

Annotation Modes

You can choose from 3 annotation modes that determine how progress labels are computed:

Mode Annotations Required Heads Use Case
single_stage None Sparse only Simple tasks, quick experiments, no VLM needed
dense_only Dense (VLM) Dual (sparse auto-generated) Detailed subtask tracking without defining high-level stages
dual Sparse + Dense (VLM) Dual Full SARM paper setup with both granularities

Mode Details

single_stage

No annotations required. The entire episode is treated as a single stage called "task", and progress is linear from 0 to 1 over the episode duration.

  • Sparse head: 1 stage ("task"), linear progress
  • Dense head: Not used
  • Best for: Simple tasks, quick experiments, or when VLM annotation is not available

Set Up Your Environment

  1. Install LeRobot by following our Installation Guide.
  2. Install SARM dependencies by running:
pip install -e ".[sarm]"

Workflow:

1. Train SARM → 2. Visualize predictions → 3. (Optional) Train policy with RA-BC

dense_only

Only dense (fine-grained) annotations from a VLM. The sparse head automatically uses a single "task" stage covering the full episode, while the dense head learns detailed subtask progression.

  • Sparse head: 1 stage ("task"), linear progress (auto-generated)
  • Dense head: Multiple fine-grained stages from VLM annotations
  • Best for: When you want detailed subtask tracking but don't need to define high-level stages

Workflow:

1. Annotate (dense) → 2. Verify → 3. Train SARM → 4. Visualize → 5. (Optional) Train policy with RA-BC

dual

Both sparse and dense annotations from VLM. Full dual-head mode as described in the SARM paper, with both high-level (sparse) and fine-grained (dense) stage predictions.

  • Sparse head: High-level stages from VLM annotations
  • Dense head: Fine-grained stages from VLM annotations
  • Best for: Complex multi-stage tasks where both granularities are useful

Workflow:

1. Annotate (sparse+dense) → 2. Verify → 3. Train SARM → 4. Visualize → 5. (Optional) Train policy with RA-BC

Step 1: Subtask Annotation

single_stage

No annotation required! Skip this step entirely. The model will use the episode's task description and compute linear progress automatically.

dense_only

Generate dense (fine-grained) annotations only using a VLM. The sparse stage will be auto-generated.

python src/lerobot/data_processing/sarm_annotations/subtask_annotation.py \
  --repo-id your-username/your-dataset \
  --dense-only \
  --dense-subtasks "Bring robot arms up from starting position,Grab near side and do 1st fold,Grab side and do 2nd fold,Grab side and do 3rd fold to finish folding" \
  --video-key observation.images.base \
  --num-workers 4 \
  --push-to-hub

What gets saved:

  • meta/temporal_proportions_sparse.json - Auto-generated sparse proportions ({"task": 1.0})
  • meta/temporal_proportions_dense.json - Dense temporal proportions
  • Per-episode columns in episodes/*.parquet:
    • dense_subtask_names, dense_subtask_start_frames, dense_subtask_end_frames
    • (also time-based columns: dense_subtask_start_times, dense_subtask_end_times)

dual

Generate both sparse (high-level) and dense (fine-grained) annotations using a VLM.

python src/lerobot/data_processing/sarm_annotations/subtask_annotation.py \
  --repo-id your-username/your-dataset \
  --sparse-subtasks "Bring arms up from starting position,Fold the towel (3 folds in total)" \
  --dense-subtasks "Bring robot arms up from starting position,Grab near side and do 1st fold,Grab side and do 2nd fold,Grab side and do 3rd fold to finish folding" \
  --video-key observation.images.base \
  --num-workers 4 \
  --push-to-hub

What gets saved:

  • meta/temporal_proportions_sparse.json - Sparse temporal proportions
  • meta/temporal_proportions_dense.json - Dense temporal proportions
  • Per-episode columns in episodes/*.parquet:
    • sparse_subtask_names, sparse_subtask_start_frames, sparse_subtask_end_frames
    • dense_subtask_names, dense_subtask_start_frames, dense_subtask_end_frames
    • (also time-based columns: *_subtask_start_times, *_subtask_end_times)

Annotation Arguments

Argument Description
--repo-id HuggingFace dataset repository ID
--sparse-subtasks Comma-separated list of high-level subtask names
--dense-subtasks Comma-separated list of fine-grained subtask names
--dense-only Generate only dense annotations (auto-creates sparse "task" stage)
--video-key Camera/video key to use (e.g., observation.images.top)
--num-workers Number of parallel GPU workers (default: 1)
--episodes Specific episode indices to annotate (default: all)
--skip-existing Skip episodes that already have annotations
--model VLM model (default: Qwen/Qwen3-VL-30B-A3B-Instruct)
--num-visualizations Number of episodes to visualize after annotation (default: 5, set to 0 to skip)

Note: After annotation completes, 5 episodes are automatically visualized by default. Use --num-visualizations 0 to skip this step.


Step 2: Verify Annotations

single_stage

No verification needed! Skip this step.

dense_only

Visualize annotations using the --visualize-only flag:

python src/lerobot/data_processing/sarm_annotations/subtask_annotation.py \
  --repo-id your-username/your-dataset \
  --visualize-only \
  --visualize-type dense \
  --num-visualizations 5 \
  --video-key observation.images.base \
  --output-dir ./subtask_viz

dual

Visualize annotations using the --visualize-only flag:

python src/lerobot/data_processing/sarm_annotations/subtask_annotation.py \
  --repo-id your-username/your-dataset \
  --visualize-only \
  --visualize-type both \
  --num-visualizations 5 \
  --video-key observation.images.base \
  --output-dir ./subtask_viz

This generates visualizations showing video frames with subtask boundaries overlaid and timeline of subtasks.

Visualization Arguments

Argument Description
--visualize-only Only visualize existing annotations (no generation)
--num-visualizations Number of episodes to visualize (default: 5)
--visualize-type Type of annotations to visualize: sparse, dense, or both

Tip: If annotations are inaccurate, adjust your subtask descriptions to be more specific and re-run.