llava_example.py 1.27 KB
Newer Older
1
2
3
import os
import subprocess

4
from PIL import Image
5
6
7
8

from vllm import LLM

# The assets are located at `s3://air-example-data-2/vllm_opensource_llava/`.
9
# You can use `.buildkite/download-images.sh` to download them
10
11


12
def run_llava():
13
14
15
16
17
18
19
20
21
22
    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,
    )

    prompt = "<image>" * 576 + (
        "\nUSER: What is the content of this image?\nASSISTANT:")

23
    image = Image.open("images/stop_sign.jpg")
24
25

    outputs = llm.generate({
26
        "prompt": prompt,
27
28
29
        "multi_modal_data": {
            "image": image
        },
30
    })
31
32
33
34
35
36

    for o in outputs:
        generated_text = o.outputs[0].text
        print(generated_text)


37
38
def main():
    run_llava()
39
40
41
42
43
44
45
46
47
48


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)

49
50
51
52
53
54
55
56
57
    # Use AWS CLI to sync the directory, assume anonymous access
    subprocess.check_call([
        "aws",
        "s3",
        "sync",
        s3_bucket_path,
        local_directory,
        "--no-sign-request",
    ])
58
    main()