Skip to content

Commit d970115

Browse files
[CI/Build] vLLM cache directory for images (#6444)
1 parent 37d7766 commit d970115

File tree

13 files changed

+123
-140
lines changed

13 files changed

+123
-140
lines changed

.buildkite/download-images.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

.buildkite/test-pipeline.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ steps:
1212
fast_check_only: true
1313
commands:
1414
- pytest -v -s async_engine # Async Engine
15-
- bash ../.buildkite/download-images.sh # Inputs
1615
- pytest -v -s test_inputs.py
1716
- pytest -v -s multimodal
1817
- pytest -v -s test_utils.py # Utils
@@ -82,7 +81,6 @@ steps:
8281
working_dir: "/vllm-workspace/tests"
8382
num_gpus: 2
8483
commands:
85-
- bash ../.buildkite/download-images.sh
8684
- VLLM_TEST_SAME_HOST=1 torchrun --nproc-per-node=4 distributed/test_same_node.py
8785
- TEST_DIST_MODEL=facebook/opt-125m DISTRIBUTED_EXECUTOR_BACKEND=ray pytest -v -s distributed/test_basic_distributed_correctness.py
8886
- TEST_DIST_MODEL=meta-llama/Llama-2-7b-hf DISTRIBUTED_EXECUTOR_BACKEND=ray pytest -v -s distributed/test_basic_distributed_correctness.py
@@ -155,7 +153,6 @@ steps:
155153
- label: Inputs Test
156154
#mirror_hardwares: [amd]
157155
commands:
158-
- bash ../.buildkite/download-images.sh
159156
- pytest -v -s test_inputs.py
160157
- pytest -v -s multimodal
161158

@@ -175,7 +172,6 @@ steps:
175172
- label: Vision Language Models Test
176173
mirror_hardwares: [amd]
177174
commands:
178-
- bash ../.buildkite/download-images.sh
179175
- pytest -v -s models -m vlm
180176

181177
- label: Prefix Caching Test

examples/llava_example.py

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import os
2-
import subprocess
3-
4-
from PIL import Image
5-
61
from vllm import LLM
7-
8-
# The assets are located at `s3://air-example-data-2/vllm_opensource_llava/`.
9-
# You can use `.buildkite/download-images.sh` to download them
2+
from vllm.assets.image import ImageAsset
103

114

125
def run_llava():
136
llm = LLM(model="llava-hf/llava-1.5-7b-hf")
147

158
prompt = "USER: <image>\nWhat is the content of this image?\nASSISTANT:"
169

17-
image = Image.open("images/stop_sign.jpg")
10+
image = ImageAsset("stop_sign").pil_image
1811

1912
outputs = llm.generate({
2013
"prompt": prompt,
@@ -28,25 +21,5 @@ def run_llava():
2821
print(generated_text)
2922

3023

31-
def main():
32-
run_llava()
33-
34-
3524
if __name__ == "__main__":
36-
# Download from s3
37-
s3_bucket_path = "s3://air-example-data-2/vllm_opensource_llava/"
38-
local_directory = "images"
39-
40-
# Make sure the local directory exists or create it
41-
os.makedirs(local_directory, exist_ok=True)
42-
43-
# Use AWS CLI to sync the directory, assume anonymous access
44-
subprocess.check_call([
45-
"aws",
46-
"s3",
47-
"sync",
48-
s3_bucket_path,
49-
local_directory,
50-
"--no-sign-request",
51-
])
52-
main()
25+
run_llava()

examples/paligemma_example.py

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import os
2-
import subprocess
3-
4-
from PIL import Image
5-
61
from vllm import LLM
7-
8-
# The assets are located at `s3://air-example-data-2/vllm_opensource_llava/`.
9-
# You can use `.buildkite/download-images.sh` to download them
2+
from vllm.assets.image import ImageAsset
103

114

125
def run_paligemma():
136
llm = LLM(model="google/paligemma-3b-mix-224")
147

158
prompt = "caption es"
169

17-
image = Image.open("images/stop_sign.jpg")
10+
image = ImageAsset("stop_sign").pil_image
1811

1912
outputs = llm.generate({
2013
"prompt": prompt,
@@ -28,25 +21,5 @@ def run_paligemma():
2821
print(generated_text)
2922

3023

31-
def main():
32-
run_paligemma()
33-
34-
3524
if __name__ == "__main__":
36-
# Download from s3
37-
s3_bucket_path = "s3://air-example-data-2/vllm_opensource_llava/"
38-
local_directory = "images"
39-
40-
# Make sure the local directory exists or create it
41-
os.makedirs(local_directory, exist_ok=True)
42-
43-
# Use AWS CLI to sync the directory, assume anonymous access
44-
subprocess.check_call([
45-
"aws",
46-
"s3",
47-
"sync",
48-
s3_bucket_path,
49-
local_directory,
50-
"--no-sign-request",
51-
])
52-
main()
25+
run_paligemma()

examples/phi3v_example.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
import os
2-
import subprocess
3-
4-
from PIL import Image
5-
61
from vllm import LLM, SamplingParams
7-
8-
# The assets are located at `s3://air-example-data-2/vllm_opensource_llava/`.
9-
# You can use `.buildkite/download-images.sh` to download them
2+
from vllm.assets.image import ImageAsset
103

114

125
def run_phi3v():
@@ -24,7 +17,7 @@ def run_phi3v():
2417
max_num_seqs=5,
2518
)
2619

27-
image = Image.open("images/cherry_blossom.jpg")
20+
image = ImageAsset("cherry_blossom").pil_image
2821

2922
# single-image prompt
3023
prompt = "<|user|>\n<|image_1|>\nWhat is the season?<|end|>\n<|assistant|>\n" # noqa: E501
@@ -44,19 +37,4 @@ def run_phi3v():
4437

4538

4639
if __name__ == "__main__":
47-
s3_bucket_path = "s3://air-example-data-2/vllm_opensource_llava/"
48-
local_directory = "images"
49-
50-
# Make sure the local directory exists or create it
51-
os.makedirs(local_directory, exist_ok=True)
52-
53-
# Use AWS CLI to sync the directory, assume anonymous access
54-
subprocess.check_call([
55-
"aws",
56-
"s3",
57-
"sync",
58-
s3_bucket_path,
59-
local_directory,
60-
"--no-sign-request",
61-
])
6240
run_phi3v()

tests/conftest.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
import os
44
import sys
55
from collections import UserList
6-
from dataclasses import dataclass
7-
from functools import cached_property
8-
from pathlib import Path
9-
from typing import (Any, Dict, List, Literal, Optional, Tuple, TypedDict,
10-
TypeVar)
6+
from typing import Any, Dict, List, Optional, Tuple, TypedDict, TypeVar
117

128
import pytest
139
import torch
@@ -18,12 +14,12 @@
1814
AutoTokenizer, BatchEncoding)
1915

2016
from vllm import LLM, SamplingParams
17+
from vllm.assets.image import ImageAsset
2118
from vllm.config import TokenizerPoolConfig
2219
from vllm.distributed import (destroy_distributed_environment,
2320
destroy_model_parallel)
2421
from vllm.inputs import TextPrompt
2522
from vllm.logger import init_logger
26-
from vllm.multimodal.utils import fetch_image
2723
from vllm.sequence import SampleLogprobs
2824
from vllm.utils import cuda_device_count_stateless, is_cpu
2925

@@ -33,30 +29,13 @@
3329
_TEST_PROMPTS = [os.path.join(_TEST_DIR, "prompts", "example.txt")]
3430
_LONG_PROMPTS = [os.path.join(_TEST_DIR, "prompts", "summary.txt")]
3531

36-
_IMAGE_DIR = Path(_TEST_DIR) / "images"
37-
"""You can use `.buildkite/download-images.sh` to download the assets."""
38-
3932

4033
def _read_prompts(filename: str) -> List[str]:
4134
with open(filename, "r") as f:
4235
prompts = f.readlines()
4336
return prompts
4437

4538

46-
@dataclass(frozen=True)
47-
class ImageAsset:
48-
name: Literal["stop_sign", "cherry_blossom", "boardwalk"]
49-
50-
@cached_property
51-
def pil_image(self) -> Image.Image:
52-
if self.name == "boardwalk":
53-
return fetch_image(
54-
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
55-
)
56-
57-
return Image.open(_IMAGE_DIR / f"{self.name}.jpg")
58-
59-
6039
class _ImageAssetPrompts(TypedDict):
6140
stop_sign: str
6241
cherry_blossom: str

vllm/assets/__init__.py

Whitespace-only changes.

vllm/assets/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pathlib import Path
2+
3+
import vllm.envs as envs
4+
5+
6+
def get_cache_dir():
7+
"""Get the path to the cache for storing downloaded assets."""
8+
path = Path(envs.VLLM_ASSETS_CACHE)
9+
path.mkdir(parents=True, exist_ok=True)
10+
11+
return path

vllm/assets/image.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import shutil
2+
from dataclasses import dataclass
3+
from functools import cached_property, lru_cache
4+
from typing import Literal
5+
6+
import requests
7+
from PIL import Image
8+
9+
from vllm.multimodal.utils import fetch_image
10+
11+
from .base import get_cache_dir
12+
13+
14+
@lru_cache
15+
def get_air_example_data_2_asset(filename: str) -> Image.Image:
16+
"""
17+
Download and open an image from
18+
``s3://air-example-data-2/vllm_opensource_llava/``.
19+
"""
20+
image_directory = get_cache_dir() / "air-example-data-2"
21+
image_directory.mkdir(parents=True, exist_ok=True)
22+
23+
image_path = image_directory / filename
24+
if not image_path.exists():
25+
base_url = "https://air-example-data-2.s3.us-west-2.amazonaws.com/vllm_opensource_llava"
26+
27+
with requests.get(f"{base_url}/{filename}", stream=True) as response:
28+
response.raise_for_status()
29+
30+
with image_path.open("wb") as f:
31+
shutil.copyfileobj(response.raw, f)
32+
33+
return Image.open(image_path)
34+
35+
36+
@dataclass(frozen=True)
37+
class ImageAsset:
38+
name: Literal["stop_sign", "cherry_blossom", "boardwalk"]
39+
40+
@cached_property
41+
def pil_image(self) -> Image.Image:
42+
if self.name == "boardwalk":
43+
return fetch_image(
44+
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
45+
)
46+
47+
return get_air_example_data_2_asset(f"{self.name}.jpg")

vllm/distributed/device_communicators/custom_all_reduce_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ def gpu_p2p_access_check(src: int, tgt: int) -> bool:
189189
cuda_visible_devices = envs.CUDA_VISIBLE_DEVICES
190190
if cuda_visible_devices is None:
191191
cuda_visible_devices = ",".join(str(i) for i in range(num_dev))
192-
VLLM_CONFIG_ROOT = envs.VLLM_CONFIG_ROOT
193-
path = os.path.expanduser(
194-
f"{VLLM_CONFIG_ROOT}/vllm/gpu_p2p_access_cache_for_{cuda_visible_devices}.json"
195-
)
192+
193+
path = os.path.join(
194+
envs.VLLM_CACHE_ROOT,
195+
f"gpu_p2p_access_cache_for_{cuda_visible_devices}.json")
196196
os.makedirs(os.path.dirname(path), exist_ok=True)
197197
from vllm.distributed.parallel_state import get_world_group
198198
if ((not is_distributed or get_world_group().local_rank == 0)

0 commit comments

Comments
 (0)