mPLUG-DocOwl icon indicating copy to clipboard operation
mPLUG-DocOwl copied to clipboard

TinyChart-visual encoder位置编码长度不匹配的错误

Open nth2000 opened this issue 1 year ago • 3 comments
trafficstars

首先感谢您的精彩工作。

目前我正在基于tinyllava模型利用tinychart数据复现训练流程,但是我发现bczhou/TinyLLaVA-3.1B-SigLIP中的visual encoder的image_size是384,vit_add_tome.py会将config中的image_size改成768。

因此在模型初始化时会基于image_size=768初始化sigLIP的position embedding的长度,但是bczhou/TinyLLaVA-3.1B-SigLIP checkpoint中的position embedding长度是基于image_size = 384的。将这个checkpoint中的参数load进来时导致了我在运行时产生了参数形状不匹配的错误。

能否请问下如何解决这个错误呢?非常感谢!

nth2000 avatar Jun 23 '24 12:06 nth2000

你好, tinychart采用插值的方式对tinyllava的position embedding进行扩展。你可以试试以下代码:

import math
import torch
import torch.nn.functional as F

def get_abs_pos(abs_pos, tgt_size):
    # abs_pos: L, C
    # tgt_size: M
    # return: M, C
    src_size = int(math.sqrt(abs_pos.size(0)))
    tgt_size = int(math.sqrt(tgt_size))
    dtype = abs_pos.dtype

    if src_size != tgt_size:
        return F.interpolate(
            abs_pos.float().reshape(1, src_size, src_size, -1).permute(0, 3, 1, 2),
            size=(tgt_size, tgt_size),
            mode="bicubic",
            align_corners=False,
        ).permute(0, 2, 3, 1).flatten(0, 2).to(dtype=dtype)
    else:
        return abs_pos

model = torch.load('pytorch_model.bin')
target_resolution = 768
target_length = (target_resolution // 14) ** 2
print(target_length)
model['vision_model.embeddings.position_embedding.weight'] = get_abs_pos(model['vision_model.embeddings.position_embedding.weight'], target_length)
torch.save(model, 'SigLIP-768/pytorch_model.bin')

zhangliang-04 avatar Jun 26 '24 09:06 zhangliang-04

首先感谢您的精彩工作。

目前我正在基于tinyllava模型利用tinychart数据复现训练流程,但是我发现bczhou/TinyLLaVA-3.1B-SigLIP中的visual encoder的image_size是384,vit_add_tome.py会将config中的image_size改成768。

因此在模型初始化时会基于image_size=768初始化sigLIP的position embedding的长度,但是bczhou/TinyLLaVA-3.1B-SigLIP checkpoint中的position embedding长度是基于image_size = 384的。将这个checkpoint中的参数load进来时导致了我在运行时产生了参数形状不匹配的错误。

能否请问下如何解决这个错误呢?非常感谢!

您好,我也遇到了同样的问题, 请问解决方案是什么?

yanchuqiao avatar Jul 12 '24 13:07 yanchuqiao

首先感谢您的精彩工作。 目前我正在基于tinyllava模型利用tinychart数据复现训练流程,但是我发现bczhou/TinyLLaVA-3.1B-SigLIP中的visual encoder的image_size是384,vit_add_tome.py会将config中的image_size改成768。 因此在模型初始化时会基于image_size=768初始化sigLIP的position embedding的长度,但是bczhou/TinyLLaVA-3.1B-SigLIP checkpoint中的position embedding长度是基于image_size = 384的。将这个checkpoint中的参数load进来时导致了我在运行时产生了参数形状不匹配的错误。 能否请问下如何解决这个错误呢?非常感谢!

您好,我也遇到了同样的问题, 请问解决方案是什么?

您好,我也遇到了同样的问题, 请问您知道解决方案了吗?想请教一下

yangyangyang-tong avatar Sep 04 '24 03:09 yangyangyang-tong