| --- |
| license: apache-2.0 |
| task_categories: |
| - robotics |
| tags: |
| - robotics |
| - text-embeddings |
| - t5 |
| - wan2.2 |
| size_categories: |
| - 1M<n<10M |
| --- |
| |
| # RoboTwin 2.0 3D — T5 Text Embedding Cache |
|
|
| Precomputed [UMT5-XXL](https://huggingface.co/google/umt5-xxl) text embeddings for the |
| **1,039,891 unique task prompts** of the RoboTwin 2.0 3D dataset |
| ([`flex-pi/robotwin_3d`](https://huggingface.co/datasets/flex-pi/robotwin_3d)), as consumed by |
| Wan2.2-TI2V-5B. Precomputing these costs substantial GPU time; this cache skips it. |
|
|
| ## Cache key |
|
|
| Task strings from `meta/tasks.jsonl` are wrapped in a fixed template before encoding, and the cache |
| key is the sha256 of that templated prompt: |
|
|
| ```python |
| DEFAULT_PROMPT = "A video recorded from a robot's point of view executing the following instruction: {task}" |
| key = hashlib.sha256(DEFAULT_PROMPT.format(task=task).encode("utf-8")).hexdigest() |
| ``` |
|
|
| | | | |
| |---|---| |
| | task | `Lift the medium-sized green bottle ensuring it remains upright.` | |
| | prompt | `A video recorded from a robot's point of view executing the following instruction: Lift the medium-sized green bottle ensuring it remains upright.` | |
| | key | `83eacc02ca58bc93ecd638b3d2318494f442778e62a71a13d7987dfdb649fe18` | |
|
|
| ## Contents |
|
|
| | Path | Description | |
| |---|---| |
| | `shards/shard_NNNNN.safetensors` | 520 shards × 2,000 prompts (last one 1,891), ~2.10 GB each | |
| | `manifest.txt` | All 1,039,891 keys, **sorted**, one per line — line `i` is row `i % 2000` of shard `i // 2000` | |
|
|
| Each shard holds two row-aligned tensors, plus `__metadata__["keys"]` (JSON list of that shard's |
| keys in row order): |
|
|
| | Tensor | Shape | Dtype | |
| |---|---|---| |
| | `contexts` | `[N, 128, 4096]` | `bfloat16` | |
| | `masks` | `[N, 128]` | `bool` | |
|
|
| `masks` marks valid tokens (mean 40.9 of 128). Values past the mask are raw T5 outputs rather than |
| zeros. Zero them on load (`context[~mask] = 0`) if your model does not apply the mask. |
|
|
| ## Converting back to the per-file `.pt` layout |
|
|
| The training pipeline reads a flat directory of `{key}.t5_len128.wan22ti2v5b.pt` files, each a |
| `{"context", "mask"}` dict, rather than shards. This script reconstructs that layout: |
|
|
| ```python |
| # unpack_to_pt.py -- rebuild the flat .pt cache from the sharded release. |
| # python unpack_to_pt.py /path/to/text_embeds_cache/robotwin2.0_3d |
| import json, os, sys |
| from concurrent.futures import ThreadPoolExecutor |
| |
| import torch |
| from huggingface_hub import hf_hub_download |
| from safetensors import safe_open |
| |
| REPO, NSHARD = "flex-pi/robotwin_3d_text_embeds_cache", 520 |
| out, tmp = sys.argv[1], "/tmp/tec_shards" |
| os.makedirs(out, exist_ok=True) |
| |
| def do(i): |
| # local_dir= gives a real file we can delete; the default cache would only |
| # yield a symlink, so removing it frees nothing. |
| p = hf_hub_download(REPO, f"shards/shard_{i:05d}.safetensors", |
| repo_type="dataset", local_dir=tmp) |
| with safe_open(p, framework="pt") as f: |
| ks = json.loads(f.metadata()["keys"]) |
| C, M = f.get_slice("contexts"), f.get_slice("masks") |
| for r, k in enumerate(ks): |
| dst = os.path.join(out, f"{k}.t5_len128.wan22ti2v5b.pt") |
| if not os.path.exists(dst): |
| torch.save({"context": C[r], "mask": M[r]}, dst) |
| os.remove(p) # drop the 2 GB shard once expanded |
| print(f"shard {i:05d} -> {len(ks)} files", flush=True) |
| |
| with ThreadPoolExecutor(4) as ex: |
| list(ex.map(do, range(NSHARD))) |
| ``` |
|
|
| Expands to ~1 TB across 1,039,891 files. Point `text_embedding_cache_dir` at `out` afterwards. |
|
|
| To pull only part of it, pass a subset of shard indices — each shard is self-describing. |
|
|
| ## Random access without unpacking |
|
|
| Resolve one prompt to its shard and read only that row; `get_slice` avoids loading the 2 GB shard: |
|
|
| ```python |
| import bisect, hashlib, json |
| from huggingface_hub import hf_hub_download |
| from safetensors import safe_open |
| |
| REPO, SHARD = "flex-pi/robotwin_3d_text_embeds_cache", 2000 |
| TPL = "A video recorded from a robot's point of view executing the following instruction: {task}" |
| keys = open(hf_hub_download(REPO, "manifest.txt", repo_type="dataset")).read().split() |
| |
| def get(task): |
| h = hashlib.sha256(TPL.format(task=task).encode("utf-8")).hexdigest() |
| i = bisect.bisect_left(keys, h) |
| if i == len(keys) or keys[i] != h: |
| raise KeyError(task) |
| p = hf_hub_download(REPO, f"shards/shard_{i // SHARD:05d}.safetensors", repo_type="dataset") |
| with safe_open(p, framework="pt") as f: |
| r = i % SHARD |
| return f.get_slice("contexts")[r], f.get_slice("masks")[r] |
| |
| ctx, mask = get("Lift the medium-sized green bottle ensuring it remains upright.") |
| print(ctx.shape, ctx.dtype, int(mask.sum())) # torch.Size([128, 4096]) torch.bfloat16 49 |
| ``` |
|
|
| ## Provenance |
|
|
| Repacked byte-exactly from the original per-prompt `.pt` cache; tensors are bit-identical, verified |
| by round-trip comparison against the source files. Encoder UMT5-XXL, context length 128, bfloat16. |
|
|