Files
sglang/examples/quick_start/srt_example_llava.py

39 lines
810 B
Python
Raw Normal View History

2024-01-24 11:44:07 +00:00
"""
Usage: python3 srt_example_llava.py
"""
2024-01-18 13:46:38 -08:00
import sglang as sgl
@sgl.function
def image_qa(s, image_path, question):
s += sgl.user(sgl.image(image_path) + question)
s += sgl.assistant(sgl.gen("answer"))
2024-01-24 10:35:31 +00:00
runtime = sgl.Runtime(model_path="liuhaotian/llava-v1.5-7b",
tokenizer_path="llava-hf/llava-1.5-7b-hf")
2024-01-18 13:46:38 -08:00
sgl.set_default_backend(runtime)
2024-01-24 11:44:07 +00:00
# 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")
2024-01-18 13:46:38 -08:00
runtime.shutdown()