forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CI/Build] vLLM cache directory for images (vllm-project#6444)
- Loading branch information
1 parent
37d7766
commit d970115
Showing
13 changed files
with
123 additions
and
140 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from pathlib import Path | ||
|
||
import vllm.envs as envs | ||
|
||
|
||
def get_cache_dir(): | ||
"""Get the path to the cache for storing downloaded assets.""" | ||
path = Path(envs.VLLM_ASSETS_CACHE) | ||
path.mkdir(parents=True, exist_ok=True) | ||
|
||
return path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import shutil | ||
from dataclasses import dataclass | ||
from functools import cached_property, lru_cache | ||
from typing import Literal | ||
|
||
import requests | ||
from PIL import Image | ||
|
||
from vllm.multimodal.utils import fetch_image | ||
|
||
from .base import get_cache_dir | ||
|
||
|
||
@lru_cache | ||
def get_air_example_data_2_asset(filename: str) -> Image.Image: | ||
""" | ||
Download and open an image from | ||
``s3://air-example-data-2/vllm_opensource_llava/``. | ||
""" | ||
image_directory = get_cache_dir() / "air-example-data-2" | ||
image_directory.mkdir(parents=True, exist_ok=True) | ||
|
||
image_path = image_directory / filename | ||
if not image_path.exists(): | ||
base_url = "https://air-example-data-2.s3.us-west-2.amazonaws.com/vllm_opensource_llava" | ||
|
||
with requests.get(f"{base_url}/{filename}", stream=True) as response: | ||
response.raise_for_status() | ||
|
||
with image_path.open("wb") as f: | ||
shutil.copyfileobj(response.raw, f) | ||
|
||
return Image.open(image_path) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ImageAsset: | ||
name: Literal["stop_sign", "cherry_blossom", "boardwalk"] | ||
|
||
@cached_property | ||
def pil_image(self) -> Image.Image: | ||
if self.name == "boardwalk": | ||
return fetch_image( | ||
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" | ||
) | ||
|
||
return get_air_example_data_2_asset(f"{self.name}.jpg") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.