base.py 1.24 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
from pathlib import Path
6
from typing import Optional
7
8

import vllm.envs as envs
9
from vllm.connections import global_http_connection
10

11
VLLM_S3_BUCKET_URL = "https://vllm-public-assets.s3.us-west-2.amazonaws.com"
12

13
14

def get_cache_dir() -> Path:
15
16
17
18
19
    """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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36


@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(
37
            f"{VLLM_S3_BUCKET_URL}/{filename}",
38
            asset_path,
39
            timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT)
40
41

    return asset_path