WebDataset 与 Lance 互转
更新时间:2026-11-23
简介
WebDataset tar 分片与 Lance 表之间的双向转换。正向一个 sample 一行,.json / .txt / .cls 解析进列,媒体(视频、图片、npy 等)发布到外部存储、列里只存地址;反向把 Lance 重新打包成 tar 分片。
功能描述
- to_lance:输入可以是目录(其下所有
*.tar)、glob 或单个 tar - 输出列:
sample_id/key/dataset_name/shard/json/text/episode_index/frame_index/timestamp/task/state/action/video_uri/media_json - 媒体发布到
video_root(bos://或本地目录) - from_lance:每
maxcount个 sample 写一个shard-000000.tar
算子参数
输入
| 输入 | 含义 |
|---|---|
| input_col | to_lance:tar 目录 / glob / 单个 tar;from_lance:Lance 表路径 |
| output_col | to_lance:Lance 表路径;from_lance:输出目录 |
输出
| 输出 | 含义 |
|---|---|
| out | 输出位置(large_string) |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| direction | str | "to_lance" | to_lance / from_lance |
| dataset_name | str | "dataset" | 数据集名 |
| video_root | str 或 None | None | to_lance 媒体发布根(bos:// 或本地目录) |
| staging_dir | str 或 None | None | to_lance 媒体暂存目录 |
| maxcount | int | 1000 | from_lance 每个分片的 sample 数 |
| write_mode | str | "overwrite" | to_lance 写入模式:overwrite / create / append |
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.embodied.webdataset_lance_udf import WebDatasetLanceConverter
10
11if __name__ == "__main__":
12 if os.getenv("DAFT_RUNNER", "native") == "ray":
13 import ray
14 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
15 daft.set_runner_ray()
16 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
17
18ds = daft.from_pydict({
19 "src": ["/data/wds/train"],
20 "dst": ["bos://my-bucket/lake/wds_train.lance"],
21 })
22 ds = ds.with_column(
23 "out",
24 aihc_udf(
25 WebDatasetLanceConverter,
26 construct_args={
27 "direction": "to_lance",
28 "dataset_name": "wds_train",
29 "video_root": "bos://my-bucket/lake/wds_media",
30 },
31 num_cpus=1,
32 num_gpus=0,
33 concurrency=1,
34 batch_size=1,
35 )(col("src"), col("dst")),
36 )
37 ds.show()
评价此篇文章
