Fatpaper commited on
Commit
e4f9222
·
verified ·
1 Parent(s): 81f3675

README, SANE patch and corrected checksums

Browse files
README.md ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ tags:
4
+ - robotics
5
+ - piper
6
+ - pi0.5
7
+ - openpi
8
+ - motionforcing
9
+ - real-time-chunking
10
+ ---
11
+
12
+ # Piper 双臂三任务:π₀.₅ 与 MotionForcing 推理权重(训练时 RTC)
13
+
14
+ 本仓库提供 Piper 双臂真机部署用的推理权重,共三个任务,每个任务三个模型,都用训练时 RTC(training-time RTC)训练:训练时随机把动作 chunk 开头最多 15 步(50 步的 30%)换成干净的真实动作作为前缀,25% 的样本不带前缀。同一任务的三个模型用同一份示教数据,服务都走 openpi 的 websocket 协议,请求和返回的格式相同,真机客户端不用改,换端口即可。
15
+
16
+ | 任务目录 | 示教 | π₀.₅ 训练数据(LeRobot) | 默认指令 |
17
+ | --- | ---: | --- | --- |
18
+ | `tidy_desk` | 50 条 | `HITdongdong/piper_dual_tidy_desk_ros2_shifted` | `Tidy up the crumpled papers and pens on the desk.` |
19
+ | `stack_cups` | 100 条 | `HITdongdong/piper_dual_stack_cups_ros2_shifted_master_gripper_100ep` | `Stack_the_paper_cups_together.` |
20
+ | `fold_towel` | 100 条 | `HITdongdong/piper_dual_fold_towel_ros2_shifted_master_gripper_100ep` | `Fold_the_towel.` |
21
+
22
+ - MotionForcing 的推理代码在 GitHub 仓库 `Hong-yu-Zhang/motionforcing-piper-deploy`。环境、接口、延迟等细节以那里的 README 为准。
23
+ - π₀.₅ 用公开的 [SANE](https://github.com/Linux-2023/SANE) 代码加本仓库里的补丁起服务。
24
+
25
+ ## 1. 内容
26
+
27
+ 每个任务目录下有三个模型:
28
+
29
+ | 目录 | 模型 | 服务代码 |
30
+ | --- | --- | --- |
31
+ | `pi05/29999` | π₀.₅(3.35B),训练 30k 步 | SANE 加补丁 |
32
+ | `ours` | MotionForcing(2.52B),我们的模型 | `motionforcing-piper-deploy` |
33
+ | `jepa_pretrain` | MotionForcing(2.52B),同一结构,初始化不同 | `motionforcing-piper-deploy` |
34
+
35
+ - `pi05/29999/`:`params/`(JAX/Orbax 推理权重,约 12 GB)、`assets/HITdongdong/<数据集名>/norm_stats.json`、`_CHECKPOINT_METADATA`。
36
+ - `ours/`、`jepa_pretrain/`:`config.json` 和两个 safetensors 分片(约 5.8 GB,骨干为 bf16,动作专家为 fp32)、`norm_stats.json`(归一化统计量)、`serve_config.json`(相机顺序、输入分辨率、动作维度和默认指令)。`config.json` 里的 `rtc_max_prefix: 15` 表示训练时前缀最长 15 步。
37
+ - `pi05_sane/piper_training_rtc_3tasks.patch`:π₀.₅ 训练时 RTC 的 SANE 补丁,包括三个任务的训练配置。
38
+ - `checksums.sha256`:除本 README 以外全部文件的校验值。
39
+
40
+ ## 2. 下载与校验
41
+
42
+ 全部约 72 GB,可以只下载需要的任务:
43
+
44
+ ```bash
45
+ huggingface-cli download Fatpaper/motionforcing-piper-rtc --include "stack_cups/*" "pi05_sane/*" "checksums.sha256" \
46
+ --local-dir ~/piper_models/motionforcing-piper-rtc
47
+ cd ~/piper_models/motionforcing-piper-rtc && grep -E " (stack_cups|pi05_sane)/" checksums.sha256 | sha256sum -c
48
+ ```
49
+
50
+ 去掉 `--include` 就是下载全部,然后用 `sha256sum -c checksums.sha256` 校验。
51
+
52
+ ## 3. 启动服务
53
+
54
+ π₀.₅ 需要先准备打过补丁的 SANE(环境安装见 SANE 的 README):
55
+
56
+ ```bash
57
+ git clone https://github.com/Linux-2023/SANE.git && cd SANE
58
+ git checkout c9d724acd746dc521a748577ebe97ec1aa133f66
59
+ git apply ~/piper_models/motionforcing-piper-rtc/pi05_sane/piper_training_rtc_3tasks.patch
60
+ GIT_LFS_SKIP_SMUDGE=1 uv sync
61
+ ```
62
+
63
+ 以叠杯子为例,另外两个任务把目录和 π₀.₅ 配置名换掉即可:
64
+
65
+ ```bash
66
+ M=~/piper_models/motionforcing-piper-rtc/stack_cups
67
+
68
+ # π₀.₅:在 SANE 根目录
69
+ uv run scripts/serve_policy.py --port 8000 policy:checkpoint \
70
+ --policy.config pi05_piper_dual_stack_cups_ros2_shifted_master_gripper_100ep_training_rtc \
71
+ --policy.dir "$M/pi05/29999"
72
+
73
+ # MotionForcing:在 motionforcing-piper-deploy 仓库根目录,按其 README 配好环境
74
+ python serve_policy.py --model-dir "$M/ours" --port 8001
75
+ python serve_policy.py --model-dir "$M/jepa_pretrain" --port 8002
76
+ ```
77
+
78
+ | 任务目录 | π₀.₅ 配置名 |
79
+ | --- | --- |
80
+ | `tidy_desk` | `pi05_piper_dual_tidy_desk_ros2_shifted_training_rtc` |
81
+ | `stack_cups` | `pi05_piper_dual_stack_cups_ros2_shifted_master_gripper_100ep_training_rtc` |
82
+ | `fold_towel` | `pi05_piper_dual_fold_towel_ros2_shifted_master_gripper_100ep_training_rtc` |
83
+
84
+ 请求包括:
85
+
86
+ - `state`:14 维,左臂 6 个关节加夹爪,然后是右臂,原始单位;
87
+ - `images`:`cam_high`、`cam_left_wrist`、`cam_right_wrist` 三路 CHW uint8 图像;
88
+ - `prompt`:可省略,省略时用上表的默认指令;
89
+ - `rtc_obs`:可省略,见第 4 节。
90
+
91
+ 返回 `actions`(50 × 14,绝对关节角和夹爪目标,单位与 `state` 相同)。MotionForcing 三路相机缺一路会直接报错。
92
+
93
+ ## 4. RTC 前缀
94
+
95
+ 客户端可以用 openpi-client 的 `ActionChunkBroker`(`use_rtc=True`),它会在请求里带上 `rtc_obs`:`prev_action` 是上一段还没执行、已经对齐到新 chunk 的动作,`d` 是这次推理期间会执行掉的步数。
96
+
97
+ - **MotionForcing**:服务端把 `prev_action` 的前 `d` 行当作干净前缀钉住,和训练时的做法一致。返回的 `actions` 前 `d` 行与发来的动作逐位相同,客户端从第 `d` 步开始执行。`d` 必须在 0 到 15 之间,`d = 0` 等同于普通请求。
98
+ - **π₀.₅**:SANE 的服务收到 `rtc_obs` 时,用的是 SANE 原有的推理时 RTC(对前缀做 guidance,是软约束),返回的前 `d` 行接近但不保证等于发来的动作。补丁只改了训练,没有给 π₀.₅ 加硬前缀推理。
99
+
100
+ 发布前做过离线检查:在示教数据的若干帧上给定真实前缀后,6 个 MotionForcing 模型在第 10–19 步的动作误差都明显下降(下降约 30%–43%),前缀和新生成部分的接缝处跳变与真实动作相当;没有用训练时 RTC 训练的旧模型给前缀后误差不下降。
101
+
102
+ ## 5. 真机测试建议
103
+
104
+ - **安全**:首次运行要在可以急停、有人值守的条件下进行,客户端保留关节速度和加速度限幅。返回的是绝对目标,第一步应该接近当前关节状态;如果偏差很大,通常是相机接反或关节顺序不对,这时不要执行。
105
+ - **对比方式**:同一任务的三个模型在同一批随机摆放上测相同的次数,模型之间交替进行。三个模型的客户端设置保持一致(每个 chunk 执行多少步,同步还是异步请求,是否开 RTC 以及 `d` 取多少),并在结果里注明。MotionForcing 每次推理比 π₀.₅ 多约 110–130 ms(GB300)。
106
+
107
+ ## 6. 许可
108
+
109
+ - π₀.₅ 权重派生自 Physical Intelligence 的 `pi05_base`,须遵守其上游许可条款(包括 PaliGemma 涉及的 Gemma 条款)。
110
+ - MotionForcing 权重派生自 `Alibaba-DAMO-Academy/RynnBrain-2B`(Apache-2.0)。推理代码按 Apache-2.0 发布(见 GitHub 仓库的 `LICENSE`)。
111
+ - SANE 补丁修改自 SANE / openpi 的代码,遵守其原有许可。
112
+
113
+ ## 7. 版本
114
+
115
+ - MotionForcing 代码:`Hong-yu-Zhang/motionforcing-piper-deploy` 提交 `ac1ad1e2ba45e4e9a68832dd074eac1cae234de7`。
116
+ - RynnBrain-2B:`ad71236d013ae5618833fded73a32569045a8e9e`,首次启动时自动下载。
117
+ - π₀.₅ 代码:SANE `c9d724acd746dc521a748577ebe97ec1aa133f66`,加 `pi05_sane/piper_training_rtc_3tasks.patch`(sha256 `394df7a19047519451d2f277e40f0242749abffb8921eaef2ca7608bd898db25`)。
checksums.sha256 CHANGED
@@ -1,4 +1,3 @@
1
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 checksums.sha256.tmp
2
  292dfc7296df155f59637e19c9f44a5c47ec60d23c7a2a27e33a77268102f05d fold_towel/jepa_pretrain/config.json
3
  e45d43e1f13fc9f375427c63d020ee97d8abf1d77368a183b1b866d7ff091bc1 fold_towel/jepa_pretrain/model-00001-of-00002.safetensors
4
  7aa772500fa68e8b1b6ee3931909928cac8abf00d04401629ddab69738fcdd29 fold_towel/jepa_pretrain/model-00002-of-00002.safetensors
@@ -30,6 +29,7 @@ c14a3ec3b785660300e24ead752820f229d90b22ba8607d976eb5bc3833d7325 fold_towel/pi0
30
  5c13c1ce680f395e588201bc4fcfb8b800566a6fc073832dd6926f5bbedec34f fold_towel/pi05/29999/params/ocdbt.process_0/d/dcce1b292459a1a15abe9b94adfff502
31
  ce1f250913cac900468a23538108328d7cd35779f994eccf2557b89b86e60b28 fold_towel/pi05/29999/params/ocdbt.process_0/manifest.ocdbt
32
  236b3c9cbb7b4aff0ce1a7fad2a6de2990d03a106a7bfd70f4623ebf8b7f4a51 fold_towel/pi05/29999/params/_sharding
 
33
  292dfc7296df155f59637e19c9f44a5c47ec60d23c7a2a27e33a77268102f05d stack_cups/jepa_pretrain/config.json
34
  c6bf4ad9700f5674dfe5496bac08b107de370db82f2b5ab1f3f0927380a8b41c stack_cups/jepa_pretrain/model-00001-of-00002.safetensors
35
  c9ac67a2bce44e87b2598dea128755342a58092fb847aae892ea83c7c89fd7de stack_cups/jepa_pretrain/model-00002-of-00002.safetensors
 
 
1
  292dfc7296df155f59637e19c9f44a5c47ec60d23c7a2a27e33a77268102f05d fold_towel/jepa_pretrain/config.json
2
  e45d43e1f13fc9f375427c63d020ee97d8abf1d77368a183b1b866d7ff091bc1 fold_towel/jepa_pretrain/model-00001-of-00002.safetensors
3
  7aa772500fa68e8b1b6ee3931909928cac8abf00d04401629ddab69738fcdd29 fold_towel/jepa_pretrain/model-00002-of-00002.safetensors
 
29
  5c13c1ce680f395e588201bc4fcfb8b800566a6fc073832dd6926f5bbedec34f fold_towel/pi05/29999/params/ocdbt.process_0/d/dcce1b292459a1a15abe9b94adfff502
30
  ce1f250913cac900468a23538108328d7cd35779f994eccf2557b89b86e60b28 fold_towel/pi05/29999/params/ocdbt.process_0/manifest.ocdbt
31
  236b3c9cbb7b4aff0ce1a7fad2a6de2990d03a106a7bfd70f4623ebf8b7f4a51 fold_towel/pi05/29999/params/_sharding
32
+ 394df7a19047519451d2f277e40f0242749abffb8921eaef2ca7608bd898db25 pi05_sane/piper_training_rtc_3tasks.patch
33
  292dfc7296df155f59637e19c9f44a5c47ec60d23c7a2a27e33a77268102f05d stack_cups/jepa_pretrain/config.json
34
  c6bf4ad9700f5674dfe5496bac08b107de370db82f2b5ab1f3f0927380a8b41c stack_cups/jepa_pretrain/model-00001-of-00002.safetensors
35
  c9ac67a2bce44e87b2598dea128755342a58092fb847aae892ea83c7c89fd7de stack_cups/jepa_pretrain/model-00002-of-00002.safetensors
pi05_sane/piper_training_rtc_3tasks.patch ADDED
@@ -0,0 +1,444 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/src/openpi/models/gemma.py b/src/openpi/models/gemma.py
2
+ index d1623d1..e6962ff 100644
3
+ --- a/src/openpi/models/gemma.py
4
+ +++ b/src/openpi/models/gemma.py
5
+ @@ -126,7 +126,9 @@ class RMSNorm(nn.Module):
6
+
7
+ # adaptive RMSNorm
8
+ modulation = nn.Dense(x.shape[-1] * 3, kernel_init=nn.initializers.zeros, dtype=dtype)(cond)
9
+ - scale, shift, gate = jnp.split(modulation[:, None, :], 3, axis=-1)
10
+ + if cond.ndim == 2:
11
+ + modulation = modulation[:, None, :]
12
+ + scale, shift, gate = jnp.split(modulation, 3, axis=-1)
13
+ normed_inputs = normed_inputs * (1 + scale) + shift # scale and shift in float32
14
+ return normed_inputs.astype(dtype), gate
15
+
16
+ @@ -392,7 +394,7 @@ class Module(nn.Module):
17
+ embedded: Sequence[at.Float[at.Array, "b _t _d"] | None],
18
+ positions: at.Int[at.Array, "b t"],
19
+ mask: at.Bool[at.Array, "b t s"],
20
+ - adarms_cond: Sequence[at.Float[at.Array, "b _d"] | None] | None = None,
21
+ + adarms_cond: Sequence[at.Float[at.Array, "b _d"] | at.Float[at.Array, "b _t _d"] | None] | None = None,
22
+ *,
23
+ kv_cache: KVCache | None = None,
24
+ deterministic: bool = True,
25
+ diff --git a/src/openpi/models/model.py b/src/openpi/models/model.py
26
+ index 50d366a..509ce96 100644
27
+ --- a/src/openpi/models/model.py
28
+ +++ b/src/openpi/models/model.py
29
+ @@ -109,6 +109,8 @@ class Observation(Generic[ArrayT]):
30
+ # Logging fields
31
+ episode_index: at.Int[ArrayT, "*b"] | None = None
32
+ frame_index: at.Int[ArrayT, "*b"] | None = None
33
+ + # LeRobot marks action targets beyond the end of an episode.
34
+ + action_is_pad: at.Bool[ArrayT, "*b ah"] | None = None
35
+
36
+ # Previous state and action for RTC.
37
+ prev_state: at.Float[ArrayT, "*b s"] | None = None
38
+ @@ -165,6 +167,7 @@ class Observation(Generic[ArrayT]):
39
+ gpr_prev_action=gpr_prev_action,
40
+ episode_index=data.get("episode_index"),
41
+ frame_index=data.get("frame_index"),
42
+ + action_is_pad=data.get("action_is_pad"),
43
+ )
44
+
45
+
46
+ @@ -251,6 +254,7 @@ def preprocess_observation(
47
+ actions_during_latency=observation.actions_during_latency,
48
+ episode_index=observation.episode_index,
49
+ frame_index=observation.frame_index,
50
+ + action_is_pad=observation.action_is_pad,
51
+ )
52
+
53
+
54
+ diff --git a/src/openpi/models/pi0.py b/src/openpi/models/pi0.py
55
+ index 2ab28df..c96f68c 100644
56
+ --- a/src/openpi/models/pi0.py
57
+ +++ b/src/openpi/models/pi0.py
58
+ @@ -12,6 +12,7 @@ from openpi.models import model as _model
59
+ from openpi.models import pi0_config
60
+ from openpi.models import gp_utils as _gp_utils
61
+ from openpi.models import ot_utils as _ot_utils
62
+ +from openpi.models import rtc_training as _rtc_training
63
+ import openpi.models.gemma as _gemma
64
+ import openpi.models.siglip as _siglip
65
+ from openpi.shared import array_typing as at
66
+ @@ -144,12 +145,13 @@ class Pi0(_model.BaseModel):
67
+
68
+ @at.typecheck
69
+ def embed_suffix(
70
+ - self, obs: _model.Observation, noisy_actions: _model.Actions, timestep: at.Float[at.Array, " b"]
71
+ + self, obs: _model.Observation, noisy_actions: _model.Actions,
72
+ + timestep: at.Float[at.Array, " b"] | at.Float[at.Array, "b s"],
73
+ ) -> tuple[
74
+ at.Float[at.Array, "b s emb"],
75
+ at.Bool[at.Array, "b s"],
76
+ at.Bool[at.Array, " s"],
77
+ - at.Float[at.Array, "b emb"] | None,
78
+ + at.Float[at.Array, "b emb"] | at.Float[at.Array, "b s emb"] | None,
79
+ ]:
80
+ input_mask = []
81
+ ar_mask = []
82
+ @@ -164,7 +166,9 @@ class Pi0(_model.BaseModel):
83
+
84
+ action_tokens = self.action_in_proj(noisy_actions)
85
+ # embed timestep using sine-cosine positional encoding with sensitivity in the range [0, 1]
86
+ - time_emb = posemb_sincos(timestep, self.action_in_proj.out_features, min_period=4e-3, max_period=4.0)
87
+ + time_emb = posemb_sincos(timestep.reshape(-1), self.action_in_proj.out_features, min_period=4e-3, max_period=4.0)
88
+ + if timestep.ndim == 2:
89
+ + time_emb = time_emb.reshape(*timestep.shape, -1)
90
+ if self.pi05:
91
+ # time MLP (for adaRMS)
92
+ time_emb = self.time_mlp_in(time_emb)
93
+ @@ -239,13 +243,26 @@ class Pi0(_model.BaseModel):
94
+ num_iters=self._config.ot_num_iters,
95
+ )
96
+ time = jax.random.beta(time_rng, 1.5, 1, batch_shape) * 0.999 + 0.001
97
+ - time_expanded = time[..., None, None]
98
+ - x_t = time_expanded * noise + (1 - time_expanded) * actions
99
+ + if self._config.train_time_rtc:
100
+ + if observation.action_is_pad is None:
101
+ + raise ValueError("Training-time RTC requires the LeRobot action_is_pad mask.")
102
+ + x_t, model_time, rtc_suffix_mask = _rtc_training.training_inputs(
103
+ + jax.random.fold_in(rng, 0x525443),
104
+ + actions,
105
+ + noise,
106
+ + time,
107
+ + max_prefix_frac=self._config.train_time_rtc_max_prefix_frac,
108
+ + prefix_drop_p=self._config.train_time_rtc_prefix_drop_p,
109
+ + )
110
+ + else:
111
+ + time_expanded = time[..., None, None]
112
+ + x_t = time_expanded * noise + (1 - time_expanded) * actions
113
+ + model_time = time
114
+ u_t = noise - actions
115
+
116
+ # one big forward pass of prefix + suffix at once
117
+ prefix_tokens, prefix_mask, prefix_ar_mask = self.embed_prefix(observation)
118
+ - suffix_tokens, suffix_mask, suffix_ar_mask, adarms_cond = self.embed_suffix(observation, x_t, time)
119
+ + suffix_tokens, suffix_mask, suffix_ar_mask, adarms_cond = self.embed_suffix(observation, x_t, model_time)
120
+ input_mask = jnp.concatenate([prefix_mask, suffix_mask], axis=1)
121
+ ar_mask = jnp.concatenate([prefix_ar_mask, suffix_ar_mask], axis=0)
122
+ attn_mask = make_attn_mask(input_mask, ar_mask)
123
+ @@ -255,7 +272,13 @@ class Pi0(_model.BaseModel):
124
+ )
125
+ v_t = self.action_out_proj(suffix_out[:, -self.action_horizon :])
126
+
127
+ - loss = jnp.mean(jnp.square(v_t - u_t), axis=-1)
128
+ + if self._config.train_time_rtc:
129
+ + loss = _rtc_training.masked_flow_loss(
130
+ + v_t, u_t, rtc_suffix_mask, observation.action_is_pad,
131
+ + action_dim=self._config.train_time_rtc_action_dim or self.action_dim,
132
+ + )
133
+ + else:
134
+ + loss = jnp.mean(jnp.square(v_t - u_t), axis=-1)
135
+ if return_aux:
136
+ return loss, {"noise": noise, "time": time}
137
+ return loss
138
+ diff --git a/src/openpi/models/pi0_config.py b/src/openpi/models/pi0_config.py
139
+ index 065e6bd..a27d383 100644
140
+ --- a/src/openpi/models/pi0_config.py
141
+ +++ b/src/openpi/models/pi0_config.py
142
+ @@ -33,6 +33,12 @@ class Pi0Config(_model.BaseModelConfig):
143
+ discrete_state_input: bool = None # type: ignore
144
+ advantage_input: bool = False
145
+
146
+ + # Training-time RTC conditions the action expert on clean action prefixes.
147
+ + train_time_rtc: bool = False
148
+ + train_time_rtc_max_prefix_frac: float = 0.3
149
+ + train_time_rtc_prefix_drop_p: float = 0.25
150
+ + train_time_rtc_action_dim: int | None = None
151
+ +
152
+ # --------------- Gaussian Process prior settings ---------------
153
+ # When enabled, replaces i.i.d. Gaussian noise with GP-structured noise
154
+ # that introduces temporal correlations across the action horizon.
155
+ @@ -67,6 +73,15 @@ class Pi0Config(_model.BaseModelConfig):
156
+ object.__setattr__(self, "max_token_len", 200 if self.pi05 else 48)
157
+ if self.discrete_state_input is None:
158
+ object.__setattr__(self, "discrete_state_input", self.pi05)
159
+ + if self.train_time_rtc:
160
+ + if not self.pi05:
161
+ + raise ValueError("Training-time RTC requires pi05 adaptive timestep conditioning.")
162
+ + if not 0.0 <= self.train_time_rtc_max_prefix_frac <= 1.0:
163
+ + raise ValueError("RTC max prefix fraction must be between 0 and 1.")
164
+ + if not 0.0 <= self.train_time_rtc_prefix_drop_p <= 1.0:
165
+ + raise ValueError("RTC prefix dropout probability must be between 0 and 1.")
166
+ + if self.train_time_rtc_action_dim is not None and not 1 <= self.train_time_rtc_action_dim <= self.action_dim:
167
+ + raise ValueError("RTC supervised action dimension must be between 1 and action_dim.")
168
+ # Validate GP settings
169
+ if self.use_gp_prior:
170
+ valid_kernels = ("SE", "OU", "PE")
171
+ diff --git a/src/openpi/models/rtc_training.py b/src/openpi/models/rtc_training.py
172
+ new file mode 100644
173
+ index 0000000..dcde77b
174
+ --- /dev/null
175
+ +++ b/src/openpi/models/rtc_training.py
176
+ @@ -0,0 +1,33 @@
177
+ +"""Training-time action-prefix conditioning for pi0.5.
178
+ +
179
+ +The objective matches the RSSR RTC training branch at 25eed0cc / lerobot-pi0
180
+ +b500ef9d: clean prefixes with per-token t=0 and loss only on in-episode,
181
+ +non-prefix positions and real action dimensions.
182
+ +"""
183
+ +
184
+ +import jax
185
+ +import jax.numpy as jnp
186
+ +
187
+ +
188
+ +def training_inputs(rng, actions, noise, time, *, max_prefix_frac: float, prefix_drop_p: float):
189
+ + """Return noisy actions, per-position times, and the trained suffix mask."""
190
+ + batch, horizon, _ = actions.shape
191
+ + length_rng, drop_rng = jax.random.split(rng)
192
+ + max_prefix = max(0, min(horizon - 1, int(horizon * max_prefix_frac)))
193
+ + lengths = jax.random.randint(length_rng, (batch,), 0, max_prefix + 1)
194
+ + drop = jax.random.uniform(drop_rng, (batch,)) < prefix_drop_p
195
+ + lengths = jnp.where(drop, 0, lengths)
196
+ + suffix_mask = jnp.arange(horizon)[None, :] >= lengths[:, None]
197
+ + token_time = jnp.where(suffix_mask, time[:, None], 0.0)
198
+ + x_t = token_time[..., None] * noise + (1.0 - token_time[..., None]) * actions
199
+ + return x_t, token_time, suffix_mask
200
+ +
201
+ +
202
+ +def masked_flow_loss(velocity, target, suffix_mask, action_is_pad, *, action_dim: int):
203
+ + """Return per-position losses whose mean equals the valid scalar RTC loss."""
204
+ + valid = jnp.logical_and(suffix_mask, jnp.logical_not(action_is_pad))
205
+ + squared_error = jnp.square(velocity[..., :action_dim] - target[..., :action_dim])
206
+ + per_position = jnp.mean(squared_error, axis=-1)
207
+ + # The existing trainer reduces the returned BxH array with a global mean.
208
+ + # Scale so that this is the mean over valid (non-prefix, in-episode) positions.
209
+ + return jnp.where(valid, per_position, 0.0) * (valid.size / jnp.maximum(jnp.sum(valid), 1))
210
+ diff --git a/src/openpi/models/rtc_training_test.py b/src/openpi/models/rtc_training_test.py
211
+ new file mode 100644
212
+ index 0000000..fe0048b
213
+ --- /dev/null
214
+ +++ b/src/openpi/models/rtc_training_test.py
215
+ @@ -0,0 +1,64 @@
216
+ +import jax
217
+ +import jax.numpy as jnp
218
+ +import numpy as np
219
+ +
220
+ +from openpi.models import gemma
221
+ +from openpi.models import rtc_training
222
+ +
223
+ +
224
+ +def test_rtc_inputs_use_clean_prefix_and_per_token_time():
225
+ + actions = jnp.full((4096, 50, 3), 2.0)
226
+ + noise = jnp.full_like(actions, 6.0)
227
+ + time = jnp.full((4096,), 0.25)
228
+ + x_t, token_time, suffix = jax.jit(
229
+ + lambda key: rtc_training.training_inputs(
230
+ + key, actions, noise, time, max_prefix_frac=0.3, prefix_drop_p=0.25
231
+ + )
232
+ + )(jax.random.key(27))
233
+ + lengths = np.sum(~np.asarray(suffix), axis=1)
234
+ + assert lengths.min() == 0
235
+ + assert lengths.max() == 15
236
+ + assert 0.26 < np.mean(lengths == 0) < 0.34
237
+ + np.testing.assert_allclose(token_time, np.where(suffix, 0.25, 0.0))
238
+ + np.testing.assert_allclose(x_t, np.broadcast_to(np.where(np.asarray(suffix)[..., None], 3.0, 2.0), x_t.shape))
239
+ +
240
+ + x_t, token_time, suffix = rtc_training.training_inputs(
241
+ + jax.random.key(28), actions[:2], noise[:2], time[:2], max_prefix_frac=0.3, prefix_drop_p=1.0
242
+ + )
243
+ + assert np.all(suffix)
244
+ + np.testing.assert_allclose(token_time, 0.25)
245
+ + np.testing.assert_allclose(x_t, 3.0)
246
+ +
247
+ +
248
+ +def test_rtc_loss_excludes_prefix_episode_tail_and_padded_dimensions():
249
+ + suffix = jnp.array([[False, True, True, True], [True, True, False, True]])
250
+ + is_pad = jnp.array([[False, False, False, True], [False, False, True, True]])
251
+ + velocity = jnp.ones((2, 4, 3)).at[..., 2].set(1000.0)
252
+ + target = jnp.zeros_like(velocity)
253
+ +
254
+ + def loss(v):
255
+ + return jnp.mean(rtc_training.masked_flow_loss(v, target, suffix, is_pad, action_dim=2))
256
+ +
257
+ + np.testing.assert_allclose(jax.jit(loss)(velocity), 1.0)
258
+ + grad = np.asarray(jax.grad(loss)(velocity))
259
+ + expected = np.zeros((2, 4, 3), dtype=np.float32)
260
+ + expected[np.asarray(suffix & ~is_pad), :2] = 0.25
261
+ + np.testing.assert_allclose(grad, expected)
262
+ +
263
+ +
264
+ +def test_adarms_supports_independent_time_for_each_action():
265
+ + norm = gemma.RMSNorm()
266
+ + x = jnp.arange(1, 1 + 2 * 4 * 8, dtype=jnp.float32).reshape(2, 4, 8)
267
+ + shared = jnp.ones((2, 8), dtype=jnp.float32)
268
+ + params = norm.init(jax.random.key(3), x, shared)
269
+ + params["params"]["Dense_0"]["kernel"] = jnp.arange(8 * 24, dtype=jnp.float32).reshape(8, 24) / 1000.0
270
+ + repeated = jnp.broadcast_to(shared[:, None, :], (2, 4, 8))
271
+ + old_output, old_gate = norm.apply(params, x, shared)
272
+ + new_output, new_gate = norm.apply(params, x, repeated)
273
+ + np.testing.assert_allclose(old_output, new_output, rtol=1e-6)
274
+ + np.testing.assert_allclose(jnp.broadcast_to(old_gate, new_gate.shape), new_gate, rtol=1e-6)
275
+ + changed = repeated.at[0, 1].set(2.0)
276
+ + changed_output, _ = norm.apply(params, x, changed)
277
+ + assert not np.allclose(changed_output[0, 1], new_output[0, 1])
278
+ + np.testing.assert_allclose(changed_output[0, 0], new_output[0, 0])
279
+ + np.testing.assert_allclose(changed_output[1], new_output[1])
280
+ diff --git a/src/openpi/policies/piper_policy.py b/src/openpi/policies/piper_policy.py
281
+ index be3b9d4..7f84166 100644
282
+ --- a/src/openpi/policies/piper_policy.py
283
+ +++ b/src/openpi/policies/piper_policy.py
284
+ @@ -80,6 +80,8 @@ class PiperInputs(transforms.DataTransformFn):
285
+ actions = np.asarray(data["actions"])
286
+ actions = _encode_actions_inv(actions, adapt_to_pi=self.adapt_to_pi)
287
+ inputs["actions"] = actions.copy()
288
+ + if "action_is_pad" in data:
289
+ + inputs["action_is_pad"] = data["action_is_pad"]
290
+
291
+ if "prompt" in data:
292
+ inputs["prompt"] = data["prompt"]
293
+ diff --git a/src/openpi/training/config.py b/src/openpi/training/config.py
294
+ index e5a1d84..8ae0636 100644
295
+ --- a/src/openpi/training/config.py
296
+ +++ b/src/openpi/training/config.py
297
+ @@ -1385,6 +1385,147 @@ _CONFIGS = [
298
+ exp_name="debug_pi05",
299
+ wandb_enabled=False,
300
+ ),
301
+ + TrainConfig(
302
+ + name="pi05_piper_dual_tidy_desk_ros2_shifted_training_rtc",
303
+ + model=pi0_config.Pi0Config(
304
+ + pi05=True,
305
+ + action_dim=32,
306
+ + action_horizon=50,
307
+ + discrete_state_input=False,
308
+ + train_time_rtc=True,
309
+ + train_time_rtc_max_prefix_frac=0.3,
310
+ + train_time_rtc_prefix_drop_p=0.25,
311
+ + train_time_rtc_action_dim=14,
312
+ + ),
313
+ + data=LeRobotPiperDataConfig(
314
+ + repo_id="HITdongdong/piper_dual_tidy_desk_ros2_shifted",
315
+ + base_config=DataConfig(prompt_from_task=True),
316
+ + default_prompt="Tidy up the crumpled papers and pens on the desk.",
317
+ + adapt_to_pi=False,
318
+ + use_delta_joint_actions=True,
319
+ + repack_transforms=_transforms.Group(
320
+ + inputs=[
321
+ + _transforms.RepackTransform(
322
+ + {
323
+ + "images": {
324
+ + "cam_high": "observation.images.cam_high",
325
+ + "cam_left_wrist": "observation.images.cam_left_wrist",
326
+ + "cam_right_wrist": "observation.images.cam_right_wrist",
327
+ + },
328
+ + "state": "observation.state",
329
+ + "actions": "action",
330
+ + "action_is_pad": "action_is_pad",
331
+ + "prompt": "prompt",
332
+ + "episode_index": "episode_index",
333
+ + "frame_index": "frame_index",
334
+ + }
335
+ + )
336
+ + ]
337
+ + ),
338
+ + ),
339
+ + weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
340
+ + batch_size=64,
341
+ + num_workers=4,
342
+ + num_train_steps=30_000,
343
+ + save_interval=5_000,
344
+ + keep_period=5_000,
345
+ + fsdp_devices=2,
346
+ + ),
347
+ + # Stack cups and fold towel, 100 episodes each: the tidy desk config above with only the data and the
348
+ + # prompt changed. Arm joints are shifted (action[t] == state[t+1]); both grippers are the master arm's
349
+ + # command at frame t. HF_LEROBOT_HOME .../datasets/real_robot.
350
+ + TrainConfig(
351
+ + name="pi05_piper_dual_stack_cups_ros2_shifted_master_gripper_100ep_training_rtc",
352
+ + model=pi0_config.Pi0Config(
353
+ + pi05=True,
354
+ + action_dim=32,
355
+ + action_horizon=50,
356
+ + discrete_state_input=False,
357
+ + train_time_rtc=True,
358
+ + train_time_rtc_max_prefix_frac=0.3,
359
+ + train_time_rtc_prefix_drop_p=0.25,
360
+ + train_time_rtc_action_dim=14,
361
+ + ),
362
+ + data=LeRobotPiperDataConfig(
363
+ + repo_id="HITdongdong/piper_dual_stack_cups_ros2_shifted_master_gripper_100ep",
364
+ + base_config=DataConfig(prompt_from_task=True),
365
+ + default_prompt="Stack_the_paper_cups_together.",
366
+ + adapt_to_pi=False,
367
+ + use_delta_joint_actions=True,
368
+ + repack_transforms=_transforms.Group(
369
+ + inputs=[
370
+ + _transforms.RepackTransform(
371
+ + {
372
+ + "images": {
373
+ + "cam_high": "observation.images.cam_high",
374
+ + "cam_left_wrist": "observation.images.cam_left_wrist",
375
+ + "cam_right_wrist": "observation.images.cam_right_wrist",
376
+ + },
377
+ + "state": "observation.state",
378
+ + "actions": "action",
379
+ + "action_is_pad": "action_is_pad",
380
+ + "prompt": "prompt",
381
+ + "episode_index": "episode_index",
382
+ + "frame_index": "frame_index",
383
+ + }
384
+ + )
385
+ + ]
386
+ + ),
387
+ + ),
388
+ + weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
389
+ + batch_size=64,
390
+ + num_workers=4,
391
+ + num_train_steps=30_000,
392
+ + save_interval=5_000,
393
+ + keep_period=5_000,
394
+ + fsdp_devices=2,
395
+ + ),
396
+ + TrainConfig(
397
+ + name="pi05_piper_dual_fold_towel_ros2_shifted_master_gripper_100ep_training_rtc",
398
+ + model=pi0_config.Pi0Config(
399
+ + pi05=True,
400
+ + action_dim=32,
401
+ + action_horizon=50,
402
+ + discrete_state_input=False,
403
+ + train_time_rtc=True,
404
+ + train_time_rtc_max_prefix_frac=0.3,
405
+ + train_time_rtc_prefix_drop_p=0.25,
406
+ + train_time_rtc_action_dim=14,
407
+ + ),
408
+ + data=LeRobotPiperDataConfig(
409
+ + repo_id="HITdongdong/piper_dual_fold_towel_ros2_shifted_master_gripper_100ep",
410
+ + base_config=DataConfig(prompt_from_task=True),
411
+ + default_prompt="Fold_the_towel.",
412
+ + adapt_to_pi=False,
413
+ + use_delta_joint_actions=True,
414
+ + repack_transforms=_transforms.Group(
415
+ + inputs=[
416
+ + _transforms.RepackTransform(
417
+ + {
418
+ + "images": {
419
+ + "cam_high": "observation.images.cam_high",
420
+ + "cam_left_wrist": "observation.images.cam_left_wrist",
421
+ + "cam_right_wrist": "observation.images.cam_right_wrist",
422
+ + },
423
+ + "state": "observation.state",
424
+ + "actions": "action",
425
+ + "action_is_pad": "action_is_pad",
426
+ + "prompt": "prompt",
427
+ + "episode_index": "episode_index",
428
+ + "frame_index": "frame_index",
429
+ + }
430
+ + )
431
+ + ]
432
+ + ),
433
+ + ),
434
+ + weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
435
+ + batch_size=64,
436
+ + num_workers=4,
437
+ + num_train_steps=30_000,
438
+ + save_interval=5_000,
439
+ + keep_period=5_000,
440
+ + fsdp_devices=2,
441
+ + ),
442
+ #
443
+ # RoboArena configs.
444
+ #