type
status
date
slug
summary
tags
category
icon
password

1 为什么block-diagonal attention mask能避免packing时attention跨图片计算

 
给定多张图片在sequence维度上拼接的序列
给定Block Diagnoal Attention Mask
下面来计算Attention
先通过linear计算QKV,线性层时channel-mix的运算,没有token间的信息交互
再有Block Diagnoal Attention Mask 的Attention计算
从上述推导可见Block Diagnoal Attention Mask 能有效避免跨图片的token交互。

2 为什么Cross-Attention融合要引入attention mask

在cross-attention融合方案中(上文3.2节)。文本特征作为attention的query,图片特征作为key,value。由于在动态分辨率batch推理时,每张图片所得到的图片特征长度是不同的,因此在组batch时,需要进行padding补齐。为了避免padding token干扰attention score,需引入attention mask。
下面以batch中的一个sample为例,说明attention mask的工作机制:
Q为文本特征,shape为
K, V为图片特征, shape为 , 其中slice为为非padding的特征
为了保证padding位置特征不会干扰attention score,需引入的mask如下
证明:
为视角
可见,引入式6的mask后使得:,满足了计算等价。
再看看如果不加mask,结果有何差异:
不妨将不加mask的记作。以padding zero为例,即
 
从推导结果可见,二者存在一个系数差异。
相关文章
BLIP系列文章小结(BLIP, BLIP-2, InstructBLIP)
Lazy loaded image
BLIP-2小结
Lazy loaded image
BLIP 小结
Lazy loaded image
BLIP3技术小结(xGen-MM (BLIP-3): A Family of Open Large Multimodal Models)
Lazy loaded image
minigpt4系列小结
Lazy loaded image
MM1技术小结(MM1: Methods, Analysis & Insights from Multimodal LLM Pre-training)
Lazy loaded image
多模态模型如何处理任意分辨率输入——Tiling与Packing技术详解Nougat 深度剖析
Loading...
莫叶何竹🍀
莫叶何竹🍀
非淡泊无以明志,非宁静无以致远
最新发布
多模态模型如何处理任意分辨率输入——Tiling与Packing技术详解
2025-5-24
多模态模型如何处理任意分辨率输入——Tiling与Packing技术详解(part2)
2025-5-24
Attention Free Transformer(AFT)技术小结
2025-4-15
BLIP 小结
2025-4-13
BLIP系列文章小结(BLIP, BLIP-2, InstructBLIP)
2025-4-13
Nougat 深度剖析
2025-3-18