Skip to content

fix: support offline mode in model import#202

Draft
Dronte wants to merge 1 commit intotrymirai:mainfrom
Dronte:dronte/offline-model-import
Draft

fix: support offline mode in model import#202
Dronte wants to merge 1 commit intotrymirai:mainfrom
Dronte:dronte/offline-model-import

Conversation

@Dronte
Copy link
Copy Markdown

@Dronte Dronte commented Apr 5, 2026

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.

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>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@Dronte Dronte marked this pull request as draft April 8, 2026 20:06
@Dronte Dronte marked this pull request as draft April 8, 2026 20:06
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