Tuna-2训练数据准备指南:t2i、图像编辑、MMU、纯文本4类jsonl格式完整清单

原创2026-10-28 12:13:021,331 阅读

Tuna-2训练数据准备指南:t2i、图像编辑、MMU、纯文本4类jsonl格式完整清单

Tuna-2 是 Meta 开源的统一多模态模型(Unified Multimodal Model),用像素嵌入(pixel embeddings)取代传统视觉编码器,一个模型同时完成图像理解、文生图(t2i)与图像编辑。本文以 Tuna-2 官方仓库中的 data_examples/ 目录为蓝本,给出 t2i、图像编辑(edit)、MMU、纯文本 4 类训练数据的 jsonl 格式完整清单、字段说明与混合采样配置,帮你一次性备齐 Tuna-2 微调数据。

Tuna-2架构演进:从TUNA到TUNA-R再到TUNA-2的视觉编码组件逐步剥离

一、4类训练数据总览

Tuna-2 采用4 路数据流加权混合训练(4-stream weighted sampling),每种任务对应一个 jsonl 清单文件:

数据流 data_type 核心字段 示例文件 默认采样权重
t2i 文生图 t2i image + caption ti_pairs.jsonl 50%
edit 图像编辑 edit_interleaved raw_image + out_image + instruction edit_pairs.jsonl 20%
mmu 多模态理解 mmu image + conversations mmu_pairs.jsonl 20%
text 纯文本 mmu_text conversations text_only.jsonl 10%

通用规则(适用于全部 4 类):

  • 文件编码 UTF-8,每行一个 JSON 对象,空行会被自动跳过;
  • 单行 JSON 解析失败时只告警、跳过该行,不会中断训练(见 _load_jsonl);
  • jsonl 中的图片相对路径以配置文件里的 image_root 为基准拼接,绝对路径则原样使用。

二、t2i 文生图:image + caption 两字段最简格式

字段清单:

字段 类型 必填 说明
image string ✅ 图片路径(相对 image_root 或绝对路径)
caption string ✅ 图片描述文本,即生成目标

示例(完整内容见 ti_pairs.jsonl):

{"image": "imgs/image1.png", "caption": "a woman with blonde-highlighted bob hair taking a selfie, wearing a pink lace sleeveless top, standing in front of a wooden paneled wall"}

Tuna-2文生图训练样例:金发女性自拍配详细caption

caption 写得越具体(主体、服装、姿态、背景),生成质量上限越高。官方样例 ti_pairs.jsonl 中每条 caption 都包含主体 + 细节 + 场景三层信息,例如这张日式定食图:

Tuna-2 t2i数据示例:含ikura三文鱼籽饭与味噌汤的日式定食

{"image": "imgs/image3.png", "caption": "a Japanese meal set with ikura salmon roe over white rice, a bowl of miso soup with tofu and green onions, chopsticks, and a small side dish on a placemat"}

💡 t2i 流同样支持 conversations 多轮对话形式,训练器会自动取最后一轮 human 作为 prompt,取 caption 优先。

对应配置:configs/data/ti_pairs.yaml

三、MMU 多模态理解:image + conversations 对话格式

MMU(Multimodal Understanding)数据训练模型的"看图说话"能力,采用标准 conversations 多轮对话结构:

字段 类型 必填 说明
image string ✅ 图片路径
conversations list ✅ 对话轮次列表,from 取 human/gpt(或 user/assistant),配 value 文本

示例(完整内容见 mmu_pairs.jsonl):

{"image": "imgs/image2.png", "conversations": [{"from": "human", "value": "What is unusual about this image?"}, {"from": "gpt", "value": "A miniature clothes iron is placed directly under the eye of an elderly person..."}]}

Tuna-2 MMU理解数据示例:眼下方放置迷你熨斗的超现实主义人像

