Bernini T2V 下一步优化规划
更新日期:2026-07-02
Baseline 命名和相对加速分母统一遵循
inference_baseline_naming.md:官方原始路径称为
pristine baseline;新设计的严格分母必须是同运行、仅关闭候选方法的
optimized-stack baseline。
总目标
在固定的 8x H100、Ulysses 8、480x848、81 帧、50-step T2V 配置上继续降低 单视频热推理延迟,同时保持三条边界清晰:
- 无损优化必须与
dense quality reference对应视频逐字节一致。 - 近似优化必须分别报告执行 step、E2E、Diffusion、逐帧指标和人工评价。
- microbenchmark 只有在真实 module shape、真实 dtype、完整 layout/quant 开销下 获得收益,才允许进入 full pipeline。
P0:锁定推荐配置和 optimized-stack baseline
工作项
- 在同一节点重跑
current optimized-stack baseline(dense lossless)、recommended_easycache、recommended_easycache_pisa三档六 prompt matrix。 - 对 PISA + EasyCache 扫少量 threshold,使实际 DiT forward 接近 28.6/50;候选从 0.09、0.10、0.11 开始,保持 retain 4 + last 1。
- 固化 profile fingerprint、模型 snapshot、Torch/Triton/PISA commit、GPU 名称和 每 rank peak memory。
- 为 static T2V cache 增加真实行为测试:prompt 隔离、RNG state、payload device。
- 为 CPU-master manager 增加 parameter replacement/mismatch 恢复和异常路径 teardown 测试。
通过门槛
- Dense lossless 的 6/6 视频与 reference SHA256 一致。
- 两个近似档均无 decode/shape/fps 错误,日志有完整 stage/action timing。
- 第二档只有在实测 forward 数接近目标后,才可以写“28.6 step + PISA”。
P1:压缩约 23 秒 cache-insensitive 成本
1. Rank-leader condition execution
当前 Qwen、T5 和部分纯 T2V preprocess 在 8 个 Ulysses rank 上重复。先让组内 leader 执行,再广播最终 embedding、latent distribution parameters 和必要 metadata。
验证顺序:2-step smoke -> 2 prompt 50-step exact -> 6 prompt exact。广播前后 tensor 的 shape、dtype、stride 和 RNG 消耗必须一致;热 E2E 至少节省约 1 s 才保留。
2. DiT root-H2D + NCCL/NVLink broadcast
当前每个 rank 都从 host 装载相同 expert。先用真实 weight bucket 做 microbenchmark:
- all-rank parallel H2D;
- rank 0 H2D + bucketed NCCL broadcast;
- 每 GPU 分片 H2D + all-gather。
分别覆盖约 50 MB QKV/out projection、约 135 MB FFN projection 和整 expert bucket。 计入 pinning、同步和 allocator 开销。只有每次 expert load 稳定节省至少约 1 s 且不 拖慢 normal step,才整体集成。
3. Expert 2 延迟预取
在 root-H2D/broadcast 方案确定后,测试在 high-noise expert 最后 1、2、4 step 开始 预取 expert 2。不能重新采用全程双 expert resident;已有结果证明它让 normal step 显著变慢。接受标准:总 diffusion 降低,normal-step 中位数退化不超过 2%,peak memory 留有稳定余量。
4. VAE decode 与保存拆分
把约 4.1 s 的 VAE/decode/save 进一步拆成 GPU decode、D2H、颜色/布局转换和 ffmpeg 编码。依次验证 inference mode、channels-last、局部 compile 和 pinned async copy。 异步编码可以提高吞吐,但不能把后台未完成的工作从单请求 latency 中删掉。
P2:Kernel、attention 和低精度
FP8 GEMM
动态 FP8 只让 FFN-up 的单 module 获益,quant 开销和一次性 weight conversion 抵消 了 full-pipeline 收益。下一轮改为:
- 模型加载时一次性生成 FP8 weight + scale,跨 request 重用;
- 按 expert、layer 和 timestep bucket 校准 activation scale;
- 分别测 QKV/out、FFN-up、FFN-down、cross-KV 的真实 M/K/N;
- microbench 同时报告 BF16、动态 FP8、预量化 FP8、误差和额外显存;
- 逐 module gate 通过后,再做 2-step 和 6-prompt full integration。
初始门槛:含 quant/layout 的 module 至少 1.15x、normal step 至少 1.08x,且不存在 31.5 s 的 request 内 lazy quant 成本。
PISA attention
- 消除
[tokens, heads, dim]与 head-major 之间多余 contiguous copy。 - 单独测 routing/top-k、layout、sparse kernel、concat 四段。
- 扫 density、起始 layer、结束 layer和 timestep schedule,而不是只扫全局 density。
- 让 EasyCache threshold 与 PISA 联合校准,避免把 FA3 的 skip 统计直接套用。
- 质量评价加入 CLIP/text alignment、运动指标和人工盲评。
Compile 与 CUDA Graph
在 shape 和 allocator 行为稳定后,对单个 normal DiT step 评估 torch.compile 和
CUDA Graph。expert swap、variable-length metadata 和 cache hit/miss 分支需要拆成
独立 graph;先证明 capture/replay 不改变 collective 次序,再做端到端集成。
P3:Diffusion cache 算法
EasyCache
- 在更大的 T2V prompt 集上拟合 threshold 与质量/step 曲线。
- 分别记录 high-noise 和 low-noise expert 的 hit 率,允许 expert-specific threshold。
- 研究 timestep-aware threshold 和最小执行预算,降低不同 prompt 的 25-35 step 波动。
- 除平均值外,报告最差 prompt 和 temporal flicker。
TeaCache
当前 Wan2.1-14B polynomial 不适合 Bernini 双 expert。下一轮必须按两个 expert 的 真实 residual 曲线分别拟合系数,再比较同执行预算下的 EasyCache。未重新拟合前, TeaCache 不进入推荐 profile。
P4:并行策略与跨硬件解释
- 复测 8x H100、4x B200 的相同模型、相同代码、相同计时边界,解释此前约 200 s B200 数据是否来自优化前路径、不同 offload 或不同通信拓扑。
- 评估 Ulysses + tensor parallel 的 2D 并行,减少单 rank projection 和 attention 工作;必须包含新增 collective 成本。
- 对多请求吞吐场景单独测试较小 Ulysses + data parallel,不与单视频 latency 混报。
- 只有当 H2D/broadcast 和 kernel 方向达到瓶颈后,再考虑参数分片/FSDP-like runtime。
统一实验协议
每项优化按以下顺序推进:
- 记录 hypothesis、目标 module、真实 shape、理论上限和可能的质量风险。
- module-wise microbenchmark,包含 warmup、P50/P90、峰值显存和完整前后处理开销。
- 2-step 单 prompt correctness smoke。
- 50-step 两 prompt A/B,固定 seed,检查逐阶段绝对时间和 SHA/SSIM。
- 六 prompt validator,首条单列 cold,后五条报告 hot mean、median、worst。
- 只有通过门槛的开关进入推荐 profile;失败结果也保留在 benchmark 文档中。
所有速度结论必须同时给出 reference:pristine baseline 只作官方原始锚点;严格
增量分母必须是同节点、同进程、只关闭当前候选方法的 optimized-stack baseline。
同时报告是否包含模型加载、是否排除首条 warmup、是否包含 VAE/save。禁止把跨节点
的 108.094 s、83.152 s 和 75.441 s 直接当成同条件 A/B。
近期交付顺序
| 优先级 | 交付物 | 目标 |
|---|---|---|
| P0 | 三档同节点 validator + PISA 28.6-step 校准 | 关闭当前最大数据缺口 |
| P1 | rank-leader condition prototype | 降低 non-diffusion 重复工作 |
| P1 | root-H2D/broadcast microbench | 降低约 8.1 s diffusion fixed 中的 H2D 部分 |
| P1 | expert 2 overlap prototype | 隐藏 switch H2D |
| P2 | 静态 FP8 weight/scale microbench | 判断 FP8 是否值得 full integration |
| P2 | PISA layout/layer/timestep sweep | 提高 attention 收益/质量比 |
| P3 | EasyCache/TeaCache 联合校准 | 建立可控的速度-质量档位 |