4. 数据集中输入缓存示例

📅 发布时间:2026/8/30 4:19:51
4. 数据集中输入缓存示例
代码importtorch path/workspace/pick-n-place-sq-lerobot-v21/latents/chunk-000/observation.images.top/\episode_000000_0_264.pthobjtorch.load(path,map_locationcpu,weights_onlyFalse)# 自己的数据才可信defdescribe(x,prefixroot):ifisinstance(x,torch.Tensor):print(f{prefix}: Tensor shape{tuple(x.shape)}dtype{x.dtype})elifisinstance(x,dict):print(f{prefix}: dict keys{list(x.keys())})fork,vinx.items():describe(v,f{prefix}[{k!r}])elifisinstance(x,(list,tuple)):print(f{prefix}:{type(x).__name__}len{len(x)})fori,vinenumerate(x[:2]):describe(v,f{prefix}[{i}])else:print(f{prefix}:{type(x).__name__}{x})describe(obj) root: dict keys[latent, latent_num_frames, latent_height, latent_width, video_num_frames, video_height, video_width, text_emb, text, frame_ids, start_frame, end_frame, fps, ori_fps] root[latent]: Tensor shape(8448, 48) dtypetorch.bfloat16 root[latent_num_frames]: int 33 root[latent_height]: int 16 root[latent_width]: int 16 root[video_num_frames]: int 129 root[video_height]: int 256 root[video_width]: int 256 root[text_emb]: Tensor shape(512, 4096) dtypetorch.bfloat16 root[text]: str Pick the green cube and place it inside the blue box root[frame_ids]: ndarray [ 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256] root[start_frame]: int 0 root[end_frame]: int 264 root[fps]: int 15 root[ori_fps]: int 30 解读这是一个「打包好的训练样本」这个 dict 就是 lingbot‑va 训练时一个 episode‑view 的完整输入缓存 视频 VAE latent 文本条件 采样元信息。逐项对账一下数字完全自洽1) 视频 latent 部分latent (8448, 48)因为33 × 16 × 16 8448所以它是把(T, H, W)展平、channel 放在最后一维的 latent 序列即(T*H*W, C)的 tokens 形式。压缩比可以反推时间(129 − 1) / 4 1 33→时间 4×Wan 系 VAE 的典型公式空间256 / 16 16→空间 16×通道48这组参数48 通道、4×16×16 压缩对应的是Wan2.2 的 VAE规格Wan2.1 是 16 通道 / 8× 空间。可以去仓库的 encode 脚本里 grepz_dim/48确认。还原成标准(C, T, H, W)布局dtorch.load(path,map_locationcpu,weights_onlyFalse)zd[latent].reshape(d[latent_num_frames],d[latent_height],d[latent_width],-1)# (33,16,16,48)zz.permute(3,0,1,2).contiguous()# (48,33,16,16)想解码回像素必须用同一个 VAE decoder裸看这些数没有任何意义。2) 文本条件部分text任务指令 “Pick the green cube and place it inside the blue box”。text_emb (512, 4096)UMT5‑XXL的预提取 embeddinghidden 4096pad 到 512 tokens——这正是 Wan 系列用的文本编码器和上面 VAE 的判断互相印证。训练时直接当 condition 用不用再跑 T5。3) 采样元信息关键别忽略ori_fps30 → fps15原始 264 帧 30fps每 2 帧抽 1 帧。frame_ids [0,2,...,256]共 129 帧 video_num_frames。注意不是 132是因为截到 129 才能满足(T−1)%40凑出整数 latent 帧 33。start_frame/end_frame 0/264对应文件名episode_000000_0_264。它的作用是给你对齐 action 用的从 LeRobot parquet 里取 action/state 时必须用同一份frame_ids即[::2][:129]去采样否则 latent 和 action 时间轴对不上。总结块内容用途latent(33·16·16, 48) bf16Wan2.2‑VAE 编码视频分支的输入/目标text_embUMT5‑XXL, (512, 4096)语言条件frame_ids/fps/...抽样元信息与 parquet 中 action/state 对齐所以这个.pth本质是episode 0、top 视角、整段0–264 帧视频在 latent 空间的表示 指令 embedding 的离线缓存dataloader 读它就是为了训练时跳过 VAE/T5 这两个最贵的编码步骤。