要点:

  • MMU 模式下训练目标文本取最后一轮 gpt/assistant 的回答;
  • 官方加载代码中角色名 human/gpt 会自动映射为 HuggingFace chat template 的 user/assistant(见 tuna/data/datasets/ti_dataset.py);
  • 建议问答尽量覆盖描述、计数、空间关系、OCR 等多种理解类型,与官方样例保持一致的多样化风格。

对应配置:configs/data/mmu_pairs.yaml

四、图像编辑:raw_image + out_image + instruction 三字段

编辑数据训练"源图 + 指令 → 目标图"的能力,样本内部按 [文本指令][源图][目标图] 的顺序拼成统一 token 序列:

字段 类型 必填 说明
raw_image string ✅ 编辑前源图(条件输入)
out_image string ✅ 编辑后目标图(训练目标)
instruction string ✅ 编辑指令文本

示例(完整内容见 edit_pairs.jsonl):

{"raw_image": "imgs/edit0.png", "out_image": "imgs/edit0_target.png", "instruction": "add warm golden sunset lighting to the scene"}

官方 3 条样例覆盖了三种典型编辑方向:

  1. 光影调整 — add warm golden sunset lighting to the scene
  2. 风格迁移 — transform the image into Van Gogh's Starry Night painting style
  3. 局部修改 + 文字擦除 — zoom in on the flower and remove the text at the bottom

⚠️ 注意与 t2i 的字段区别:编辑数据不使用 image/caption,而是 raw_image/out_image/instruction,写错字段名会导致样本被静默跳过。

对应配置:configs/data/edit_pairs.yaml;数据集实现见 tuna/data/datasets/edit_dataset.py

五、纯文本对话:无 image 字段的 conversations

纯文本流用于防止模型在视觉训练中"语言能力退化",格式与 MMU 相同,但去掉 image 字段:

字段 类型 必填 说明
conversations list ✅ 同 MMU 的对话结构,from 为 human/gpt

示例(完整内容见 text_only.jsonl):

{"conversations": [{"from": "human", "value": "What is the capital of France?"}, {"from": "gpt", "value": "The capital of France is Paris, known for the Eiffel Tower, Louvre Museum, and its rich cultural heritage."}]}

数据集在缺少 image 字段时会自动构造占位图像张量,不会报错(data_type 设为 mmu_text)。对应配置:configs/data/text_only.yaml

六、混合采样权重与多分辨率配置

4 路数据流的默认权重定义在 configs/train/train.yaml 中,可按自己的数据量调整(sampling_weights 之和必须为 1):

data:
  sampling_weights:
    t2i: 0.50
    edit: 0.20
    mmu: 0.20
    text: 0.10
  streams:
    t2i:
      _target_: tuna.data.datasets.ti_dataset.TIDataset
      jsonl_path: ./data_examples/ti_pairs.jsonl
      image_root: ./data_examples
      image_size: 512
      data_type: t2i
      max_text_length: 2048
      multi_resolution: true

多分辨率训练默认开启,图片会按原生宽高比就近归入 5 个分辨率桶(512x512、448x576、576x448、384x672、672x384),因此建议准备的数据尽量覆盖不同宽高比,而非全部裁成正方形;开启 multi_resolution 时该流 batch_size 需为 1。

七、数据准备自检清单 ✅

  • [ ] 4 个 jsonl 文件均为 UTF-8 编码、每行一个合法 JSON
  • [ ] 图片相对路径均相对 image_root 可解析,无失效链接
  • [ ] t2i 数据每行含 image + caption
  • [ ] MMU / 纯文本数据 conversations 以 human 开头、gpt 结尾
  • [ ] 编辑数据使用 raw_image / out_image / instruction,且源图与目标图尺寸接近
  • [ ] 数据覆盖 512x512 至 672x384 多种宽高比(多分辨率桶)
  • [ ] sampling_weights 四项之和为 1

备齐数据后即可用官方示例数据做冒烟测试,再替换为自己的数据流路径:

python -m tuna.scripts.train \
    training.max_steps_per_epoch=4 \
    training.batch_size=1

参考资料

登录后查看全文
tuna-2