AlexWortega commited on
Commit
769604a
·
verified ·
1 Parent(s): 638924d

Upload tinyvla2/scripts/eval_libero_canon.py with huggingface_hub

Browse files
tinyvla2/scripts/eval_libero_canon.py CHANGED
@@ -46,13 +46,19 @@ def main():
46
  p.add_argument("--max-steps", type=int, default=520)
47
  p.add_argument("--n-action-steps", type=int, default=25,
48
  help="actions executed per predicted chunk before re-planning")
49
- p.add_argument("--grip-mode", default="threshold", choices=["threshold", "linear"])
50
  p.add_argument("--decode", default="servo", choices=["servo", "scaled"],
51
  help="servo (default): integrate predicted deltas into a desired EE pose and "
52
  "command the error against the measured pose. The naive scaled decode "
53
  "replays achieved motion as a command, which the OSC controller "
54
  "under-tracks: GT round-trip replay scores 1/5 scaled vs 3/5 servo "
55
  "against a 4/5 raw-GT ceiling.")
 
 
 
 
 
 
56
  p.add_argument("--kp", type=float, default=120.0)
57
  p.add_argument("--kr", type=float, default=12.0)
58
  p.add_argument("--save-video-dir", type=Path, default=None)
@@ -131,17 +137,25 @@ def main():
131
  Drops the anchor delta: sidecars built from observation state have
132
  a_pose == s_pose, so chunk[0] is identically zero.
133
  """
134
- return (chunk_norm[:, :7] * span / 2 + mid)[1:]
135
 
136
- def grip_cmd(openness):
 
 
 
 
 
 
 
 
137
  if args.grip_mode == "threshold":
138
- return -1.0 if openness > fit["grip_threshold"] else 1.0
139
- return float(np.clip(openness * fit["grip_a"] + fit["grip_b"], -1, 1))
140
 
141
  def decode_scaled(phys):
142
  osc = np.zeros((len(phys), 7), dtype=np.float32)
143
  osc[:, :6] = phys[:, :6] * mscale
144
- osc[:, 6] = [grip_cmd(g) for g in phys[:, 6]]
145
  return np.clip(osc, -1.0, 1.0)
146
 
147
  def measured_pose(obs):
@@ -178,8 +192,13 @@ def main():
178
  latent = policy._semantic_latent(batch)
179
  last_refresh = step_i / fps
180
  batch["semantic_latent"] = latent
181
- with torch.autocast("cuda", torch.bfloat16):
182
- pred = policy.predict_action_chunk(batch)[0].float().cpu().numpy()
 
 
 
 
 
183
  phys = to_physical(pred)[: args.n_action_steps]
184
  if args.decode == "servo":
185
  queue = list(phys) # consumed as deltas, servoed below
@@ -194,7 +213,7 @@ def main():
194
  act = np.zeros(7, dtype=np.float32)
195
  act[:3] = args.kp * (des_p - cur_p)
196
  act[3:6] = args.kr * (des_R * cur_R.inv()).as_rotvec()
197
- act[6] = grip_cmd(d[6])
198
  act = np.clip(act, -1, 1)
199
  else:
200
  act = queue.pop(0)
 
46
  p.add_argument("--max-steps", type=int, default=520)
47
  p.add_argument("--n-action-steps", type=int, default=25,
48
  help="actions executed per predicted chunk before re-planning")
49
+ p.add_argument("--grip-mode", default="canon", choices=["canon", "threshold", "linear"])
50
  p.add_argument("--decode", default="servo", choices=["servo", "scaled"],
51
  help="servo (default): integrate predicted deltas into a desired EE pose and "
52
  "command the error against the measured pose. The naive scaled decode "
53
  "replays achieved motion as a command, which the OSC controller "
54
  "under-tracks: GT round-trip replay scores 1/5 scaled vs 3/5 servo "
55
  "against a 4/5 raw-GT ceiling.")
56
+ p.add_argument("--pred-seeds", type=int, default=4,
57
+ help="average the flow ODE over N noise draws per decision. "
58
+ "predict_action_chunk starts from torch.randn, so a single draw "
59
+ "makes the whole rollout a lottery: the SAME checkpoint and "
60
+ "settings scored 4/20 and 8/20 on consecutive runs. Averaging "
61
+ "removes that and is the better point estimate under an L2 metric.")
62
  p.add_argument("--kp", type=float, default=120.0)
63
  p.add_argument("--kr", type=float, default=12.0)
64
  p.add_argument("--save-video-dir", type=Path, default=None)
 
137
  Drops the anchor delta: sidecars built from observation state have
138
  a_pose == s_pose, so chunk[0] is identically zero.
139
  """
140
+ return (chunk_norm[:, :8] * span / 2 + mid)[1:]
141
 
142
+ def grip_cmd(row):
143
+ """row = one physical canonical step: [dpos(3), drot(3), openness, command].
144
+
145
+ `canon` reads the native command the policy now predicts directly. The other
146
+ two reconstruct it from the openness, which is only 92.5% accurate per step
147
+ and was costing ~10 points of closed-loop ceiling.
148
+ """
149
+ if args.grip_mode == "canon":
150
+ return float(np.clip(row[7], -1, 1))
151
  if args.grip_mode == "threshold":
152
+ return -1.0 if row[6] > fit["grip_threshold"] else 1.0
153
+ return float(np.clip(row[6] * fit["grip_a"] + fit["grip_b"], -1, 1))
154
 
155
  def decode_scaled(phys):
156
  osc = np.zeros((len(phys), 7), dtype=np.float32)
157
  osc[:, :6] = phys[:, :6] * mscale
158
+ osc[:, 6] = [grip_cmd(r) for r in phys]
159
  return np.clip(osc, -1.0, 1.0)
160
 
161
  def measured_pose(obs):
 
192
  latent = policy._semantic_latent(batch)
193
  last_refresh = step_i / fps
194
  batch["semantic_latent"] = latent
195
+ acc = None
196
+ for _s in range(args.pred_seeds):
197
+ torch.manual_seed(10_000 + 977 * ep + 13 * step_i + _s)
198
+ with torch.autocast("cuda", torch.bfloat16):
199
+ q = policy.predict_action_chunk(batch)[0].float()
200
+ acc = q if acc is None else acc + q
201
+ pred = (acc / args.pred_seeds).cpu().numpy()
202
  phys = to_physical(pred)[: args.n_action_steps]
203
  if args.decode == "servo":
204
  queue = list(phys) # consumed as deltas, servoed below
 
213
  act = np.zeros(7, dtype=np.float32)
214
  act[:3] = args.kp * (des_p - cur_p)
215
  act[3:6] = args.kr * (des_R * cur_R.inv()).as_rotvec()
216
+ act[6] = grip_cmd(d)
217
  act = np.clip(act, -1, 1)
218
  else:
219
  act = queue.pop(0)