fix: support offline mode in model import#202
Conversation
Fall back to local HuggingFace cache when network is unreachable or HF_HUB_OFFLINE is set. Scans cached files instead of calling the API, and uses try_to_load_from_cache for downloads. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7a39f54884
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| repo_id=file_spec.repo or model_repo, | ||
| filename=file_spec.filename, | ||
| ) | ||
| if result is None or isinstance(result, str) and not Path(result).exists(): |
There was a problem hiding this comment.
Handle _CACHED_NO_EXIST before converting cache result to Path
try_to_load_from_cache can return the _CACHED_NO_EXIST sentinel (not just None or a path string), but the current guard only rejects None and missing string paths. In that case the code falls through to Path(result), which raises TypeError and breaks offline imports in caches that recorded a missing file (for example after a previous lookup). Treat the sentinel/non-string return as a cache miss and re-raise the original download error instead.
Useful? React with 👍 / 👎.
| cache_info = huggingface_hub.scan_cache_dir() | ||
| for repo_info in cache_info.repos: | ||
| if repo_info.repo_id == model_repo: | ||
| return [f.file_name for rev in repo_info.revisions for f in rev.files] |
There was a problem hiding this comment.
Limit offline weight discovery to the active cached revision
The offline fallback unions files from all cached revisions (for rev in repo_info.revisions for f in rev.files), so list_weight_files can include stale shard names that no longer exist in the current main revision. download_weights will then attempt to fetch those stale files and fail offline even when the latest cached snapshot is otherwise usable. The fallback should select files from a single target revision (e.g., the cached commit pointed to by main) rather than combining every revision.
Useful? React with 👍 / 👎.
Fall back to local HuggingFace cache when network is unreachable or HF_HUB_OFFLINE is set. Scans cached files instead of calling the API, and uses try_to_load_from_cache for downloads.