Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- fix: load cached projector files offline in the multimodal chat handlers' from_pretrained by @sohailshk in #XXXXX
- fix: load cached pretrained models in offline mode by @emme1t in #2396
- fix(ci): install matching NVML headers for CUDA wheel builds

Expand Down
78 changes: 64 additions & 14 deletions llama_cpp/llama_chat_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3195,7 +3195,12 @@ def from_pretrained(
from pathlib import Path

try:
from huggingface_hub import hf_hub_download, HfFileSystem # type: ignore
from huggingface_hub import ( # type: ignore
hf_hub_download,
HfFileSystem,
snapshot_download,
constants,
)
from huggingface_hub.utils import validate_repo_id # type: ignore
except ImportError:
raise ImportError(
Expand All @@ -3205,12 +3210,32 @@ def from_pretrained(

validate_repo_id(repo_id)

hffs = HfFileSystem()

files = [
file["name"] if isinstance(file, dict) else file
for file in hffs.ls(repo_id) # type: ignore
]
if constants.HF_HUB_OFFLINE:
if (
local_dir is not None
and Path(local_dir).is_dir()
and any(Path(local_dir).iterdir())
):
snapshot_path = Path(local_dir)
else:
snapshot_path = Path(
snapshot_download(
repo_id=repo_id,
cache_dir=cache_dir,
local_files_only=True,
)
)
files = [
f"{repo_id}/{file.name}"
for file in snapshot_path.iterdir()
if file.is_file()
]
else:
hffs = HfFileSystem()
files = [
file["name"] if isinstance(file, dict) else file
for file in hffs.ls(repo_id) # type: ignore
]

# split each file into repo_id, subfolder, filename
file_list: List[str] = []
Expand Down Expand Up @@ -3703,7 +3728,12 @@ def from_pretrained(
from pathlib import Path

try:
from huggingface_hub import hf_hub_download, HfFileSystem # type: ignore
from huggingface_hub import ( # type: ignore
hf_hub_download,
HfFileSystem,
snapshot_download,
constants,
)
from huggingface_hub.utils import validate_repo_id # type: ignore
except ImportError:
raise ImportError(
Expand All @@ -3713,12 +3743,32 @@ def from_pretrained(

validate_repo_id(repo_id)

hffs = HfFileSystem()

files = [
file["name"] if isinstance(file, dict) else file
for file in hffs.ls(repo_id) # type: ignore
]
if constants.HF_HUB_OFFLINE:
if (
local_dir is not None
and Path(local_dir).is_dir()
and any(Path(local_dir).iterdir())
):
snapshot_path = Path(local_dir)
else:
snapshot_path = Path(
snapshot_download(
repo_id=repo_id,
cache_dir=cache_dir,
local_files_only=True,
)
)
files = [
f"{repo_id}/{file.name}"
for file in snapshot_path.iterdir()
if file.is_file()
]
else:
hffs = HfFileSystem()
files = [
file["name"] if isinstance(file, dict) else file
for file in hffs.ls(repo_id) # type: ignore
]

file_list: List[str] = []
for file in files:
Expand Down