| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | from functools import lru_cache |
| 5 | from pathlib import Path |
| 6 | |
| 7 | import vllm.envs as envs |
| 8 | from vllm.connections import global_http_connection |
| 9 | |
| 10 | VLLM_S3_BUCKET_URL = "https://vllm-public-assets.s3.us-west-2.amazonaws.com" |
| 11 | |
| 12 | |
| 13 | def get_cache_dir() -> Path: |
| 14 | """Get the path to the cache for storing downloaded assets.""" |
| 15 | path = Path(envs.VLLM_ASSETS_CACHE) |
| 16 | path.mkdir(parents=True, exist_ok=True) |
| 17 | |
| 18 | return path |
| 19 | |
| 20 | |
| 21 | @lru_cache |
| 22 | def get_vllm_public_assets(filename: str, s3_prefix: str | None = None) -> Path: |
| 23 | """Download an asset file from `s3://vllm-public-assets` |
| 24 | and return the path to the downloaded file. |
| 25 | """ |
| 26 | asset_directory = get_cache_dir() / "vllm_public_assets" |
| 27 | asset_directory.mkdir(parents=True, exist_ok=True) |
| 28 | |
| 29 | asset_path = asset_directory / filename |
| 30 | if not asset_path.exists(): |
| 31 | if s3_prefix is not None: |
| 32 | filename = s3_prefix + "/" + filename |
| 33 | global_http_connection.download_file( |
| 34 | f"{VLLM_S3_BUCKET_URL}/{filename}", |
| 35 | asset_path, |
| 36 | timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT, |
| 37 | ) |
| 38 | |
| 39 | return asset_path |