add a batch llava example

This commit is contained in:
Lianmin Zheng
2024-01-24 11:44:07 +00:00
parent 6dceab4d17
commit 711d343530
2 changed files with 23 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ image benchmark source: https://huggingface.co/datasets/liuhaotian/llava-bench-i
### Other Dependency
```
pip3 install "sglang[all]"
pip3 install "torch>=2.1.2" "transformers>=4.36" pillow
```

View File

@@ -1,3 +1,6 @@
"""
Usage: python3 srt_example_llava.py
"""
import sglang as sgl
@@ -12,7 +15,24 @@ runtime = sgl.Runtime(model_path="liuhaotian/llava-v1.5-7b",
sgl.set_default_backend(runtime)
state = image_qa.run(image_path="images/cat.jpeg", question="What is this?")
print(state["answer"])
# Single
state = image_qa.run(
image_path="images/cat.jpeg",
question="What is this?",
max_new_tokens=64)
print(state["answer"], "\n")
# Batch
states = image_qa.run_batch(
[
{"image_path": "images/cat.jpeg", "question":"What is this?"},
{"image_path": "images/dog.jpeg", "question":"What is this?"},
],
max_new_tokens=64,
)
for s in states:
print(s["answer"], "\n")
runtime.shutdown()