Instructions to use AlexWortega/tinyvla with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LeRobot
How to use AlexWortega/tinyvla with LeRobot:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Upload tinyvla2/scripts/eval_lekiwi_groot.py with huggingface_hub
Browse files
tinyvla2/scripts/eval_lekiwi_groot.py
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Run the GR00T (physical_ai_ft) checkpoint on held-out LeKiwi.
|
| 3 |
+
|
| 4 |
+
This is a deliberately unfair test, and the point is to measure HOW unfair.
|
| 5 |
+
|
| 6 |
+
The checkpoint is `conditioning: id` + `action_space: native`. Its action head was
|
| 7 |
+
trained on six GR00T families whose native layouts are 44/14/24/12/23/26-43 dims,
|
| 8 |
+
each addressed by an embodiment id in 10..15. LeKiwi (SO-100 arm on a 3-wheel kiwi
|
| 9 |
+
base, 9 dims: 6 joint targets in degrees + x_mm/y_mm/theta) was never assigned an
|
| 10 |
+
id and its dim k has no reason to mean what any GR00T robot's dim k means.
|
| 11 |
+
|
| 12 |
+
So the model is given every advantage available:
|
| 13 |
+
- each trained id 10..15 is tried, and the BEST is reported (oracle id selection)
|
| 14 |
+
- id 0 is reported too: rows 0..9 are the stale C-scaled ids this run never
|
| 15 |
+
touched, so it is the "no matching identity" reference
|
| 16 |
+
- the same 4-seed ODE averaging and the same per-dim ABS/DELTA baseline search
|
| 17 |
+
used for the in-distribution evaluation
|
| 18 |
+
|
| 19 |
+
Preprocessing mirrors HubEpisodeStream: decimate to 10 Hz, per-dataset z-score,
|
| 20 |
+
zero-pad state to 256 and actions to 64.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
from __future__ import annotations
|
| 24 |
+
|
| 25 |
+
import sys
|
| 26 |
+
from pathlib import Path
|
| 27 |
+
|
| 28 |
+
import numpy as np
|
| 29 |
+
import torch
|
| 30 |
+
|
| 31 |
+
sys.path.insert(0, str(Path(__file__).parent))
|
| 32 |
+
from eval_physical_ai import bootstrap_ci, chunk_err, classify_dims, predict_mean # noqa: E402
|
| 33 |
+
|
| 34 |
+
CKPT = "/home/alexw/tinyvla/outputs/physical_ai_ft_fixed"
|
| 35 |
+
NAME, ROOT = "lekiwi_cleanup", str(Path("~/tinyvla_data/lekiwi/lekiwi_cleanup").expanduser())
|
| 36 |
+
TARGET_HZ = 10.0
|
| 37 |
+
IDS = [10, 11, 12, 13, 14, 15, 0]
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@torch.no_grad()
|
| 41 |
+
def main():
|
| 42 |
+
from lerobot.datasets.lerobot_dataset import LeRobotDataset, LeRobotDatasetMetadata
|
| 43 |
+
from safetensors.torch import load_file
|
| 44 |
+
from transformers import AutoTokenizer
|
| 45 |
+
|
| 46 |
+
from tinyvla.modeling_tinyvla import TinyVLAPolicy
|
| 47 |
+
|
| 48 |
+
pol = TinyVLAPolicy.from_pretrained(CKPT)
|
| 49 |
+
pol.load_state_dict(load_file(f"{CKPT}/model.safetensors"), strict=True) # never strict=False
|
| 50 |
+
cfg = pol.config
|
| 51 |
+
pol = pol.cuda().eval()
|
| 52 |
+
tok = AutoTokenizer.from_pretrained(cfg.lm_model_name)
|
| 53 |
+
print(f"GATE strict load OK | action_dim={pol.action_dim} "
|
| 54 |
+
f"max_state={cfg.max_state_dim} max_action={cfg.max_action_dim}")
|
| 55 |
+
|
| 56 |
+
meta = LeRobotDatasetMetadata(NAME, root=ROOT)
|
| 57 |
+
stride = max(1, round(meta.fps / TARGET_HZ))
|
| 58 |
+
ds = LeRobotDataset(NAME, root=ROOT, video_backend="torchcodec",
|
| 59 |
+
delta_timestamps={"action": [t / TARGET_HZ for t in range(cfg.chunk_size)]})
|
| 60 |
+
sm = np.asarray(meta.stats["observation.state"]["mean"], dtype=np.float64)
|
| 61 |
+
ss = np.maximum(np.asarray(meta.stats["observation.state"]["std"], dtype=np.float64), 1e-6)
|
| 62 |
+
am = np.asarray(meta.stats["action"]["mean"], dtype=np.float64)
|
| 63 |
+
as_ = np.maximum(np.asarray(meta.stats["action"]["std"], dtype=np.float64), 1e-6)
|
| 64 |
+
ad = len(am)
|
| 65 |
+
print(f"LeKiwi: {meta.total_episodes} eps, {meta.fps} fps -> stride {stride} ({TARGET_HZ} Hz), "
|
| 66 |
+
f"action_dim {ad}")
|
| 67 |
+
|
| 68 |
+
# per-dim ABS/DELTA classification, on RAW units, exactly as for the GR00T families
|
| 69 |
+
hf = ds.reader.hf_dataset.with_format("numpy")
|
| 70 |
+
s_all = np.asarray(hf["observation.state"], dtype=np.float64)[::stride]
|
| 71 |
+
a_all = np.asarray(hf["action"], dtype=np.float64)[::stride]
|
| 72 |
+
kind, amap, lag, std_a = classify_dims(s_all[:4000], a_all[:4000])
|
| 73 |
+
names = meta.features["action"].get("names") or list(range(ad))
|
| 74 |
+
names = names.get("motors", names) if isinstance(names, dict) else names
|
| 75 |
+
print("dim classification:",
|
| 76 |
+
", ".join(f"{names[j]}={kind[j]}" + (f"<-s{amap[j]}" if kind[j] == "abs" else "")
|
| 77 |
+
for j in range(ad)))
|
| 78 |
+
|
| 79 |
+
imk = sorted(k for k in meta.features if k.startswith("observation.images"))
|
| 80 |
+
prim = next((k for k in imk if "wrist" not in k), imk[0])
|
| 81 |
+
wrist = next((k for k in imk if "wrist" in k), None)
|
| 82 |
+
|
| 83 |
+
def rs(x):
|
| 84 |
+
return torch.nn.functional.interpolate(x[None].float(), size=(cfg.image_size, cfg.image_size),
|
| 85 |
+
mode="bilinear", align_corners=False)[0]
|
| 86 |
+
|
| 87 |
+
# held-out tail episodes
|
| 88 |
+
test_eps = range(max(0, meta.total_episodes - 12), meta.total_episodes)
|
| 89 |
+
samples = []
|
| 90 |
+
for ep in test_eps:
|
| 91 |
+
s = int(meta.episodes["dataset_from_index"][ep])
|
| 92 |
+
e = int(meta.episodes["dataset_to_index"][ep])
|
| 93 |
+
for idx in range(s, max(s + 1, e - cfg.chunk_size * stride), 90):
|
| 94 |
+
item = ds[idx]
|
| 95 |
+
A = item["action"].numpy().astype(np.float64)[:, :ad]
|
| 96 |
+
if A.shape[0] < cfg.chunk_size:
|
| 97 |
+
continue
|
| 98 |
+
st_raw = item["observation.state"].numpy().astype(np.float64)[:ad]
|
| 99 |
+
st_n = (st_raw - sm) / ss
|
| 100 |
+
samples.append({
|
| 101 |
+
"ep": ep,
|
| 102 |
+
"cam0": rs(item[prim]),
|
| 103 |
+
"cam1": rs(item[wrist]) if wrist else torch.zeros(3, cfg.image_size, cfg.image_size),
|
| 104 |
+
"state": torch.nn.functional.pad(torch.tensor(st_n, dtype=torch.float32),
|
| 105 |
+
(0, cfg.max_state_dim - len(st_n))),
|
| 106 |
+
"A": (A - am) / as_,
|
| 107 |
+
"ref": np.array([(st_raw[amap[j]] - am[j]) / as_[j] if kind[j] == "abs" and amap[j] >= 0
|
| 108 |
+
else 0.0 for j in range(ad)]),
|
| 109 |
+
"task": item.get("task") or "",
|
| 110 |
+
})
|
| 111 |
+
print(f"held-out samples: {len(samples)} from {len(list(test_eps))} episodes\n")
|
| 112 |
+
|
| 113 |
+
def run(emb_id):
|
| 114 |
+
preds = []
|
| 115 |
+
for k in range(0, len(samples), 8):
|
| 116 |
+
chunk = samples[k:k + 8]
|
| 117 |
+
t = tok([c["task"] for c in chunk], padding="max_length", truncation=True,
|
| 118 |
+
max_length=48, return_tensors="pt")
|
| 119 |
+
b = {"observation.images.cam0": torch.stack([c["cam0"] for c in chunk]).cuda(),
|
| 120 |
+
"observation.images.cam1": torch.stack([c["cam1"] for c in chunk]).cuda(),
|
| 121 |
+
"observation.state": torch.stack([c["state"] for c in chunk]).cuda(),
|
| 122 |
+
"observation.language.tokens": t["input_ids"].cuda(),
|
| 123 |
+
"observation.language.attention_mask": t["attention_mask"].bool().cuda(),
|
| 124 |
+
"embodiment_id": torch.full((len(chunk),), emb_id, dtype=torch.long).cuda()}
|
| 125 |
+
preds.append(predict_mean(pol, b, 4))
|
| 126 |
+
return np.concatenate(preds, 0)
|
| 127 |
+
|
| 128 |
+
print(f"{'emb id':>8} {'subset':7}{'dims':>5}{'err':>9}{'B0':>9}{'B1':>9}{'B2':>9}{'ratio':>8}"
|
| 129 |
+
f" 95% CI")
|
| 130 |
+
best = {}
|
| 131 |
+
for emb in IDS:
|
| 132 |
+
pred = run(emb)
|
| 133 |
+
for subset in ("abs", "delta"):
|
| 134 |
+
sel = (kind == subset)
|
| 135 |
+
if not sel.any():
|
| 136 |
+
continue
|
| 137 |
+
per_ep = {}
|
| 138 |
+
for i, c in enumerate(samples):
|
| 139 |
+
P = pred[i][:, :ad].astype(np.float64)
|
| 140 |
+
e, _ = chunk_err(P, c["A"], kind, amap, c["ref"], sel)
|
| 141 |
+
b0, _ = chunk_err(np.zeros_like(c["A"]), c["A"], kind, amap, c["ref"], sel)
|
| 142 |
+
b1, _ = chunk_err(np.tile(c["ref"], (len(c["A"]), 1)), c["A"], kind, amap, c["ref"], sel)
|
| 143 |
+
b2, _ = chunk_err(np.tile(c["A"][0], (len(c["A"]), 1)), c["A"], kind, amap, c["ref"], sel)
|
| 144 |
+
per_ep.setdefault(c["ep"], []).append((e, b0, b1, b2))
|
| 145 |
+
rows = np.array([np.mean(v, axis=0) for v in per_ep.values()])
|
| 146 |
+
err, b0, b1, b2 = rows.mean(0)
|
| 147 |
+
floor = min(b0, b1)
|
| 148 |
+
ratios = rows[:, 0] / np.maximum(rows[:, 1:3].min(1), 1e-9)
|
| 149 |
+
lo, hi = bootstrap_ci(ratios)
|
| 150 |
+
tag = " (untrained id row)" if emb == 0 else ""
|
| 151 |
+
print(f"{emb:>8} {subset:7}{int(sel.sum()):>5}{err:>9.3f}{b0:>9.3f}{b1:>9.3f}{b2:>9.3f}"
|
| 152 |
+
f"{err/floor:>8.2f} [{lo:.2f}, {hi:.2f}]{tag}")
|
| 153 |
+
k = subset
|
| 154 |
+
if k not in best or err / floor < best[k][1]:
|
| 155 |
+
best[k] = (emb, err / floor, b2 / floor)
|
| 156 |
+
|
| 157 |
+
print("\nORACLE id selection (best of 10..15, i.e. maximally generous to the checkpoint):")
|
| 158 |
+
for subset, (emb, r, b2r) in best.items():
|
| 159 |
+
note = " <- oracle repeat-A0 is BETTER, so the model loses to a dynamics-free predictor" \
|
| 160 |
+
if b2r < r else ""
|
| 161 |
+
print(f" {subset:6} best id {emb}: ratio {r:.2f} (oracle repeat-A0 {b2r:.2f}){note}")
|
| 162 |
+
print("\nratio < 1.0 beats the trivial baseline (hold still for abs dims, zero motion for delta)")
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
if __name__ == "__main__":
|
| 166 |
+
main()
|