UMAP可视化
Qwen2.5VL输入的input ids的token embedding的UMAP可视化:
其中type 0代表img token的占位符,由于都是同样的token,所以在空间距离上接近
type1代表system prompt的token
type2代表text token
Qwen2.5VL输入的input ids的token embedding+将img token的占位符换成经过ViT的实际img token的UMAP可视化:
可以看出此时img token和text token还是分为了明显不同的簇
在经过LLM之后得到的最后一层的hidden embedding中,UMAP显示此时的img token基本上和text token融合到了一起。其中type4代表img token之间的<|vision_start|>和<|vision_end|> token
直接将LLM得到的最后一层的hidden embedding经过mlp head并按照最大概率转换成ids,并用detokenizer解码得到text,发现视觉token基本上转化为了图像里面包含的物体的名字,这进一步说明其实最后visual token已经对齐到了text语意空间。
<|im_end|><|im_end|>A.. AI assistant<|im_end|><|im_end|> <|im_start|> <|im_end|>This<|im_end|><|im_end|>0 and<|im_end|>, and picture and,,边door,, <|im_end|> <|im_end|><|im_end|> wall and on and picture painting picture blue picture边,,,, curtains. door0 picture on, on and,,, on on,,,,, hotel on picture picture picture,, picture on,,,.,<|im_end|> room<|im_end|> room hotel onpicture picture picture, picture,边,,..,,<|im_end|> wall door wallpicture to picture边 on on black picture,,,, curtain,<|im_end|>,, to,,pictureful画 above,,,, curtain,, 0 door inowel,,,,picture, room,, curtain,<|im_end|>door2 door wall above bottom, above, picture picture,,,, curtainscur curtains, wall,,owel, of white on white andbox curtain towel. curtains shower6, door wall door to,, white towel on white white curtain curtain.. curtain5 door, to, white white on on,, , ,垂 door bathroom to, box box to on top white ,. curtain curtains curtains curtain7 wall knobskk knob and toilet paper toilet影 tan to curtain toilet <|im_end|><|im_end|><|im_end|>0画<|im_end|><|im_end|> picture wall框ful,, ,, curtains<|im_end|><|im_end|><|im_end|><|im_end|>,, to above, and pictureful room curtains curtains, curtains curtains curtains curtains<|im_end|> on0 picture picture above picture、 andpicture, door door curtains in. curtains curtain hotel on picture in and picture frame, frame black picture curtains picture to. hotel art hotel to wall door Picture picture picture picture边, board. curtains curtains curtains.<|im_end|> above, and wall 边 picture, and by picture frame,2 curtains white white curtains curtains room on picture picture picture colors , picture picture to, shower curtains. room to,ewire picture picture, picture,,s picture picture curtains curtains above picture, IH above mirrorpicture picture picture pictureicturegreen. painting on. between <|im_end|> curtains room in curtains to1 wall on picture Picture picture,, picture. room, on.. , toilet above to picture picture<|im_end|>边 picture picture frame to curtains curtains curtains curtains pattern, door, door ", to above to picture, to curtains abstract curtains tan , to door wall above picture below to wall toilet to to door cream doorcur. chain yellow tub0, abstract, toilet,,,, camera, curtains door curtains curtains curtains curtains shower<|im_start|><|im_end|><|im_end|>1 and<|im_end|><|im_end|>, room,,, wall,, white curtain head, curtains<|im_end|> wall to\ above aboveboard, yellow wall corner in of hook curtain on,, to0 curtain to, and wall curtain,, to curtains-ring for.,, curtain curtains picture on picture picture picture picture above directly above curtains. curtain, curtains above curtain curtains<|im_end|> wall showerpicture picture andpicture hotel above curtains, curtain,cur curtains,<|im_end|> wall to picture on picture, room shower, wallcur curtainscur. beigecur curtain,, to frame border frame picture frame边 board to curtaincurling drawnining, ,ish on frame picture,, picture picture picture picture curtain, above curtainsishish curtain) left toilet picture Picture,,, on框 bathroom curtaincurcur.ish bathroomcur picture wall on picture picture blue and, Picture on of yellow. above rings green to. door wall to picture , and painting to on of curtainsaw curtainsled curtain texture pattern curtain0 framedfulblue and and,picture and bathroom curtains cream rings, curtains , door door to picture colored画 picture, picture to area curtains to curtain cream curtains door, door0 black black frame<|im_end|> above frame picture to, curtains caramel curtains curtains shower to curtains door bathroom<|im_end|><|im_end|>0 and<|im_end|> pattern, picture picture and, curtains shower - curtains towel<|im_end|> <|im_end|>, wall picture picture, and,, on, curtains curtains curtains. curtains<|im_end|> , space0 picture picture,、, picture., curtains to curtain, shower , hotel door on picture picture green,),ful,. to curtain,,robe curtain door wall picture picture image, painting, picture above shower,垂 curtains<|im_end|> curtain, wall on above picture below on above black, to curtain curtains curtain. hotel toilet, curtain hotel, toilet picture black above边, on, curtain, side curtains.,,, toilet, paper to wall to to,,, room, to toilet, curtains to, door door above above, above to wall to to curtaincur side curtainsy,it curtain, hotel wall bathroom on white white towel , corner curtain. curtains. bathroom curtains white to, to, white white towel on tocur., curtains curtain The by,,iler color to white on towel on on to to, draped yellow back1 bath bathroom to white white on on toilet cover to curtain. to. curtains curtains� tub1 door,, and on of, Ни curtains curtain toilet curtains curtain curtains tub curtainpicture<|im_end|><|im_end|> and<|im_end|> picture ,,, beigeaint 前 curtain,,<|im_end|> wall hotel color toilet, Holidaycur room curtains curtain curtains ,距,, toilet<|im_end|> and to on to single ,. to式. curtain vanity <|im_end|> paper w on on on onower, to式ish. up隔 stall, dooruters on on bath towel white, to curtain$$$ishuum curtains curtain tubish, wall to white on on on on shape,.igeuring curtains., on to, side, of cup on white toilet,右侧. curtains curtain垂. tubr tub, cupto, on silver to toilet room<|im_end|> stall room<|im_end|><|im_end|>, to ,, other silver, toilet white bowl, to right curtain hotelyc2.ush tub,, paper silver stall paper to to to to side curtains.. shower tocur, tub. paper paper bin to white to toilet to to tocur curtain tub tub curtain tub tub bin bin box to and curtains toilet toilet<|im_end|> seat toilet curtains, bathtub tub to-bottom, can bin trash left white to toilet tub toilet to white side shower垂 tub tubbat bathtub7 trash trash floor white lid toilet toilet door厕 toilet toilet curtains tub bathtub in-bottom bathtub bathroom<|im_end|><|im_end|> toilet on,,, curtains tub curtain caramel<|im_end|> 隔塑<|im_end|>室<|im_end|> towel on towel, on top,黄色纹 curtain curtainiped动 tub tub tub,<|im_end|><|im_end|> toilet toilet white tù tà curtains to curtain 隔 curtain tub bathtub in tub),) toilet toilet sil toilet tub curtain paper黄色 acc bathtub tubPicturehtub,,插, side tub white white垂.生 curtain.色 curtain curtain tub经济 end , to cover toilet, to to, curtain hotel drawn to curtainahu tub, tub wall bin in to tub lid curtain. shower bathtubow, tub, tub bin can pipe, stall to toilet , curtain bathtub tub tub , at can under to toilet lid lid hood bathtub lid curtains shower tub tub tub tub a at can can toto toilet to toilet bathtub bathtub toilet tub tub tub<|im_end|> tub bathtub can trash to. toilet lid toilet toilet<|im_end|> bowl curtain white on on tub.bat tub bin under hotel<|im_end|> c toilet toilet toilet lid wash on toiletwhite on by in bathtub p floor toilet floorestyle to<|im_end|> <|im_end|>. trash white towel on tubbat picture5地 door picture towel floor to<|im_end|>�单<|im_end|> floor<|im_end|>, on white on . tub standard<|im_end|><|im_end|> towel<|im_end|><|im_end|><|im_end|> box<|im_end|><|im_end|><|im_end|><|im_end|><|im_end|><|im_end|><|im_end|><|im_end|><|im_end|><|im_end|><|im_end|><|im_end|> detailed<|im_end|><|im_end|><|im_end|> object is<|im_end|><|im_end|><|im_end|><|im_end|><|im_end|>label",<|im_end|><|im_end|><|im_end|><|im_end|>D coordinates box<|im_end|> thebbox_3d".<|im_end|><|im_end|>3D coordinates box of is<|im_end|>:x,, y,, z_center, width_size, y_size, z_size, yaw, pitch, pitch]<|im_end|> <|im_start|><|im_end|>``````对LLM的attention进行可视化
对attention进行可视化发现确实出现了attetnion sink的情况:
Qwen2.5VL 3B一共有36个layer
feature dim是2048,head数是16,每个head管128维的子向量
选择可视化Qwen2.5VL的第一个head的前100个token的attention map:
由于是自回归,存在causal attention的attention mask,因此非零的attention只会出现在对角线的左下角
可以观察到在某些维度确实出现了attention sink的情况。
但是最后由于token的数量过多(1k+以上),导致全局的attention map基本看不出东西
疑问:当token序列过长时会不会出现attention值过度平滑的情况?(attention的总和必须为1)
答案:其实在绝大多数情况下,由于softmax的存在,很多attention对应的值都是非常稀疏的,对于大多数token的attention基本都是0
第100个token对前100个token的causal attention的分布图(比较特殊):
绝大多数情况都是大部分attention的值都接近于0: