base.py 1.19 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4
from functools import lru_cache
5
6
7
from pathlib import Path

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
15
16
17
18
    """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
19
20
21


@lru_cache
22
def get_vllm_public_assets(filename: str, s3_prefix: str | None = None) -> Path:
23
24
25
26
27
28
29
30
31
32
33
34
    """
    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(
35
            f"{VLLM_S3_BUCKET_URL}/{filename}",
36
            asset_path,
37
38
            timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT,
        )
39
40

    return asset_path