Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
86ab567b
Unverified
Commit
86ab567b
authored
Aug 11, 2024
by
Roger Wang
Committed by
GitHub
Aug 12, 2024
Browse files
[CI/Build] Minor refactoring for vLLM assets (#7407)
parent
f020a629
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
26 deletions
+35
-26
vllm/assets/base.py
vllm/assets/base.py
+29
-1
vllm/assets/image.py
vllm/assets/image.py
+6
-25
No files found.
vllm/assets/base.py
View file @
86ab567b
from
functools
import
lru_cache
from
pathlib
import
Path
from
pathlib
import
Path
from
typing
import
Optional
import
vllm.envs
as
envs
import
vllm.envs
as
envs
from
vllm.connections
import
global_http_connection
from
vllm.envs
import
VLLM_IMAGE_FETCH_TIMEOUT
vLLM_S3_BUCKET_URL
=
"https://vllm-public-assets.s3.us-west-2.amazonaws.com"
def
get_cache_dir
():
def
get_cache_dir
()
->
Path
:
"""Get the path to the cache for storing downloaded assets."""
"""Get the path to the cache for storing downloaded assets."""
path
=
Path
(
envs
.
VLLM_ASSETS_CACHE
)
path
=
Path
(
envs
.
VLLM_ASSETS_CACHE
)
path
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
path
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
return
path
return
path
@
lru_cache
def
get_vllm_public_assets
(
filename
:
str
,
s3_prefix
:
Optional
[
str
]
=
None
)
->
Path
:
"""
Download an asset file from ``s3://vllm-public-assets``
and return the path to the downloaded file.
"""
asset_directory
=
get_cache_dir
()
/
"vllm_public_assets"
asset_directory
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
asset_path
=
asset_directory
/
filename
if
not
asset_path
.
exists
():
if
s3_prefix
is
not
None
:
filename
=
s3_prefix
+
"/"
+
filename
global_http_connection
.
download_file
(
f
"
{
vLLM_S3_BUCKET_URL
}
/
{
filename
}
"
,
asset_path
,
timeout
=
VLLM_IMAGE_FETCH_TIMEOUT
)
return
asset_path
vllm/assets/image.py
View file @
86ab567b
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
functools
import
lru_cache
from
typing
import
Literal
from
typing
import
Literal
from
PIL
import
Image
from
PIL
import
Image
from
vllm.connections
import
global_http_connection
from
vllm.assets.base
import
get_vllm_public_assets
from
vllm.envs
import
VLLM_IMAGE_FETCH_TIMEOUT
from
.base
import
get_cache_dir
VLM_IMAGES_DIR
=
"vision_model_images"
@
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"
global_http_connection
.
download_file
(
f
"
{
base_url
}
/
{
filename
}
"
,
image_path
,
timeout
=
VLLM_IMAGE_FETCH_TIMEOUT
)
return
Image
.
open
(
image_path
)
@
dataclass
(
frozen
=
True
)
@
dataclass
(
frozen
=
True
)
...
@@ -36,4 +14,7 @@ class ImageAsset:
...
@@ -36,4 +14,7 @@ class ImageAsset:
@
property
@
property
def
pil_image
(
self
)
->
Image
.
Image
:
def
pil_image
(
self
)
->
Image
.
Image
:
return
get_air_example_data_2_asset
(
f
"
{
self
.
name
}
.jpg"
)
image_path
=
get_vllm_public_assets
(
filename
=
f
"
{
self
.
name
}
.jpg"
,
s3_prefix
=
VLM_IMAGES_DIR
)
return
Image
.
open
(
image_path
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment