Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
bc6ad367
Unverified
Commit
bc6ad367
authored
Jan 05, 2025
by
Yineng Zhang
Committed by
GitHub
Jan 05, 2025
Browse files
fix lint (#2733)
parent
3a22a303
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
13 deletions
+12
-13
scripts/playground/reference_hf.py
scripts/playground/reference_hf.py
+12
-13
No files found.
scripts/playground/reference_hf.py
View file @
bc6ad367
...
@@ -26,11 +26,12 @@ I'm going to the
...
@@ -26,11 +26,12 @@ I'm going to the
import
argparse
import
argparse
import
requests
import
requests
from
PIL
import
Image
import
torch
import
torch
from
PIL
import
Image
from
transformers
import
(
from
transformers
import
(
AutoModelForCausalLM
,
AutoProcessor
,
AutoModelForImageTextToText
AutoModelForCausalLM
,
AutoModelForImageTextToText
,
AutoProcessor
,
)
)
from
sglang.srt.hf_transformers_utils
import
get_tokenizer
from
sglang.srt.hf_transformers_utils
import
get_tokenizer
...
@@ -39,8 +40,7 @@ from sglang.srt.hf_transformers_utils import get_tokenizer
...
@@ -39,8 +40,7 @@ from sglang.srt.hf_transformers_utils import get_tokenizer
@
torch
.
no_grad
()
@
torch
.
no_grad
()
def
vlm_text_with_image
(
args
):
def
vlm_text_with_image
(
args
):
# Load the processor and model for ImageTextToText tasks
# Load the processor and model for ImageTextToText tasks
processor
=
AutoProcessor
.
from_pretrained
(
processor
=
AutoProcessor
.
from_pretrained
(
args
.
model_path
,
trust_remote_code
=
True
)
args
.
model_path
,
trust_remote_code
=
True
)
model
=
AutoModelForImageTextToText
.
from_pretrained
(
model
=
AutoModelForImageTextToText
.
from_pretrained
(
args
.
model_path
,
args
.
model_path
,
torch_dtype
=
args
.
dtype
,
torch_dtype
=
args
.
dtype
,
...
@@ -64,11 +64,8 @@ def vlm_text_with_image(args):
...
@@ -64,11 +64,8 @@ def vlm_text_with_image(args):
{
{
"type"
:
"image"
,
"type"
:
"image"
,
},
},
{
{
"type"
:
"text"
,
"text"
:
"Describe this image."
},
"type"
:
"text"
,
],
"text"
:
"Describe this image."
}
]
}
}
]
]
...
@@ -84,11 +81,13 @@ def vlm_text_with_image(args):
...
@@ -84,11 +81,13 @@ def vlm_text_with_image(args):
if
not
hasattr
(
processor
,
"apply_chat_template"
):
if
not
hasattr
(
processor
,
"apply_chat_template"
):
raise
ValueError
(
"The processor does not support chat templates."
)
raise
ValueError
(
"The processor does not support chat templates."
)
text_prompt
=
processor
.
apply_chat_template
(
text_prompt
=
processor
.
apply_chat_template
(
conversation
,
add_generation_prompt
=
True
)
conversation
,
add_generation_prompt
=
True
)
# Prepare inputs for the model
# Prepare inputs for the model
inputs
=
processor
(
text
=
[
text_prompt
],
images
=
[
image
],
inputs
=
processor
(
text
=
[
text_prompt
],
images
=
[
image
],
return_tensors
=
"pt"
).
to
(
return_tensors
=
"pt"
).
to
(
"cuda:0"
)
"cuda:0"
)
# Generate output from the model
# Generate output from the model
output_ids
=
model
.
generate
(
output_ids
=
model
.
generate
(
...
...
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