终于抽时间看了 InternVL3’s paper 后的一些简单思考,感觉 InternVL3 上面的一些技术更新是值得学习借鉴的,所以写了一下简单思考

image.png

整体的架构依然是 Vit + Project + LM 的组合,InternViT-300M 和 InternViT-6B 则作为是 Vit 的选择,QwenLM2.5 和 InternLM3 则作为是 LM 部分的选择,Connector部分则是用多层的 MLP 作为连接两个模态之间转换的组件,并且是随机初始化的。

像素重排(Pixel Unshuffle)

In line with the approach taken in InternVL2.5, InternVL3 incorporates a pixel unshuffle operation to enhance scalability for processing high-resolution images. This operation reduces the visual token count to one-quarter of its original value, representing each 448×448 image tile with 256 visual tokens.

对于 Pixel Unshuffle 的解释

  1. 基本数学原理
  1. 具体重排过程

    def pixel_unshuffle(x, downscale_factor):
        batch_size, channels, height, width = x.shape    
        new_channels = channels * (downscale_factor ** 2)
        new_height = height // downscale_factor
        new_width = width // downscale_factor
        
        x = x.view(batch_size, channels, new_height, downscale_factor, 
                   new_width, downscale_factor)
        x = x.permute(0, 1, 3, 5, 2, 4)
        x = x.contiguous()
        x = x.view(batch_size, new_channels, new_height, new_width)
        
        return x
    

可变视觉位置编码 (V2PE)

这里提供了一种新的位置编码方式 —— Variable Visual Position Encoding

Variable Visual Position Encoding. InternVL3 also integrates the Variable Visual Position Encoding (V2PE) [1], which utilizes smaller, more flexible position increments for visual tokens. This modification facilitates the handling of longer multimodal contexts without excessively extending the position window.

$$ p_i = \begin{cases} 0, & \text{if } i = 1, \\ f_{\text{pos}}(p_{i-1}, x_i), & \text{for } i = 2,3,...,N. \end{cases} $$

paper中说在过去的跨模态位置编码的实现都是+1,与模态无关,这点不正确,在苏剑林的科学空间以及QwenVL、KimiVL等团队实现的 mRoPE 来看,并不是一味的+1,可看上一篇blogs关于这个的介绍,V2PE的设计是将文本token和图像token区分出来表示位置:

$$ p_i = p_{i-1} + \begin{cases} 1, & \text{if } x_i \text{ is a textual token}, \\ \delta, & \text{if } x_i \text{ is a visual token}, \end{cases} $$

其中 $δ$  是一个 <1的值,在同一张图中 $δ$ 相同,目的是为了维持在图片内的相对位置关系,在训练期间,系统会从一组预定义的分数值中随机为每幅图像选择:$\delta \in \Delta = \left\{1, \frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \frac{1}{16}, \frac{1}{32}, \frac{1}{64}, \frac{1}{128}, \frac{1}{256}\right\}$,通过不同的 $δ$ 来考虑训练时长文本的问题,在 inference的时候可以灵活选择 $δ$ 来使用,当 $δ$ ==1 的时候,则退化到 InternVL2.5 的位置编码逻辑了。当然我觉得这里更有的位置编码是苏剑林写的 RoPE-tie2 的方式,虽然会浪费很多位置编码,造成长文本的压力,但是在区分模态间,更加的清晰,且模态内都是保持等价+1的形式来增加位置信息。