feat(hub): add local-directory mode for offline model loading - #53
Merged
Conversation
Add hub.NewLocal(dir) / Repo.WithLocalDir(dir) so a *hub.Repo can read files straight from a plain local directory instead of downloading from HuggingFace Hub, with no network access. DownloadInfo scans the directory and DownloadFile(s) resolve paths within it; every existing consumer of *hub.Repo works unchanged.
Removing artifact of the AI generation.
Removed design rationale reference from changelog entry.
janpfeifer
approved these changes
Jul 30, 2026
janpfeifer
left a comment
Contributor
There was a problem hiding this comment.
Thank you @Niexiawei !
I removed the AI planning file, I hope you don't mind. Otherwise it looks great ... and I was meaning to do this for a while now, I'm so happy you already did it.
Merging here.
Contributor
|
Btw, @Niexiawei , inspired by your PR, I went further in PR #54 and added the following:
I also updated the Check it out! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hub.NewLocal(dir)/Repo.WithLocalDir(dir), letting a*hub.Reporead model filesdirectly from a plain local directory (e.g. output of
git cloneorhuggingface-cli download --local-dir) instead of downloading from HuggingFace Hub.DownloadInfoscans the directory tobuild the file listing, and
DownloadFile(s)resolve repo-relative names to paths inside it.FileURLreturns an explicit error since there is no remote URL in this mode.*hub.Repo—models/transformer,models/safetensors,models/gguf,models/sam2,tokenizers/*— works unchanged, since they only depend onDownloadInfo/DownloadFile(s)/HasFile/IterFileNames/IterFileInfos, all of which arebranched internally in
hub.datasetsis out ofscope, standard-cache offline mode is a separate follow-up) are written up in
docs/local-model-loading-plan.md.Test plan
go build ./...andgo vet ./...passgo test ./hub/...passes, including 12 new tests inhub/local_test.gocovering:forward-slash file names,
.git/.cacheexclusion, file sizes,HasFile,DownloadFilesuccess/missing-file/path-traversal-safety,FileURLerroring inlocal mode, missing-directory error, and that scanning never mutates the local directory
go test ./... -shortpasses across the repo (one unrelated pre-existing failure inmodels/transformeron Windows, caused by an XLA PJRT auto-installer symlink-permissionissue, not by this change)
BAAI/bge-small-zh-v1.5) in adownstream consumer project: pointed it at a local snapshot directory via
hub.NewLocal,ran embedding + similarity search with zero network calls, and got correct results