Skip to content

fix: load cached projector files offline in the multimodal chat handlers' from_pretrained - #2473

Open
sohailshk wants to merge 1 commit into
abetlen:mainfrom
sohailshk:fix/chat-handler-offline
Open

sohailshk wants to merge 1 commit into
abetlen:mainfrom
sohailshk:fix/chat-handler-offline

Conversation

@sohailshk

Copy link
Copy Markdown

#2396 made Llama.from_pretrained work with HF_HUB_OFFLINE=1. The two chat-handler from_pretrained classmethods have the same code and were not changed.

Repro, two steps. First download the projector (online):

from llama_cpp.llama_chat_format import Llava15ChatHandler, MTMDChatHandler

Llava15ChatHandler.from_pretrained("ggml-org/SmolVLM-256M-Instruct-GGUF", "mmproj-*Q8_0.gguf")

Then run the same call again with HF_HUB_OFFLINE=1 (for either handler, and also with a populated local_dir):

import os
os.environ["HF_HUB_OFFLINE"] = "1"
MTMDChatHandler.from_pretrained("ggml-org/SmolVLM-256M-Instruct-GGUF", "mmproj-*Q8_0.gguf")

Actual on main: huggingface_hub.errors.OfflineModeIsEnabled: Cannot reach https://huggingface.co/api/models/ggml-org/SmolVLM-256M-Instruct-GGUF, raised by HfFileSystem().ls(repo_id) before the cached file is looked at.
Expected: the cached (or local_dir) projector file is matched against the pattern and loaded, as in Llama.from_pretrained.

Fix: in Llava15ChatHandler.from_pretrained and MTMDChatHandler.from_pretrained, when huggingface_hub.constants.HF_HUB_OFFLINE is set, list the files of a populated local_dir, otherwise of the cached snapshot (snapshot_download(..., local_files_only=True)), instead of calling HfFileSystem. The online path is unchanged. The listing stays non-recursive, like the existing hffs.ls(repo_id) call.

Behaviour change: offline, the pattern is matched only against files already on disk, so a pattern that is ambiguous online (mmproj-*) resolves to the single cached file. This is the same as Llama.from_pretrained since #2396.

Test: not included in the PR, since tests are usually removed from outside PRs here; a test (cached snapshot and populated local_dir, both handlers) is available on request. On main it gives 4 failed (OfflineModeIsEnabled), with this change 4 passed; tests/test_llama_chat_format.py 2 passed; ruff check and ruff format --check pass. Resolution was also checked with the real cached ggml-org/SmolVLM-256M-Instruct-GGUF projector, online and offline.

Not run: loading the projector into a model (the mtmd load), the server tests.

The implementation and tests were written with AI assistance.

…ers' from_pretrained

Llava15ChatHandler.from_pretrained and MTMDChatHandler.from_pretrained still
list the repo through HfFileSystem, so with HF_HUB_OFFLINE=1 they raise
OfflineModeIsEnabled even when the projector file is cached or already in
local_dir. Use the cached snapshot or a populated local_dir, as
Llama.from_pretrained does since abetlen#2396.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant