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
streaming: in-context demo support cache (per-dataset episode ring, LRU), morphology+robot-text per sample
Browse files
tinyvla_b200/src/tinyvla/data/streaming_hub.py
CHANGED
|
@@ -62,9 +62,19 @@ class HubEpisodeStream(IterableDataset):
|
|
| 62 |
seed: int = 42,
|
| 63 |
rank: int = 0,
|
| 64 |
world_size: int = 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
):
|
| 66 |
super().__init__()
|
| 67 |
self.specs = specs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
self.token = token
|
| 69 |
self.chunk = chunk
|
| 70 |
self.image_size = image_size
|
|
@@ -265,7 +275,7 @@ class HubEpisodeStream(IterableDataset):
|
|
| 265 |
is_pad[avail:] = True
|
| 266 |
if cams["cam1"] is None and zero_img is None:
|
| 267 |
zero_img = torch.zeros_like(cams["cam0"][j])
|
| 268 |
-
|
| 269 |
"observation.images.cam0": cams["cam0"][j],
|
| 270 |
"observation.images.cam1": cams["cam1"][j] if cams["cam1"] is not None else zero_img,
|
| 271 |
"camera_mask": cam_mask,
|
|
@@ -276,6 +286,12 @@ class HubEpisodeStream(IterableDataset):
|
|
| 276 |
"embodiment_id": torch.tensor(spec.get("embodiment_id", si), dtype=torch.long),
|
| 277 |
"task": task,
|
| 278 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
|
| 280 |
# ------------------------------------------------------------------- iter
|
| 281 |
|
|
@@ -287,12 +303,44 @@ class HubEpisodeStream(IterableDataset):
|
|
| 287 |
weights = [s["weight"] for s in self.specs]
|
| 288 |
|
| 289 |
buf: list[dict] = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
while True: # infinite stream; the training loop counts steps, not epochs
|
| 291 |
si = rng.choices(range(len(self.specs)), weights=weights, k=1)[0]
|
| 292 |
try:
|
| 293 |
meta = self._load_meta(si)
|
| 294 |
ep_idx, _, task = meta["episodes"][rng.randrange(len(meta["episodes"]))]
|
|
|
|
| 295 |
for item in self._stream_episode(si, ep_idx, task):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
if len(buf) < self.shuffle_buffer:
|
| 297 |
buf.append(item)
|
| 298 |
continue
|
|
|
|
| 62 |
seed: int = 42,
|
| 63 |
rank: int = 0,
|
| 64 |
world_size: int = 1,
|
| 65 |
+
n_support: int = 0,
|
| 66 |
+
morph_descriptors: dict | None = None, # morph_key -> (16,) tensor
|
| 67 |
+
robot_prompts: dict | None = None, # morph_key -> str
|
| 68 |
+
support_cache_datasets: int = 8,
|
| 69 |
+
support_cache_size: int = 48,
|
| 70 |
):
|
| 71 |
super().__init__()
|
| 72 |
self.specs = specs
|
| 73 |
+
self.n_support = n_support
|
| 74 |
+
self.morph_descriptors = morph_descriptors or {}
|
| 75 |
+
self.robot_prompts = robot_prompts or {}
|
| 76 |
+
self.support_cache_datasets = support_cache_datasets
|
| 77 |
+
self.support_cache_size = support_cache_size
|
| 78 |
self.token = token
|
| 79 |
self.chunk = chunk
|
| 80 |
self.image_size = image_size
|
|
|
|
| 275 |
is_pad[avail:] = True
|
| 276 |
if cams["cam1"] is None and zero_img is None:
|
| 277 |
zero_img = torch.zeros_like(cams["cam0"][j])
|
| 278 |
+
out = {
|
| 279 |
"observation.images.cam0": cams["cam0"][j],
|
| 280 |
"observation.images.cam1": cams["cam1"][j] if cams["cam1"] is not None else zero_img,
|
| 281 |
"camera_mask": cam_mask,
|
|
|
|
| 286 |
"embodiment_id": torch.tensor(spec.get("embodiment_id", si), dtype=torch.long),
|
| 287 |
"task": task,
|
| 288 |
}
|
| 289 |
+
mkey = spec.get("morph_key")
|
| 290 |
+
if mkey and mkey in self.morph_descriptors:
|
| 291 |
+
out["morphology"] = self.morph_descriptors[mkey]
|
| 292 |
+
if mkey:
|
| 293 |
+
out["morph_text"] = self.robot_prompts.get(mkey, "")
|
| 294 |
+
yield out
|
| 295 |
|
| 296 |
# ------------------------------------------------------------------- iter
|
| 297 |
|
|
|
|
| 303 |
weights = [s["weight"] for s in self.specs]
|
| 304 |
|
| 305 |
buf: list[dict] = []
|
| 306 |
+
# in-context demo support: per-dataset ring of (img, action_chunk, ep) from
|
| 307 |
+
# PREVIOUS episodes of the same dataset. LRU over datasets bounds memory.
|
| 308 |
+
from collections import OrderedDict, deque
|
| 309 |
+
|
| 310 |
+
sup_cache: OrderedDict[int, deque] = OrderedDict()
|
| 311 |
+
|
| 312 |
+
def attach_support(item, si, ep_idx):
|
| 313 |
+
if self.n_support <= 0:
|
| 314 |
+
return item
|
| 315 |
+
pool = list(sup_cache.get(si, ()))
|
| 316 |
+
other = [e for e in pool if e[2] != ep_idx] or pool
|
| 317 |
+
imgs, acts = [], []
|
| 318 |
+
for _ in range(self.n_support):
|
| 319 |
+
if other:
|
| 320 |
+
e = other[rng.randrange(len(other))]
|
| 321 |
+
imgs.append(e[0]); acts.append(e[1])
|
| 322 |
+
else: # bootstrap: first episode of this dataset — fall back to self
|
| 323 |
+
imgs.append(item["observation.images.cam0"]); acts.append(item["action"])
|
| 324 |
+
item["support_images"] = torch.stack(imgs)
|
| 325 |
+
item["support_actions"] = torch.stack(acts)
|
| 326 |
+
return item
|
| 327 |
+
|
| 328 |
while True: # infinite stream; the training loop counts steps, not epochs
|
| 329 |
si = rng.choices(range(len(self.specs)), weights=weights, k=1)[0]
|
| 330 |
try:
|
| 331 |
meta = self._load_meta(si)
|
| 332 |
ep_idx, _, task = meta["episodes"][rng.randrange(len(meta["episodes"]))]
|
| 333 |
+
n_seen = 0
|
| 334 |
for item in self._stream_episode(si, ep_idx, task):
|
| 335 |
+
if self.n_support > 0:
|
| 336 |
+
n_seen += 1
|
| 337 |
+
if n_seen % 17 == 0: # редкая подвыборка эпизода в кэш демо
|
| 338 |
+
d = sup_cache.setdefault(si, deque(maxlen=self.support_cache_size))
|
| 339 |
+
d.append((item["observation.images.cam0"], item["action"], ep_idx))
|
| 340 |
+
sup_cache.move_to_end(si)
|
| 341 |
+
while len(sup_cache) > self.support_cache_datasets:
|
| 342 |
+
sup_cache.popitem(last=False)
|
| 343 |
+
item = attach_support(item, si, ep_idx)
|
| 344 |
if len(buf) < self.shuffle_buffer:
|
| 345 |
buf.append(item)
|
| 346 |
continue
|