Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/lora/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_get_adapter_absolute_path_local_existing(mock_abspath, mock_exist):
assert get_adapter_absolute_path(path) == absolute_path


@patch("huggingface_hub.snapshot_download")
@patch("huggingface_hub.HfApi.snapshot_download")
@patch("os.path.exists")
def test_get_adapter_absolute_path_huggingface(mock_exist, mock_snapshot_download):
# Hugging Face model identifier
Expand All @@ -186,7 +186,7 @@ def test_get_adapter_absolute_path_huggingface(mock_exist, mock_snapshot_downloa
assert get_adapter_absolute_path(path) == absolute_path


@patch("huggingface_hub.snapshot_download")
@patch("huggingface_hub.HfApi.snapshot_download")
@patch("os.path.exists")
def test_get_adapter_absolute_path_huggingface_error(
mock_exist, mock_snapshot_download
Expand Down
4 changes: 2 additions & 2 deletions vllm/assets/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import numpy as np
import numpy.typing as npt
from huggingface_hub import hf_hub_download
from PIL import Image

from vllm.multimodal.media.audio import load_audio_pyav
from vllm.transformers_utils.repo_utils import hf_api

from .base import get_cache_dir

Expand All @@ -27,7 +27,7 @@ def download_video_asset(filename: str) -> str:
video_path = video_directory / filename
video_path_str = str(video_path)
if not video_path.exists():
video_path_str = hf_hub_download(
video_path_str = hf_api().hf_hub_download(
repo_id="raushan-testing-hf/videos-test",
filename=filename,
repo_type="dataset",
Expand Down
7 changes: 5 additions & 2 deletions vllm/benchmarks/datasets/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import numpy as np
import pybase64 as base64
from huggingface_hub import snapshot_download
from PIL import Image
from typing_extensions import deprecated

Expand All @@ -46,6 +45,7 @@
from vllm.multimodal.audio import get_audio_duration
from vllm.multimodal.image import convert_image_mode
from vllm.tokenizers import TokenizerLike
from vllm.transformers_utils.repo_utils import hf_api
from vllm.utils.argparse_utils import FlexibleArgumentParser
from vllm.utils.import_utils import PlaceholderModule
from vllm.utils.mistral import is_mistral_tokenizer
Expand Down Expand Up @@ -3334,7 +3334,10 @@ def __init__(self, **kwargs) -> None:
self._remote_path_root = (
f"https://huggingface.co/datasets/{self.hf_name}/resolve/main"
)
self._local_path_root = snapshot_download(self.hf_name, repo_type="dataset")
self._local_path_root = hf_api().snapshot_download(
self.hf_name,
repo_type="dataset",
)

def sample(
self,
Expand Down
6 changes: 4 additions & 2 deletions vllm/lora/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
from typing import TYPE_CHECKING

import huggingface_hub
import regex as re
from huggingface_hub.utils import HfHubHTTPError, HFValidationError
from torch import nn
Expand Down Expand Up @@ -37,6 +36,7 @@
from vllm.model_executor.layers.fused_moe import FusedMoE
from vllm.model_executor.layers.linear import LinearBase
from vllm.model_executor.utils import get_moe_expert_mapping, get_packed_modules_mapping
from vllm.transformers_utils.repo_utils import hf_api

if TYPE_CHECKING:
from vllm.model_executor.layers.logits_processor import LogitsProcessor
Expand Down Expand Up @@ -340,7 +340,9 @@ def get_adapter_absolute_path(lora_path: str) -> str:
error_log = "Error downloading the ModelScope model"
else:
# Otherwise, we assume the path is a Hugging Face Hub repo.
download_fn = lambda: huggingface_hub.snapshot_download(repo_id=lora_path)
download_fn = lambda: hf_api().snapshot_download(
repo_id=lora_path,
)
download_exceptions = (HfHubHTTPError, HFValidationError)
error_log = "Error downloading the HuggingFace model"

Expand Down
5 changes: 2 additions & 3 deletions vllm/model_executor/model_loader/bitsandbytes_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import numpy as np
import torch
from huggingface_hub import HfApi
from packaging import version
from torch import nn
from transformers.utils import SAFE_WEIGHTS_INDEX_NAME
Expand Down Expand Up @@ -48,6 +47,7 @@
set_weight_attrs,
)
from vllm.platforms import current_platform
from vllm.transformers_utils.repo_utils import hf_api
from vllm.utils.torch_utils import set_default_torch_dtype

logger = init_logger(__name__)
Expand Down Expand Up @@ -97,8 +97,7 @@ def _get_weight_files(
if weight_files:
return model_name_or_path, weight_files, pattern
else:
hf_api = HfApi()
repo_files = hf_api.list_repo_files(repo_id=model_name_or_path)
repo_files = hf_api().list_repo_files(repo_id=model_name_or_path)
for pattern in allowed_patterns:
matching_files = fnmatch.filter(repo_files, pattern)
if matching_files:
Expand Down
4 changes: 2 additions & 2 deletions vllm/model_executor/model_loader/gguf_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import regex as re
import torch
import torch.nn as nn
from huggingface_hub import hf_hub_download
from transformers import AutoModelForCausalLM, AutoModelForImageTextToText

from vllm.config import ModelConfig, VllmConfig
Expand All @@ -27,6 +26,7 @@
gguf_quant_weights_iterator_multi,
)
from vllm.transformers_utils.gguf_utils import detect_gguf_multimodal
from vllm.transformers_utils.repo_utils import hf_api
from vllm.utils.torch_utils import set_default_torch_dtype

if TYPE_CHECKING:
Expand Down Expand Up @@ -57,7 +57,7 @@ def _prepare_weights(self, model_config: ModelConfig):
# repo id/filename.gguf
if "/" in model_name_or_path and model_name_or_path.endswith(".gguf"):
repo_id, filename = model_name_or_path.rsplit("/", 1)
return hf_hub_download(
return hf_api().hf_hub_download(
repo_id=repo_id,
filename=filename,
revision=model_config.revision,
Expand Down
4 changes: 2 additions & 2 deletions vllm/model_executor/model_loader/tensorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import regex as re
import torch
from huggingface_hub import snapshot_download
from torch import nn
from torch.utils._python_dispatch import TorchDispatchMode
from transformers import PretrainedConfig
Expand All @@ -26,6 +25,7 @@
from vllm.logger import init_logger
from vllm.model_executor.layers.vocab_parallel_embedding import VocabParallelEmbedding
from vllm.platforms import current_platform
from vllm.transformers_utils.repo_utils import hf_api
from vllm.utils.argparse_utils import FlexibleArgumentParser
from vllm.utils.import_utils import PlaceholderModule

Expand Down Expand Up @@ -629,7 +629,7 @@ def serialize_extra_artifacts(
)

with tempfile.TemporaryDirectory() as tmpdir:
snapshot_download(
hf_api().snapshot_download(
served_model_name,
local_dir=tmpdir,
ignore_patterns=[
Expand Down
14 changes: 7 additions & 7 deletions vllm/model_executor/model_loader/weight_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import numpy as np
import regex as re
import torch
from huggingface_hub import HfFileSystem, hf_hub_download, snapshot_download
from safetensors.torch import load, load_file, safe_open, save_file
from tqdm.auto import tqdm
from transformers.utils import SAFE_WEIGHTS_INDEX_NAME
Expand All @@ -46,6 +45,7 @@
)
from vllm.platforms import current_platform
from vllm.tracing import instrument
from vllm.transformers_utils.repo_utils import hf_api, hf_fs
from vllm.utils.import_utils import PlaceholderModule

try:
Expand Down Expand Up @@ -373,7 +373,7 @@ def get_quant_config(
if not is_local:
# Download the config files.
with get_lock(model_config.model, load_config.download_dir):
hf_folder = snapshot_download(
hf_folder = hf_api().snapshot_download(
model_config.model,
revision=model_config.revision,
allow_patterns="*.json",
Expand Down Expand Up @@ -431,7 +431,7 @@ def get_sparse_attention_config(
if not is_local:
# Download the config files.
with get_lock(model_name_or_path, load_config.download_dir):
hf_folder = snapshot_download(
hf_folder = hf_api().snapshot_download(
model_name_or_path,
revision=model_config.revision,
allow_patterns="*.json",
Expand Down Expand Up @@ -534,7 +534,7 @@ def download_weights_from_hf(
# Attempt to reduce allow_patterns to a single pattern
# so we only have to call snapshot_download once.
try:
fs = HfFileSystem()
fs = hf_fs()
file_list = fs.ls(
os.path.join(model_name_or_path, subfolder or ""),
detail=False,
Expand All @@ -546,7 +546,7 @@ def download_weights_from_hf(
# unnecessary files (e.g., from subdirectories like "original/").
index_file = f"{model_name_or_path}/{SAFE_WEIGHTS_INDEX_NAME}"
if "*.safetensors" in allow_patterns and index_file in file_list:
index_path = hf_hub_download(
index_path = hf_api().hf_hub_download(
repo_id=model_name_or_path,
filename=SAFE_WEIGHTS_INDEX_NAME,
cache_dir=cache_dir,
Expand Down Expand Up @@ -582,7 +582,7 @@ def download_weights_from_hf(
with get_lock(model_name_or_path, cache_dir):
start_time = time.perf_counter()
for allow_pattern in allow_patterns:
hf_folder = snapshot_download(
hf_folder = hf_api().snapshot_download(
model_name_or_path,
allow_patterns=allow_pattern,
ignore_patterns=ignore_patterns,
Expand Down Expand Up @@ -631,7 +631,7 @@ def download_safetensors_index_file_from_hf(
with get_lock(model_name_or_path, cache_dir):
try:
# Download the safetensors index file.
hf_hub_download(
hf_api().hf_hub_download(
repo_id=model_name_or_path,
filename=index_file,
cache_dir=cache_dir,
Expand Down
10 changes: 6 additions & 4 deletions vllm/plugins/lora_resolvers/hf_hub_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import asyncio
import os

from huggingface_hub import HfApi, snapshot_download

import vllm.envs as envs
from vllm.logger import init_logger
from vllm.lora.request import LoRARequest
from vllm.lora.resolver import LoRAResolverRegistry
from vllm.plugins.lora_resolvers.filesystem_resolver import FilesystemResolver
from vllm.transformers_utils.repo_utils import hf_api

logger = init_logger(__name__)

Expand Down Expand Up @@ -49,7 +48,7 @@ async def resolve_lora(
return None

repo_path = await asyncio.to_thread(
snapshot_download,
hf_api().snapshot_download,
repo_id=maybe_repo,
allow_patterns=f"{maybe_subpath}/*" if maybe_subpath != "." else "*",
)
Expand Down Expand Up @@ -110,7 +109,10 @@ async def _get_adapter_dirs(self, repo_name: str) -> set[str]:
Args:
repo_name: Name of the HF hub repo to inspect.
"""
repo_files = await asyncio.to_thread(HfApi().list_repo_files, repo_id=repo_name)
repo_files = await asyncio.to_thread(
hf_api().list_repo_files,
repo_id=repo_name,
)
adapter_dirs = {
os.path.dirname(name)
for name in repo_files
Expand Down
6 changes: 3 additions & 3 deletions vllm/tokenizers/grok2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pathlib import Path
from typing import Any, Literal, overload

from huggingface_hub import hf_hub_download
from huggingface_hub.utils import (
EntryNotFoundError,
HfHubHTTPError,
Expand All @@ -20,6 +19,7 @@

from vllm.entrypoints.chat_utils import ChatCompletionMessageParam
from vllm.logger import init_logger
from vllm.transformers_utils.repo_utils import hf_api

from .protocol import TokenizerLike

Expand Down Expand Up @@ -70,7 +70,7 @@ def _maybe_load_tokenizer_config(
return {}

try:
config_file = hf_hub_download(
config_file = hf_api().hf_hub_download(
repo_id=repo_id,
filename="tokenizer_config.json",
revision=revision,
Expand Down Expand Up @@ -208,7 +208,7 @@ def from_pretrained(
repo_id = None
else:
vocab_file = Path(
hf_hub_download(
hf_api().hf_hub_download(
repo_id=str(path_or_repo_id),
filename="tokenizer.tok.json",
revision=revision,
Expand Down
8 changes: 4 additions & 4 deletions vllm/tokenizers/kimi_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

import pybase64
import tiktoken
from huggingface_hub import hf_hub_download
from transformers import AddedToken, BatchEncoding
from transformers.utils import chat_template_utils as hf_chat_utils

from vllm.entrypoints.chat_utils import ChatCompletionMessageParam
from vllm.logger import init_logger
from vllm.tokenizers.protocol import TokenizerLike
from vllm.transformers_utils.repo_utils import hf_api

logger = init_logger(__name__)

Expand Down Expand Up @@ -78,7 +78,7 @@ def from_pretrained(

# Try to download tiktoken.model or tokenizer.model
try:
vocab_path = hf_hub_download(
vocab_path = hf_api().hf_hub_download(
repo_id=repo_id,
filename="tiktoken.model",
revision=revision,
Expand All @@ -87,7 +87,7 @@ def from_pretrained(
vocab_file = Path(vocab_path)
except Exception:
try:
vocab_path = hf_hub_download(
vocab_path = hf_api().hf_hub_download(
repo_id=repo_id,
filename="tokenizer.model",
revision=revision,
Expand All @@ -101,7 +101,7 @@ def from_pretrained(

# Also download tokenizer_config.json if available
with contextlib.suppress(Exception):
hf_hub_download(
hf_api().hf_hub_download(
repo_id=repo_id,
filename="tokenizer_config.json",
revision=revision,
Expand Down
7 changes: 4 additions & 3 deletions vllm/transformers_utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import huggingface_hub
import torch
from huggingface_hub import constants, get_safetensors_metadata
from huggingface_hub import constants
from packaging.version import Version
from safetensors.torch import _TYPES as _SAFETENSORS_TO_TORCH_DTYPE
from transformers import GenerationConfig, PretrainedConfig
Expand Down Expand Up @@ -43,6 +43,7 @@
from .repo_utils import (
file_or_path_exists,
get_hf_file_to_dict,
hf_api,
list_repo_files,
try_get_local_file,
with_retry,
Expand Down Expand Up @@ -1143,7 +1144,7 @@ def try_get_safetensors_metadata(
revision: str | None = None,
):
get_safetensors_metadata_partial = partial(
get_safetensors_metadata, model, revision=revision
hf_api().get_safetensors_metadata, model, revision=revision
)

try:
Expand Down Expand Up @@ -1237,7 +1238,7 @@ def get_safetensors_params_metadata(
# local HF cache: weights may already be cached from a prior run, and
# weight loading itself uses the same cache.
try:
local_dir = huggingface_hub.snapshot_download(
local_dir = hf_api().snapshot_download(
repo_id=model,
revision=revision,
allow_patterns=["*.safetensors"],
Expand Down
Loading
Loading