从图像 token 到视频 token
将潜空间图像切成 patch 后,Transformer 处理的是 token 序列。若潜空间帧大小为 H×W、patch 边长为 p、帧数为 F,则简化 token 数为 F×(H/p)×(W/p)。这里假设 H、W 可整除 p,且时间维没有额外压缩。
全局注意力的分数矩阵大小随 token 数平方增长。将帧数加倍可能使注意力分数元素增加至四倍,但真实耗时还受算子、分块注意力和硬件影响,不能直接据此宣称四倍总成本。
可运行的规模计算
import assert from "node:assert/strict";
function videoTokens(frames, height, width, patch) {
if (![frames,height,width,patch].every(Number.isSafeInteger) ||
Math.min(frames,height,width,patch) <= 0 ||
height % patch || width % patch) throw new Error("invalid shape");
return frames * (height/patch) * (width/patch);
感谢阅读本文
如果你觉得内容有帮助,欢迎点赞支持或分享给同行开发者。
787 次阅读|53 人赞过