Realization · 落地实现
WM Realization — wm4d 世界模型多任务 v2
WAN2.1 DiT 1.3B + Wan-VAE + umT5 cross-attn + velocity head (GenCeption-faithful)。用信息缺口 逼模型真正使用 caption。
WAN2.1 DiT 1.3B
Wan-VAE
umT5 cross-attn
velocity head · GenCeption-faithful
① 动机 / 核心思想
② 任务集
③ 实现要点
④ 实验矩阵
⑤ 可控性证据
⑥ 架构设计
⑦ 训练流程
⑧ 推理流程
⑨ 网络结构
⑩ Prompt 设计
⑪ 复现信息
① 动机 / 核心思想
为什么要做多任务 v2:clean full latent 下 caption 被模型完全忽略。
诊断
在 clean full latent 条件下 caption 内容被完全忽略 :交换 caption 内容(caption swap)输出 L1 ≈ 0.014 (≈ 直接删除 caption 的效果);只有把 cross-attn 整条关掉(OFF) 输出才崩到 1.22 。根因——recon / depth / seg 是图像的确定性映射 ,给了干净全 latent,目标已被输入唯一决定,caption 信息冗余 ,模型自然学会不看它。
解法(无法造 paired data)
造不出「同图不同 caption 对应不同真值」的 paired data,于是走多任务 v2 :用 MAE / 噪声 / coarse 池化 / perceiver 主动制造信息缺口 H(Y|X) > 0 ——让输入不再唯一决定输出。caption 只注入生成类任务(ids 3–7) ,逼模型真正用 caption 去补上缺失的信息。
一句话
确定性任务 (recon/seg/depth)里 caption 是冗余的 → 模型不看;制造信息缺口 后目标不再被输入唯一决定 → caption 成为必要条件 ,模型被迫使用。门控开关:caption_task_ids = [3,4,5,6,7](开 id9 caption-perceiver 时 +9、开 id10 diffusion-transfer 时 +10)。
② 任务集 · 8 基础 + 3 门控扩展
基础任务 id0–7 ;门控扩展 id8 heavy-raw / id9 caption-perceiver / id10 diffusion-transfer (config-gated,默认 off 时逐位不变)。id / 名称 / 输入退化(制造信息缺口的方式)/ 是否注入 caption。
id 名称 输入退化(信息缺口) 注入 caption
0 recon 部分 MAE token 掩码 否
1 seg —(clean full latent,确定性映射) 否
2 depth —(clean full latent,确定性映射) 否
3 gen_mask 大块掩码 是
4 env_gen coarse 1×1 池化(单 token,原 8×8=64)+ 50% B-swap (换 B 样本 caption+z0 作 GT,coarse 仍取 A) 是
5 diffusion flow-matching 噪声 是
6 gen_mani 90% token → 噪声 是
7 recon_perceiver light 输入 = 噪声,只能经 128-token perceiver 看 z0;caption 进 perceiver 自注意力 (single-pass) 是
8 prompt_extract_perceiver heavy-raw · off 两遍 DiT · Pass2 从噪声仅凭 readout 重建(无 caption 变体,默认关) 否
9 caption_perceiver heavy 两遍 DiT · caption 进两 pass 自注意力 + 两段 prompt(extract / inject) 是
10 diffusion_transfer new 输入 = A 的 z0(clean 或随机-t 加噪);cond = B caption ;GT = B z0;20% B=A 是
注:caption 门控 = caption_task_ids [3,4,5,6,7](门控扩展开时 +9 / +10)——生成类任务(gen_mask / env_gen / diffusion / gen_mani / recon_perceiver)及 id9 caption-perceiver、id10 diffusion-transfer 注入 caption;recon / seg / depth 与 id8 heavy-raw 不注入。
③ 实现要点
caption 怎么进模型、perceiver 怎么造瓶颈、cond-stream 双流怎么写回、warm-start 怎么接。
caption-AdaLN-Zero ca 模式 caption_adaln
零初始化 AdaLN 头 把 umT5 caption 池化成条件向量 → 加到每个 DiT 块的时间调制 e0 ,按 caption 行门控 。
默认关闭时逐位不变 (零初始化 = 恒等起步,不扰动 baseline)。
开关 caption_adaln · 注入点 = 每个 DiT 块的 e0 时间调制
Perceiver id7 recon_perceiver · light perceiver_mode: ca|sa
6 层 (原 2 层)。单开关 perceiver_mode 同时控制【提取】(128 可学习 query 读干净 z0 )与【注入】(perceiver token → DiT image token),二者强制同模式 。
ca = cross-attn :query 交叉注意 z0 / token 进 cross-attn context。sa = self-attn :query 与 z0 拼接 做自注意力 / token 并入 image 自注意力序列,用 per-row self_attn_mask 隔离非 perceiver 行。
新增 · single-pass caption perceiver_caption_sa :sa 模式下把 caption tokens 拼进 perceiver 自注意力 序列(query + z0 + caption),input 仍为纯噪声 。与 id9 heavy 的 two-pass 构成 single-pass ↔ two-pass 对比。
默认 ca · 提取与注入模式强制一致 · perceiver_caption_sa 默认 off
cond-stream SA caption cond_attn_mode: ca|sa
sa 下 caption / 任务 token 作双流 attend 图像 K/V,并经零初始化 beta_img 门 做 image ← cond 双向写回 (MJ1 修复)。
step0 与 ca 逐位一致 ,随训练 caption 才开始影响图像。
开关 cond_attn_mode · beta_img 零初始化 → 起步无扰动
Heavy perceiver id9 caption-perceiver · two-pass capperc_two_prompt
两遍 DiT + caption 进两 pass 自注意力 。基于 id9 caption_perceiver + 开关 capperc_two_prompt:Pass1 EXTRACT (prompt「extract the scene content into compact tokens」)从干净 z0 提 128-token readout;Pass2 INJECT (prompt「generate the driving scene from the caption and compact tokens」)从噪声 凭 readout + caption 重建 z0。
两 pass 用不同 task-prompt ,caption 在两 pass 都进 perceiver 自注意力 。因两遍 DiT 显存重 → bs = 2 。 (原始 id8 prompt_extract_perceiver 是无 caption 的独立变体,默认关;"heavy" 实验走 id9 + two-prompt。)
id9 + capperc_two_prompt · caption-in-SA(both passes) · 与 id7 light 成 single↔two-pass 对比
Diffusion-transfer id10 · new diffusion_transfer_task
独立 rectified-flow 任务 (与 id5 diffusion 分开、不混)。输入 = A 样本的 z0(clean 或随机-t 加噪,各 50%);条件 = B 样本 caption ;GT = B 的 clean z0;20% B=A 。prompt =「diffusion transfer」。
逼模型把 A 的内容按 B caption 迁移 → 直接量测 caption 对生成的驱动力。B 样本经 batch 内 roll-by-1 取(需 batch≥2)。
id10 · 复用 _genception_v_loss flow · caption_task_ids +10
init_ckpt warm-start
4 组实验均从 baseline 26415 的 step12000 非严格加载 (matched = 858, unexpected = 0)。新增参数(6 层 perceiver 的后 4 层 / caption_ada / cond-stream / heavy )保持各自初始化;caption_ada 输出零初始化 = 恒等起步 ,保证 warm-start 起点与 baseline 行为一致、不破坏已学表征。
strict=False load · matched=858 · unexpected=0 · 新增参数各自初始化
输出头与解码
GenCeption-faithful velocity head + Wan-VAE 解码 ——velocity(flow-matching)预测忠于 GenCeption 设定,latent 经 Wan-VAE 解回像素。
velocity head (GenCeption-faithful) → Wan-VAE decode
④ 当前实验矩阵
全部 32 卡 、warm-start 自 26415 step12000 、perceiver ca 6 层 。
组 exp cond_attn_mode caption_adaln cond_adaln_zero heavy batch 说明
A_baseline 26617 ca off off off 4 ca 参照基线
caadaln 26618 ca on off off 4 主干 caption-AdaLN-Zero
B_sa 26619 sa off off off 2 caption 走 cond-stream 双向 SA
D_heavy 26620 sa on on on 2 两遍 DiT heavy perceiver(→ 现 id9 caption-perceiver)
显存 —— ca = bs4 便宜;sa = bs2 (cond-stream + image←cond 额外激活);heavy = bs2 (两遍 DiT)。
新训练模式 · 单任务激活(single-task)
在多任务矩阵之外新增单任务激活 实验:task_weights 设为 one-hot (每次只激活一个 task),DDP 安全靠 0.0·_mt2_param_tether() 保证未激活分支参数仍参与图。用于隔离验证 本轮 4 处改动。下列 config 已就绪、待提交 (本页尚无其运行数据):
config 激活 task task_weights 关键开关 warm-start
mt2_st_task4 id4 env_gen8-long · idx4=1 coarse_hw:1 · task4_bswap · sa+adaln D_heavy/18000
mt2_st_lightperc id7 light-perc8-long · idx7=1 perceiver_caption_sa A_dl/18000
mt2_st_heavy id9 caption-perc10-long · idx9=1 caption_perceiver_task · capperc_two_prompt capperc/18000
mt2_st_difftransfer id10 diff-transfer11-long · idx10=1 diffusion_transfer_task A_dl/18000
⑤ baseline 可控性证据
来自 wm_vis (26415 · step9000 ):交换 caption A ↔ B 的输出 latent-L1 (越大 = caption 越可控)。
diffusion 1.032
gen_mask 0.251
recon_perceiver 0.153
env_gen 0.056
gen_mani 0.036
最新结论(驱动本轮重设计)
(a) 除纯 diffusion (id5)外,图像条件 任务(env_gen / gen_mask / gen_mani / perceiver)基本忽略 caption ——上图 diffusion L1=1.032 一枝独秀,其余都低。(b) perceiver 重建质量差 (recon_perceiver 仅 0.153,且成像模糊)。(c) 主要症结 = perceiver + caption 。→ 据此重设计 id4 (1×1 coarse + 50% B-swap)、id7 (caption 进 perceiver SA)、id9 heavy (two-pass caption-perceiver + 两段 prompt),并新增 id10 diffusion-transfer 直接量测 caption 驱动力。
⑥ 架构设计图 · 整体主干
单视图 latent → 逐任务退化 → patch-embed → WAN2.1 DiT(cross-attn 注入 umT5)→ velocity head → Wan-VAE 解码。
umT5 text encoder
task-prompt [ ; caption ]
4096 → 1536 cross-attn ctx
v3 侧输入 → DiT
cond-stream SA
caption-AdaLN modulation
perceiver tokens
Wan-VAE · encode
single-view latent z0 [16ch · 90×160]
per-task 输入退化
patch-embed Conv3d kernel 1×2×2
tokens [Ld=3600 · dim=1536]
WAN2.1 DiT 1.3B 30 blocks · 12 heads cross-attn → umT5
velocity head GenCeption-faithful
reconstruct ẑ0
Wan-VAE · decode
image
整体架构 :多 task head(id0–7 基础 + id8/9/10 门控扩展 )共享同一 DiT backbone;cond-stream SA / caption-AdaLN / perceiver 为 v3 可选侧输入(开关见 §③)。
⑦ 训练设计图 · build_mt2_inputs → forward → v-loss
每样本按 task_weights 抽任务、施加退化、按需注入 caption;warm-start 后算逐任务 GenCeption velocity loss。
latents train · gt_depth_gf · gt_seg · caption_lang
build_mt2_inputs draw task ~ multinomial(task_weights) · 单任务=one-hot apply 退化 · inject caption iff id ∈ {3,4,5,6,7 (+9,+10)}
batch · 32 卡 · per-GPU bs 3 或 2
WM4DModel.forward warm-start 自 26415 · init_ckpt · strict=False
per-task GenCeption v-loss velocity → reconstruct z0 flow-matching x_t=(1−t)·z0 + t·ε [gen tasks]
DDP bf16 AdamW · warmup · ckpt / 3000 steps
训练流程 :任务采样 + 退化 + 条件注入都在 build_mt2_inputs 完成;生成类任务走 flow-matching 加噪。
4 组配置开关 A_baseline = ca | caadaln = ca + caption-AdaLN | B_sa = cond-stream SA | D_heavy = sa + AdaLN + heavy two-pass。
⑧ Infer 设计图 · predict_latent + 可控性量测
推理与训练同构:退化 → forward(umT5 ctx) → velocity → 解码;可控性 = 同任务改 caption A/B 测 latent-L1。
predict_latent(task, scene)
load clean z0
degrade per task MAE mask · noise · coarse-pool · perceiver-compress
model.forward + umT5 context task prompt [ ; caption ]
velocity → reconstruct ẑ0
Wan-VAE decode → image
推理主链 :predict_latent 逐任务退化后前向,velocity 重建 ẑ0 再解码成图。
同一生成任务 · 固定场景 id ∈ {3,4,5,6,7}
forward · caption A → out_A
forward · caption B → out_B
latent-L1( out_A , out_B ) 越大 = caption 越可控
可控性量测 :仅改 caption(A→B),量测两输出 latent-L1(逐任务数值见 §⑤)。
推理注意 · caption-AdaLN 为训练期专用 主干 caption-AdaLN 路径当前仅训练期生效,推理时为 no-op ;推理阶段 caption 的影响经 umT5 cross-attn (sa 模式下另加 cond-stream )注入。
⑨ 网络结构设计图 · WanAttentionBlock 内部
单个 DiT block(×30):AdaLN-Zero → Self-Attn(3D RoPE) → Cross-Attn(umT5) → FFN → Head。
WanAttentionBlock ×30
e0 = time_projection(t)
caption-AdaLN head (zero-init) pool umT5 caption → e0_cap gated → caption rows [caadaln]
+
e0 (+ e0_cap)
AdaLN-Zero modulation 6 chunks: shift/scale/gate ×2
Self-Attention · 3D RoPE cond-stream(sa): bi-dir β / β_img
Cross-Attention → umT5 ctx image span · n_img = Ld
FFN
cond-stream (sa) cond↔img: β, β_img(zero-init) step0 ≡ ca · bidirectional MMDiT
umT5 context 1536-dim
Head head_norm + AdaLN(e) + Linear + unpatchify → velocity
Block 内部 :AdaLN-Zero 由 e0 调制(caadaln 时额外加 zero-init caption e0_cap,门控到 caption 行);Self-Attn 带 3D RoPE,sa 模式下 cond-stream 经 β/β_img 双向写回(step0 与 ca 逐位一致);Cross-Attn 注入 umT5(仅 image span,n_img=Ld);末端 Head 出 velocity。
input = noise
128 learnable queries depth 6 · ca|sa · +cap(sa)
clean z0
caption → perceiver SA
128 compressed tokens info bottleneck
reconstruct z0
Perceiver(id7 recon_perceiver · light) :input=noise,z0 只能经这 128 个压缩 token 恢复;perceiver_caption_sa 时 caption 也进 perceiver 自注意力(single-pass )。
caption → SA (both passes)
clean z0
Pass1 · 30-layer DiT prompt: EXTRACT extract scene → compact tokens
128-token readout 仅此进 Pass2
noise
Pass2 · reconstruct z0 from noise prompt: INJECT · readout + caption generate scene from caption + compact tokens · grad_ckpt
Heavy(id9 caption-perceiver · two-pass) :Pass1 EXTRACT 从干净 z0 提 128-token readout,Pass2 INJECT 从噪声凭 readout+caption 重建 z0;caption 在两 pass 都进 perceiver 自注意力 ,两 pass 用不同 prompt 。原始 id8 prompt_extract_perceiver 为无 caption 变体、默认关。
⑩ Prompt 设计 · umT5 任务提示 + caption
每任务基础 prompt(configs/umt5_prompts_v2.json)经 umT5 编码成 per-block cross-attn context;生成类任务再拼接真实 caption。
task prompt [ ; caption ]
umT5 encoder
4096-dim
text_embedding
per-block cross-attn ctx 1536-dim
umT5 管线 :prompt(+caption)→ umT5 → 4096-dim → text_embedding → 1536-dim 每块 cross-attn context。
id task prompt (EN) umT5 tokens caption
0 recon reconstruct the driving scene 6 no
1 seg segment the scene into semantic classes 8 no
2 depth estimate the depth map 5 no
3 gen_mask inpaint the missing regions of the driving scene 10 YES
4 env_gen generate the driving scene from the coarse environment layout 11 YES
5 diffusion generate a driving scene 5 YES
6 gen_mani edit the driving scene following the description 8 YES
7 recon_perceiver reconstruct the driving scene from its compressed tokens 12 YES
8 prompt_extract_perceiver heavy-raw · off (extract-perceiver 原型 · 无 caption) — no
9 caption_perceiver · Pass1 heavy extract the scene content into compact tokens — YES
9 caption_perceiver · Pass2 heavy generate the driving scene from the caption and compact tokens — YES
10 diffusion_transfer new diffusion transfer — YES
说明: 生成类任务(ids 3–7)在 task prompt 之后拼接 该帧真实 caption (来自 caption_lang,caption_task_ids=[3,4,5,6,7],开 id9/id10 时 +9 / +10);非生成任务只看 task prompt。门控扩展 :id9 caption-perceiver 两 pass 用不同 prompt (extract / inject)且 caption 进 perceiver 自注意力;id10 diffusion-transfer 用 prompt「diffusion transfer」+ B 样本 caption。改动 2/4 的新 prompt 在 umt5_prompts_v3.pt,改动 1/3 仍用 umt5_prompts_v2。文件中另有 det: detect the objects in the scene,不在当前任务集内。
⑪ repo / branch / 复现信息
代码仓库、关键 commit、实验配置、warm-start ckpt 与当前训练任务。
代码仓库 · wm4d
repo:https://git.neodrive..net/longshan/wm4d.git · 分支 main
8aa13ff wm4d mt2: OOM fix from local single-GPU smoke (verified) — 最新
ff8fb09 v3.1 caption-AdaLN + 6L configurable perceiver
b497313 init_ckpt warm-start
1d1fc68 configurable CA/SA + AdaLN + heavy
本轮 4 处改动(task4 1×1+B-swap · id7 perceiver_caption_sa · id9 capperc_two_prompt · id10 diffusion_transfer )为 config-gated (默认 off = 逐位不变),在分支 feat/v3-arch(wm4d_v3);CPU sanity 全绿,云端实验尚未提交。
实验配置文件
configs/mt2_A_baseline.yaml
configs/mt2_caadaln.yaml
configs/mt2_B_sa.yaml
configs/mt2_D_heavy.yaml
(+ 各自 _test smoke 变体)
warm-start ckpt
/mnt/pfs/personal/world_model/wm4d_runs/mt2_1hz_gf/ckpt_step12000.pt
来自 baseline 实验 26415 · step12000
当前实验(训练平台 · 32 卡 · warm-start · 首步实测显存无 OOM)
exp 组 配置 首步显存
26634 A_baseline ca 64 GB
26635 caadaln ca + caption-AdaLN 64 GB
26636 B_sa cond-stream SA 72 GB
26637 D_heavy sa + AdaLN + heavy 52 GB
注:26634–26637 为按上述配置文件重提交、首步显存实测无 OOM 的当前批 ;§④ 矩阵中的 26617–26620 为前一批。
展示站仓库
repo:https://git.neodrive..net/longshan/personal_demo_files.git · 分支 main (本页所在)
生成时间:2026-08-28
代码 commit:wm4d main 分支 v3.1 — caption-AdaLN + 6L configurable perceiver + init_ckpt warm-start
诚实边界: 本页记录当前实验的配置与实现要点(多任务 32 卡实验均 warm-start 自 baseline 26415 step12000),可控性数据来自 26415 step9000 的 wm_vis 推理。本轮新增 的 4 处 config-gated 架构改动(id4 / id7 / id9 heavy / id10 diffusion-transfer,默认 off 逐位不变)与 4 个单任务激活 config 均已就绪、待提交 ,本页尚无其运行数据;结论 (a)/(b)/(c) 来自既有观察。数值随训练进展修订,勿当最终结论。