Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
67abdbb4
Unverified
Commit
67abdbb4
authored
Aug 09, 2024
by
Isotr0py
Committed by
GitHub
Aug 09, 2024
Browse files
[VLM][Doc] Add `stop_token_ids` to InternVL example (#7354)
parent
07ab1607
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
6 deletions
+17
-6
examples/offline_inference_vision_language.py
examples/offline_inference_vision_language.py
+17
-6
No files found.
examples/offline_inference_vision_language.py
View file @
67abdbb4
...
...
@@ -124,16 +124,27 @@ def run_minicpmv(question):
# InternVL
def
run_internvl
(
question
):
# Generally, InternVL can use chatml template for conversation
TEMPLATE
=
"<|im_start|>User
\n
{prompt}<|im_end|>
\n
<|im_start|>Assistant
\n
"
prompt
=
f
"<image>
\n
{
question
}
\n
"
prompt
=
TEMPLATE
.
format
(
prompt
=
prompt
)
model_name
=
"OpenGVLab/InternVL2-2B"
llm
=
LLM
(
model
=
"OpenGVLab/InternVL2-4B"
,
model
=
model_name
,
trust_remote_code
=
True
,
max_num_seqs
=
5
,
)
stop_token_ids
=
None
tokenizer
=
AutoTokenizer
.
from_pretrained
(
model_name
,
trust_remote_code
=
True
)
messages
=
[{
'role'
:
'user'
,
'content'
:
f
"<image>
\n
{
question
}
"
}]
prompt
=
tokenizer
.
apply_chat_template
(
messages
,
tokenize
=
False
,
add_generation_prompt
=
True
)
# Stop tokens for InternVL
# models variants may have different stop tokens
# please refer to the model card for the correct "stop words":
# https://huggingface.co/OpenGVLab/InternVL2-2B#service
stop_tokens
=
[
"<|endoftext|>"
,
"<|im_start|>"
,
"<|im_end|>"
,
"<|end|>"
]
stop_token_ids
=
[
tokenizer
.
convert_tokens_to_ids
(
i
)
for
i
in
stop_tokens
]
return
llm
,
prompt
,
stop_token_ids
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment