base.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """Assets for testing. vLLM conveniently has a bucket of public assets
  2. we can use."""
  3. import os
  4. from functools import lru_cache
  5. from pathlib import Path
  6. from typing import Optional
  7. import aphrodite.common.envs as envs
  8. from aphrodite.connections import global_http_connection
  9. def get_default_cache_root():
  10. return os.getenv(
  11. "XDG_CACHE_HOME",
  12. os.path.join(os.path.expanduser("~"), ".cache"),
  13. )
  14. vLLM_S3_BUCKET_URL = "https://vllm-public-assets.s3.us-west-2.amazonaws.com"
  15. APHRODITE_ASSETS_CACHE = envs.APHRODITE_ASSETS_CACHE
  16. APHRODITE_IMAGE_FETCH_TIMEOUT = envs.APHRODITE_IMAGE_FETCH_TIMEOUT
  17. def get_cache_dir() -> Path:
  18. """Get the path to the cache for storing downloaded assets."""
  19. path = Path(APHRODITE_ASSETS_CACHE)
  20. path.mkdir(parents=True, exist_ok=True)
  21. return path
  22. @lru_cache
  23. def get_vllm_public_assets(filename: str,
  24. s3_prefix: Optional[str] = None) -> Path:
  25. """
  26. Download an asset file from ``s3://vllm-public-assets``
  27. and return the path to the downloaded file.
  28. """
  29. asset_directory = get_cache_dir() / "vllm_public_assets"
  30. asset_directory.mkdir(parents=True, exist_ok=True)
  31. asset_path = asset_directory / filename
  32. if not asset_path.exists():
  33. if s3_prefix is not None:
  34. filename = s3_prefix + "/" + filename
  35. global_http_connection.download_file(
  36. f"{vLLM_S3_BUCKET_URL}/{filename}",
  37. asset_path,
  38. timeout=APHRODITE_IMAGE_FETCH_TIMEOUT)
  39. return asset_path