# Bernini Editing 下一步优化规划 更新日期:2026-07-02 当前同节点五例 hot-inference 结果为 pristine `1714.106 s`、editing lossless `1138.782 s`,总和口径 `1.505x`。后续工作分成 **lossless system track** 和 **approximate algorithm track**,两条轨道使用不同正确性和质量门槛,结果不得混报。 ## 统一定义 ### Lossless system track 保持同一实数算法和数学映射:模型权重、40-step scheduler、dense attention、 CFG/APG 分支、conditioning 和随机采样不变。允许等价重排、批处理、通信 overlap、 cache 和不同的 BF16 reduction tiling,因此不要求跨实现 bitwise equality。 通过条件是公式/排列 oracle、serial differential、RNG 与 cache lifecycle test、真实 GPU shape audit 和五例同节点 hot A/B 全部通过。PSNR/SSIM、SHA 和人工 contact sheet 只作诊断,不代替数学语义审计。 ### Approximate algorithm track PISA sparse attention、FP8 quantization、EasyCache、TeaCache、step skipping 和其他 改变算子或实际计算量的方法都属于近似轨道。必须同时报告速度、真实执行工作量、 数值误差和视频质量;即使视觉结果可接受,也不能标为 lossless。 ## P0:强化基准与审计 1. 在同一 allocation 中交替运行 pristine 与 optimized,至少三轮 measure,报告每例 median、P90、range 和 `sum(pristine)/sum(optimized)`,降低节点时序噪声。 2. 增加 request-stage timer:media preprocess、planner、T5、expert H2D/switch、 DiT normal step、VAE decode、D2H/postprocess。所有 stage 合计必须闭合到 synchronized request walltime。 3. 固化 Torch/CUDA/FA3/NCCL/Triton、model snapshot、输入 SHA、launcher env、GPU clocks 和峰值显存;统一 pristine/optimized 的 FA3 wrapper 后再复测 dependency normalization 的影响。 4. 补一个 live 8-GPU `all_to_all_single` vs legacy `all_to_all` differential,覆盖五例 实际 source+target sequence length、global padding trim 和 async stream event。 5. 扩大 real-Wan differential 到 expert 1/2、多个 block 和真实五例 metadata;逐层 检查 packed segment 不串扰,而不是追求最终视频逐比特一致。 ## P1:Lossless 条件路径去重 ### Rank-leader planner/encoder 当前八个 Ulysses rank 重复执行 media condition、Qwen planner 和 T5。评估由 group leader 计算确定性 embedding/distribution parameters,再广播最终 tensor 和 metadata。 必须保持 dtype、shape、stride、mask、token ordering 与原路径一致;涉及 latent sample 时只广播 distribution parameters,仍在原逻辑位置消费 RNG,或证明一次采样广播与 原分布/RNG 合同等价。 验证顺序:单模块 broadcast microbench、两例 2-step differential、五例 40-step 同节点 A/B。只有 E2E 有稳定正收益且 69/69 CPU suite、GPU formula audit 和 cache lifecycle 均通过,才进入默认 launcher。 ### 跨请求 media cache 把当前 request-local media dedupe 扩展为 server-lifetime immutable cache,key 至少包含 文件内容 SHA、duration/fps、resize/crop/normalize 参数、model snapshot、dtype 和 encoder version。只缓存确定性 payload 或 distribution parameters,不缓存本应重新 sample 的 latent;提供 LRU、显存/主存预算和请求结束引用释放。 ### Condition/metadata cache 整理 统一 condition projection、RoPE、mask、`cu_seqlens` 和 packed-condition 的 key 与 失效策略。为 tensor mutation/version、expert switch、shape collision、异常 teardown、 并发 request 隔离增加测试,避免为了命中率放宽语义条件。 ## P1:Lossless 权重搬运与 overlap ### Root H2D + NCCL broadcast 当前每个 rank 从 host 各自搬运同一 expert。按真实 QKV/out、FFN-up/down 和整 expert bucket 比较:all-rank H2D、rank-0 H2D + NCCL broadcast、分片 H2D + all-gather。 microbenchmark 必须计入 pinning、allocator、event 和 collective,同一 weight bit pattern 到达每个 rank 后再做 module output differential。 ### Expert 2 延迟预取 在 expert 1 的最后若干 step 用独立 copy stream 预取 expert 2,并用 event 精确约束 首次消费。不得恢复双 expert 全程 resident,因为已有 profiling 显示它会拖慢 normal step。验收同时看 request E2E、normal-step P50/P90 和 peak memory。 ### Offload 生命周期 继续审计 `CpuMasterModule` 的 parameter replacement、shared storage、异常退出和 repeated request teardown。探索 pinned CPU master 与 bucketed async H2D,但禁止在 timer 外偷跑 属于当前请求的必要 transfer。 ## P2:Lossless DiT 与 decode 1. 对固定 shape bucket 评估 `torch.compile` 和 CUDA Graph。expert switch、不同 editing layout、packed branch count 和 cache hit/miss 应拆成显式 graph;先验证 collective 次序和 RNG state,再测 E2E。 2. 继续融合 target patch、mask gather、APG delta 和 output unpatchify 中的纯 elementwise 链。每个 fused kernel 都对独立 FP32/FP64 公式 oracle,并使用实际 5120 hidden dim、 BF16 和 production token length。 3. 对 RV2V 动态 branch set 自动选择 chunk 1-5,目标是减少 launch overhead 与峰值显存, 但 branch boundary、zero-scale alias 和 APG reference 必须与 serial oracle 一致。 4. 拆分 VAE decode、D2H、layout/color conversion 和 MP4 encode。热 latency 只可 overlap 真正能与同请求前序并行的工作;后台未完成任务不能从 latency 中删除。 5. 评估 channels-last、decode-only compile、pinned async D2H 和预分配 output buffer, 逐项验证 decode tensor 的数值容差和 frame/layout 顺序。 ## P3:Approximate attention 与低精度 ### PISA 先按 editing 的真实 module shape 做 self-attention microbenchmark,完整计入 routing、 top-k、layout conversion、sparse kernel 和 concat。扫描 density、layer range、timestep schedule 与 V2V/RV2V branch shape;只有模块端到端正收益后才集成完整五例。 PISA 报告必须包括实际 attention density、每层/每 timestep 命中、E2E/stage speedup、 数值误差、PSNR/SSIM、文本一致性、运动指标和人工盲评。cross-attention 是否保持 dense 要单独写明。 ### FP8 在模型加载时预生成 FP8 weight/scale,避免 request 内 lazy quant。分别测 QKV/out、 FFN-up/down、cross-KV 的真实 M/K/N,比较 per-tensor、per-channel 和 timestep-aware activation scale。module gate 需要同时报告含 quant/layout 的速度、误差和显存;FP8 始终属于 approximate track。 ## P3:Approximate diffusion cache ### EasyCache 对 V2V、MV2V、RV2V、ADS2V 分任务记录 high/low-noise expert 的实际 DiT forward 数和 hit schedule。扫描 threshold、retain-first、retain-last 和最小执行预算;速度必须从 同运行、只关闭 EasyCache 的 optimized-stack baseline 计算。 ### TeaCache 不能直接复用 Wan2.1/T2V polynomial。先用 Bernini editing 双 expert 的 residual curve 分别拟合系数,再在与 EasyCache 相同的实际 forward budget 下比较最差 case、temporal flicker 和 source/reference adherence。 ### 组合档 PISA、FP8 与 diffusion cache 会相互改变 residual 和数值轨迹。组合实验必须重新校准, 不能把单项 speedup 相乘,也不能沿用单项的 executed-step 或质量数据。推荐档至少保留: - dense lossless reference; - one-method optimized-stack baseline; - PISA-only、cache-only、FP8-only; - 明确参数的组合候选。 ## 统一实验门槛 每个候选按以下顺序推进: 1. 写明数学变换、可复用条件、潜在失效模式和理论上限。 2. 用实际 dtype/shape/layout 做 module microbenchmark,报告 warmup、P50/P90、峰值显存 和所有前后处理开销。 3. 运行 CPU semantic suite、2-step 单例和相关 GPU oracle。 4. 同节点跑五例 warmup+measure;lossless 候选保持 dense 40-step,approximate 候选记录 实际 DiT forward、density 或 quantization 配置。 5. lossless 以算法/数学语义通过为 gate;approximate 另做逐帧指标、source adherence、 motion/text metrics 和人工评价。两者的表格、命名和结论分开。 6. 只保留同节点重复实验中的稳定正收益;负结果和 no-op 也记录,避免重复探索。 ## 近期交付顺序 | 优先级 | 交付物 | 目标 | | --- | --- | --- | | P0 | 三轮同 allocation 五例 A/B + stage ledger | 收紧 1.505x 的方差和瓶颈解释 | | P0 | live 8-GPU collective + real metadata audit | 补齐当前 world-size-2 硬件覆盖限制 | | P1 | rank-leader planner/T5 prototype | 删除 Ulysses rank 间确定性重复计算 | | P1 | root-H2D/broadcast microbench | 降低每 rank 重复 expert transfer | | P1 | expert-2 prefetch prototype | 隐藏不可避免的 expert switch H2D | | P1 | server-lifetime immutable media cache | 降低重复素材请求的 preprocess 成本 | | P2 | graph/compile + decode microbench | 降低固定 launch 和 decode 开销 | | P3 | PISA/FP8 module gates | 决定近似 kernel 是否值得 full integration | | P3 | Editing-specific EasyCache/TeaCache calibration | 建立独立、可解释的速度-质量档位 | 所有新速度必须同时注明分母、commit、job、节点、计时边界和是否包含 model load。 `pristine baseline` 只作 upstream 锚点;候选的增量收益必须相对同运行、仅关闭该候选的 `optimized-stack baseline`。