2024-03-25 14:16:30 -07:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
2024-06-03 13:56:41 +08:00
|
|
|
from PIL import Image
|
2024-03-25 14:16:30 -07:00
|
|
|
|
|
|
|
from vllm import LLM
|
|
|
|
|
|
|
|
# The assets are located at `s3://air-example-data-2/vllm_opensource_llava/`.
|
2024-06-03 13:56:41 +08:00
|
|
|
# You can use `.buildkite/download-images.sh` to download them
|
2024-03-25 14:16:30 -07:00
|
|
|
|
|
|
|
|
2024-07-02 00:57:09 -07:00
|
|
|
def run_llava():
|
2024-03-25 14:16:30 -07:00
|
|
|
llm = LLM(
|
|
|
|
model="llava-hf/llava-1.5-7b-hf",
|
|
|
|
image_token_id=32000,
|
|
|
|
image_input_shape="1,3,336,336",
|
|
|
|
image_feature_size=576,
|
|
|
|
)
|
|
|
|
|
2024-07-03 11:34:00 +08:00
|
|
|
prompt = "USER: <image>\nWhat is the content of this image?\nASSISTANT:"
|
2024-03-25 14:16:30 -07:00
|
|
|
|
2024-07-02 00:57:09 -07:00
|
|
|
image = Image.open("images/stop_sign.jpg")
|
2024-05-29 04:29:31 +08:00
|
|
|
|
|
|
|
outputs = llm.generate({
|
2024-06-03 13:56:41 +08:00
|
|
|
"prompt": prompt,
|
2024-07-02 00:57:09 -07:00
|
|
|
"multi_modal_data": {
|
|
|
|
"image": image
|
|
|
|
},
|
2024-05-29 04:29:31 +08:00
|
|
|
})
|
2024-03-25 14:16:30 -07:00
|
|
|
|
|
|
|
for o in outputs:
|
|
|
|
generated_text = o.outputs[0].text
|
|
|
|
print(generated_text)
|
|
|
|
|
|
|
|
|
2024-07-02 00:57:09 -07:00
|
|
|
def main():
|
|
|
|
run_llava()
|
2024-03-25 14:16:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# Download from s3
|
|
|
|
s3_bucket_path = "s3://air-example-data-2/vllm_opensource_llava/"
|
|
|
|
local_directory = "images"
|
|
|
|
|
|
|
|
# Make sure the local directory exists or create it
|
|
|
|
os.makedirs(local_directory, exist_ok=True)
|
|
|
|
|
2024-03-28 14:36:10 -07:00
|
|
|
# Use AWS CLI to sync the directory, assume anonymous access
|
|
|
|
subprocess.check_call([
|
|
|
|
"aws",
|
|
|
|
"s3",
|
|
|
|
"sync",
|
|
|
|
s3_bucket_path,
|
|
|
|
local_directory,
|
|
|
|
"--no-sign-request",
|
|
|
|
])
|
2024-07-02 00:57:09 -07:00
|
|
|
main()
|