OpenGVLab / InternVL

[CVPR 2024 Oral] InternVL Family: A Pioneering Open-Source Alternative to GPT-4o. 接近GPT-4o表现的开源多模态对话模型
https://internvl.readthedocs.io/en/latest/
MIT License
5.24k stars 409 forks source link

请问怎样使用基于internvl-v1.5 之后的模型文件? #310

Closed Qinger27 closed 3 weeks ago

Qinger27 commented 2 months ago

总算使用 internvl- v1.5 做完微调了,非常感谢你们的工作!现在想问下怎么使用微调后的模型呀?使用 transformers 的 AutoModel.from_pretrained 函数加载时报错缺少很多配置文件,我要从 internvl-1.5 那里复制过来吗?怎么确认自己是否使用的是微调后的模型参数呀?

期待好心人的解答~

njzfw1024 commented 2 months ago

总算使用 internvl- v1.5 做完微调了,非常感谢你们的工作!现在想问下怎么使用微调后的模型呀?使用 transformers 的 AutoModel.from_pretrained 函数加载时报错缺少很多配置文件,我要从 internvl-1.5 那里复制过来吗?怎么确认自己是否使用的是微调后的模型参数呀?

期待好心人的解答~

从预训练文件中复制过来就行

Weiyun1025 commented 1 month ago

如果您希望用我们的代码训练完后得到的权重也能通过AutoModel.from_pretrained加载的话需要做如下操作:

  1. 该目录下的模型结构代码全部复制到ckpt的目录下
  2. 将关于internvl的import改成相对路径的import,例如from internvl.model.internlm2.modeling_internlm2 import InternLM2ForCausalLM修改为from .internlm2.modeling_internlm2 import InternLM2ForCausalLM
  3. 在config中添加如下内容:
    "architectures": [
    "InternVLChatModel"
    ],
    ### 添加以下内容 ###
    "auto_map": {
    "AutoConfig": "configuration_internvl_chat.InternVLChatConfig",
    "AutoModel": "modeling_internvl_chat.InternVLChatModel",
    "AutoModelForCausalLM": "modeling_internvl_chat.InternVLChatModel"
    },
    ### 添加以上内容 ###
    "downsample_ratio": 0.5,
  4. modeling_intern_vit.py替换成我们发布出的modeling_intern_vit.py,否则ViT部分的FlashAttention会存在ImportError
czczup commented 3 weeks ago

总算使用 internvl- v1.5 做完微调了,非常感谢你们的工作!现在想问下怎么使用微调后的模型呀?使用 transformers 的 AutoModel.from_pretrained 函数加载时报错缺少很多配置文件,我要从 internvl-1.5 那里复制过来吗?怎么确认自己是否使用的是微调后的模型参数呀? 期待好心人的解答~

从预训练文件中复制过来就行

是的,复制过来就好了