Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support internvl2 chat template #1911

Merged
merged 4 commits into from
Jul 5, 2024
Merged

Conversation

AllentDan
Copy link
Collaborator

No description provided.

@lvhan028
Copy link
Collaborator

lvhan028 commented Jul 4, 2024

InternVL2 defines 3 types of chat templates.
https://huggingface.co/OpenGVLab/InternVL2-26B/blob/main/conversation.py#L333
Among the currently released models, 2B/8B/26B adopt internlm2-chat while 4B uses phi3-chat.
We should consider them all.

@lvhan028 lvhan028 requested review from RunningLeon and lvhan028 July 4, 2024 08:49
@lvhan028 lvhan028 added the enhancement New feature or request label Jul 4, 2024
@lvhan028 lvhan028 mentioned this pull request Jul 4, 2024
@lvhan028
Copy link
Collaborator

lvhan028 commented Jul 4, 2024

Please fix the UT error

@lvhan028
Copy link
Collaborator

lvhan028 commented Jul 4, 2024

@zhulinJulia24 may update TC

@lvhan028 lvhan028 requested a review from zhulinJulia24 July 5, 2024 05:13
@czczup
Copy link

czczup commented Jul 5, 2024

Hi, I feel that it may not be necessary to implement these three chat templates separately. For InternVL2-2B/8B/26B, we can simply use the chat template of internlm2-chat. The main difference is the system prompt.

I used the following code to run the InternVL2 model, and it seems to work well based on my tests.

from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig
from lmdeploy.vl import load_image

model = 'OpenGVLab/InternVL2-2B'
system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态基础模型。人工智能实验室致力于原始技术创新,开源开放,共享共创,推动科技进步和产业发展。'
image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
chat_template_config = ChatTemplateConfig('internlm2-chat')
chat_template_config.meta_instruction = system_prompt
pipe = pipeline(model, chat_template_config=chat_template_config,
                backend_config=TurbomindEngineConfig(session_len=8192))
response = pipe(('describe this image', image))
print(response.text)

@czczup
Copy link

czczup commented Jul 5, 2024

For InternVL2-4B, can the Phi3 chat template be used directly? I see there is an implementation here.

@lvhan028
Copy link
Collaborator

lvhan028 commented Jul 5, 2024

Hi, @czczup thanks for the suggestion.
But I am concerned that it may not be user-friendly, as users are required to be aware of setting the chat template.

@lvhan028 lvhan028 merged commit a1ca810 into InternLM:main Jul 5, 2024
5 checks passed
@zhulinJulia24 zhulinJulia24 mentioned this pull request Jul 16, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants