FARM reward model -- DexMimicGen Two-Arm Three-Piece Assembly
Failure-aware reward model (FARM, v7 recipe) for the bimanual task Assemble the three pieces: place the two pieces
onto the base. It is the progress-only ReWiND-state model
chomeed/rewind_state_dexmg_two_arm_three_piece_assembly
fine-tuned for 5,000 steps on the same success demos plus 200 failed rollouts of the base policy, with exactly the
recipe of the Threading model
chomeed/farm_rewind_state_dexmg_two_arm_threading.
It is trained so that the reward keeps rising while an attempt makes progress and falls once the attempt starts to
fail. The model outputs one reward in [0, 1] per frame. Use it only with the causal hybrid8 window described under
Evaluation.
On 100 fresh rollouts that no model had seen, failed episodes end at a reward of 0.003 (baseline: 0.19) and successful ones at 0.93 (baseline: 0.91).
How the failure reward is lowered
FARM never labels a failure "0". It finds where each failed rollout goes wrong and trains the reward to fall over the ~3 s after that point, in the same causal windows the model sees at inference.
- Find the critical point t*. The frozen baseline scores each of the 200 failed rollouts frame by frame with a
16-frame uniform window (frames
linspace(0, t, 16), not thehybrid8window used at inference). The scores are smoothed over 7 frames, and t* is their maximum: the furthest the attempt got before it went wrong. The median t* is frame 292 (14.6 s into a 25 s rollout). - Take the frames right after it. The failure clip covers frames t*-5 to t*+60, cut short where the rollout ends (20-66 frames). It is always sampled at 16 evenly spaced anchors (1.3-4.3 frames apart).
- Make the reward fall along the clip. Each anchor k is scored in its inference window (8 frames spread over
the history before it + the 8 frames ending at it), which gives a reward logit z_k. The hinge
relu(z_{k+1} - z_k + 0.2)penalises any anchor that is not at least 0.2 logits below the previous one; when the hinge is fully satisfied, the logit falls by at least 3 (15 x 0.2) across the clip. It is a soft penalty (the mean over the 15 steps, averaged with the success hinge in 5), not a hard constraint. - Keep the credit earned before the failure. There is no absolute target, and no loss term acts on failure frames outside the clip. The reward before t*-5 is left to what the model learned from successes. On the mined failures it sits slightly above the baseline's: the mean over the 5 s before t* is 0.87 (baseline 0.83).
- Protect successes. (a) The original ReWiND progress loss keeps training on all 1,006 success demos (MSE to
linear progress, with half of the clips "rewound"). (b) Each failure clip comes with 3 matched success windows,
ranked by a 50/50 blend of (i) cosine similarity on the normalised state trajectory (weight 0.4) and on the
frozen baseline's per-camera Transformer embeddings (0.2 per camera), over 16 subsampled frames, and (ii) banded
DTW on the state trajectory (band 3, early-warp penalty 0.5). One of the 3 is drawn per sample and scored at 16
anchors in the same causal window. A hinge without margin,
relu(z_k - z_{k+1}), penalises any fall there, and an MSE pullssigmoid(z_k)to linear progress (anchor frame / (episode length - 1)). On Three-Piece most of these windows lie early in successful demos (median last anchor at frame 64, 27 % of the way through; see caveats).
L = L_ReWiND + 1.0 * (L_fail_hinge + L_succ_hinge) / 2 + 1.0 * L_succ_MSE, with the hinge and MSE weights ramped
in over the first 500 steps. A Bradley-Terry success-vs-failure term exists in the code but has weight 0 (logged
only), and TV smoothing is off. The matching therefore only decides which success windows feed (b); no
success-vs-failure comparison enters the loss.
Training data
chomeed/dexmg_two_arm_three_piece_assembly: all 1,006 DexMimicGen-generated success demos (239,827 frames, 20 fps; median 238 frames, longest 272 frames = 13.6 s) for the progress term. There is no validation split.chomeed/dexmg_two_arm_three_piece_assembly_failures: 200 failed rollouts of the frozen base Diffusion Policy, each a 500-frame (25 s) time-out.- A pair manifest mined with the frozen baseline: one failure clip per failed rollout, each with 3 matched success windows (sampled at 16-64 frames; the chosen ones are 16-61 frames long, median 19), taken from 54 different demos.
Model and configuration
Same model as the baseline: 3 RGB cameras at 84x84 (agentview, robot0_eye_in_hand, robot1_eye_in_hand) through
DINOv2-base at native resolution (last 2 blocks and final LayerNorm fine-tuned), the 18-d observation.state
(mean/std normalised with the demo statistics), the instruction through a frozen
sentence-transformers/all-MiniLM-L12-v2 in the preprocessor (not stored here), and a 4-layer Transformer (512-d,
8 heads) with a sigmoid head over a 16-frame window. 102,945,537 parameters, 30,545,409 trainable.
| setting | value |
|---|---|
| initialisation | chomeed/rewind_state_dexmg_two_arm_three_piece_assembly (step 50,000; byte-identical file) |
| released checkpoint | step 5,000 of a run defined over 100k steps; model.safetensors sha256 220b6ede72da5ea2e761936dab659bedaf24b0500f2f0ca95135a035d387307c |
| batch | 4 samples, each = 1 ReWiND clip + 16 failure-anchor + 16 success-anchor windows (132 windows of 16 frames per step) |
| optimiser | AdamW (0.9, 0.95), weight decay 1e-10, grad clip 10, bf16 mixed precision, seed 1000, 1x RTX 4090 |
| learning rate | 1e-4 for all non-DINOv2 parameters (MLPs, Transformer, head), 1e-5 for the fine-tuned DINOv2 blocks and final LayerNorm; 1,000-step warmup, cosine over 100k steps, so still 9.94e-5 at step 5,000 |
| failure hinge | margin 0.2 on logits, 16 anchors over t*-5..t*+60, hybrid8 windows |
| success anchors | 16 per window: no-decrease hinge (margin 0) + MSE to linear progress |
| loss weights | ReWiND 1, hinges 1 (averaged), success MSE 1, Bradley-Terry 0, TV 0; 500-step ramp |
Apart from the dataset, the manifest, the initial checkpoint and the run names, the training configuration is
identical to the Threading model's. scheduler_peak_lr: 5e-5 in the config does not set the peak: LeRobot's cosine
schedule scales the optimizer LR and uses peak_lr only for the 5 % floor ratio.
Evaluation
Causal window (hybrid8). For t >= 16, the reward at frame t is the last output of a 16-frame window:
np.linspace(0, t-8, 8).astype(int) followed by frames t-7..t. Only frames <= t are used. The hinge and anchor terms
were trained on this layout, and the RL reward shaper uses the same window (RewindRewardShaper,
trajectory_mode="hybrid", window_recent_n=8).
Protocol. Episode score = mean of the last 3 per-frame rewards, threshold 0.5. Failures caught = failure score < 0.5; successes recognised = success score >= 0.5; balanced accuracy = the mean of the two. AUROC = probability that a random success outscores a random failure.
Fresh held-out rollouts (headline). 100 new rollouts of the frozen base Diffusion Policy with env seeds 20000-20099, disjoint from every seed used for training, RL or earlier evaluation: 63 successes (10.25-15.1 s long) and 37 failures (all 25 s time-outs). No reward model saw them.
| model | success score | failure score (lower is better) | failures caught | successes recognised | balanced acc. | AUROC |
|---|---|---|---|---|---|---|
| ReWiND-state (baseline) | 0.91 | 0.19 | 31/37 | 61/63 | 0.90 | 0.99 |
| FARM, step 5k (this model) | 0.93 | 0.003 | 37/37 | 61/63 | 0.98 | 0.998 |
- The baseline already lowers most failure rewards on this task, but 6/37 fresh failures still end at >= 0.5; FARM catches all 37.
- Both missed successes are longer than any training demo: the longest fresh success (15.1 s, score 0.0005) and the third-longest (14.2 s, score 0.41). The baseline misses the same two. The longest one scores below 5 of the 37 failures, hence the AUROC of 0.998.
- FARM still credits a failed attempt early on: its per-episode peak averages 0.97 (baseline 0.89). Its reward then stays below 0.5 from a median 15.45 s, about 9.6 s before the time-out.
- Against t* (the 50 mined failures 150-199, in-sample: their post-t* clips were trained): the mean reward over the 5 s before t* is 0.87 (baseline 0.83) and 0.84 around t* (t* +- 0.25 s; baseline 0.90); 5/50 are already below 0.5 at t* (baseline 8/50). The reward first drops below 0.5 a median 0.7 s after t* (96 % within 3 s), and that time correlates with t* at 0.96 (baseline: 0.92 on the same measure).
- In-sample reference, not evidence of generalisation (successes 956-1005 are training demos, failures 150-199 were mined for training): FARM 1.00 / 0.002 / 50/50 / 50/50 / 1.00 / 1.00; baseline 1.00 / 0.19 / 43/50 / 50/50 / 0.93 / 1.00.
- Step 2,000 of the same run (not uploaded) scored 0.96 / 0.0002 / 37/37 / 61/63 / 0.98 / 0.998 on the fresh rollouts.
Loading
A sketch of the evaluation path (reference implementation: load_rewind_reward_model +
compute_rewind_reward_for_episode); this exact snippet was not run on its own.
import lerobot_policy_rewind_state_ours_variant7 # registers `rewind_state_ours_variant7` (local plugin, see caveats)
from huggingface_hub import snapshot_download
from lerobot.configs.policies import PreTrainedConfig
from lerobot.datasets.lerobot_dataset import LeRobotDatasetMetadata
from lerobot.policies.factory import make_policy, make_pre_post_processors
from lerobot_policy_rewind_state.common.eval_rewind_reward_visualization_dense import dense_predict_per_frame
path = snapshot_download("chomeed/farm_rewind_state_dexmg_two_arm_three_piece_assembly")
cfg = PreTrainedConfig.from_pretrained(path)
# Required: config.json's pretrained_path is the *baseline's* local training checkpoint. Without this line
# make_policy loads the baseline (on the training cluster) or fails (anywhere else).
cfg.pretrained_path = path
cfg.device = "cuda"
meta = LeRobotDatasetMetadata("chomeed/dexmg_two_arm_three_piece_assembly")
policy = make_policy(cfg=cfg, ds_meta=meta).eval()
pre, _ = make_pre_post_processors(policy_cfg=cfg, pretrained_path=None, dataset_stats=meta.stats)
# cams: {"observation.images.agentview", "...robot0_eye_in_hand", "...robot1_eye_in_hand"} -> float (1, T, 3, 84, 84) in [0, 1]
# state: raw observation.state, shape (1, T, 18)
batch = pre({**cams, "observation.state": state,
"task": ["Assemble the three pieces: place the two pieces onto the base"]})
reward = dense_predict_per_frame(policy, {k: batch[k] for k in cams}, batch["task.minilm"],
state=batch["observation.state"], max_window=16, sampling="hybrid", n_recent=8)
Caveats
A time shortcut is not ruled out by the training signal. On Three-Piece the matched success windows are mostly early: their last anchor sits at a median frame 64 (3.2 s, 27 % of the way through the demo); 74 % end within the first 40 % of their demo, and only 11 % reach its last tenth. Meanwhile t* lies beyond the end of the longest success demo (272 frames, 13.6 s) in about two thirds of the pairs, and 80 % of the failure anchors do too. A rule like "late = low" would satisfy most failure-hinge terms, and the progress term constrains successes only up to 13.6 s.
- For the concern: both fresh successes it misses are longer than any training demo, and FARM also lowers the second-longest (15.0 s) to 0.68, against 1.00 under the baseline. The baseline misses the same two, so the misses are not specific to FARM, but FARM makes this weakness somewhat worse.
- Against it, weakly: on the 50 mined failures (training data), the reward first drops below 0.5 a median 0.7 s after t* and that time follows t* (correlation 0.96), but the baseline already reaches 0.92 on the same measure, which is computed from t* onward, and 5/50 episodes are already below 0.5 at t* (baseline: 8/50).
Episode length is a confound. Every failure is a 25 s time-out and fresh successes end after 10.25-15.1 s, while the score is read at the episode end. Failures that end early were not tested.
Only the clip after t* is trained. Low rewards late in a failure, and behaviour on failure modes unlike the 200 training failures (all time-outs of one base policy), are generalisation, not training targets.
Causal only through the window. The trunk lays tokens out stream-major, masks them with triu and regroups them
with h.view(B, T, -1), so early output positions inside a window see later frames. Read only the last output of a
window that ends at t. dense_predict_per_frame scores frames 0-15 from one pass over frames 0-15 (outputs 0-14 see
later frames, up to frame 15); for strictly causal online use, feed the prefix 0..t and read its last output, as the
RL shaper does. Episode scores (last 3 frames) are unaffected.
v7, not v6. Earlier Three-Piece "FARM" detection and RL numbers belong to v6 (margin 0.3, steps 2,000 and 5,000), a different checkpoint. Do not attribute them to this model, which was not used as an RL reward. FARM v6 did not beat ReWiND as an RL reward: 69 % vs 73 % evaluation success on Three-Piece and 71 % vs 77 % on Threading (the Threading FARM value is digitised from a plot of its best replicates, so it is optimistic).
Loading needs the plugins. lerobot_policy_rewind_state_ours_variant7 and lerobot_policy_rewind_state are local
LeRobot plugin packages with no public code location yet. The results were produced with a locally modified LeRobot
0.4.4, and the snippet is untested on stock LeRobot: config.json loads through the plugin, but train_config.json
contains fork-only fields (dataset.cf_aug, val, test) that stock LeRobot may not parse. Override
cfg.pretrained_path; config.json's pretrained_path (the baseline's local checkpoint) and preference_pairs_path
are local training values. The 14-d action output and the postprocessor exist for LeRobot compatibility only; use
predict_reward.
Companion artifacts
- Baseline this model was fine-tuned from:
chomeed/rewind_state_dexmg_two_arm_three_piece_assembly - Same recipe on Threading:
chomeed/farm_rewind_state_dexmg_two_arm_threading - Datasets, base policies and the MimicGen FARM-SARM models are in the MimicGen & DexMimicGen Reward Modeling collection.