feat: make kernel loading work when offline mode ie enabled.#580
feat: make kernel loading work when offline mode ie enabled.#580sayakpaul wants to merge 2 commits into
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
| get_kernel("kernels-test-untrusted/ci-test-kernel", version=1, trust_remote_code=True) | ||
|
|
||
|
|
||
| def test_install_kernel_offline_with_revision(monkeypatch, local_kernel_path): |
| f"Skipping publisher trust check for '{repo_id}' because Hugging Face " | ||
| "Hub is in offline mode. Pass trust_remote_code=True to suppress this " | ||
| "warning.", |
There was a problem hiding this comment.
| f"Skipping publisher trust check for '{repo_id}' because Hugging Face " | |
| "Hub is in offline mode. Pass trust_remote_code=True to suppress this " | |
| "warning.", | |
| f"Skipping publisher trust check for '{repo_id}' because Hugging Face " | |
| "Hub is in offline mode.", |
Just to avoid incentivizing people to use trust_remote_code.
| if constants.HF_HUB_OFFLINE: | ||
| # Enumerate variants from the local snapshot rather than the Hub. | ||
| try: | ||
| local_repo_path = Path( | ||
| str( | ||
| api.snapshot_download( | ||
| repo_id, | ||
| repo_type="kernel", | ||
| cache_dir=CACHE_DIR, | ||
| revision=locked_sha, | ||
| local_files_only=True, | ||
| ) | ||
| ) | ||
| ) | ||
| except LocalEntryNotFoundError as e: | ||
| raise FileNotFoundError( | ||
| f"Locked kernel `{repo_id}` was not downloaded. Make sure it's downloaded locally." | ||
| ) from e | ||
| variants = get_variants_local(local_repo_path / "build") | ||
| else: | ||
| variants = get_variants(api, repo_id=repo_id, revision=locked_sha) |
There was a problem hiding this comment.
These should actually be the same code path. I think the current implementation si wrong in that it calls get_variants, load_kernel should already be local/offline, but I think the network dependency got accidentally introduced when adding the get_variants code.
So, it should be your code in both cases (constants.HF_HUB_OFFLINE and constants.HF_HUB_OFFLINE).
| def load_kernel( | ||
| repo_id: str, | ||
| *, | ||
| lockfile: Path | None, |
There was a problem hiding this comment.
I think if we add revision here as well, then install_kernel could just call load_kernel when constants.HF_HUB_OFFLINE is set. So the cases would be:
revision=None,lockfile=None-> get lock file from the caller package's metadata and get revision.revision=something,lockfile=None-> use the given revision.revision=None,lockfile=some_path-> get the revision from the lockfile.revision=something,lockfile=some_path-> raise an exception
| # The Hub cannot be reached, so the local snapshot must exist. Locate | ||
| # it and enumerate variants from disk rather than calling list_repo_tree. | ||
| try: | ||
| local_repo_path = Path( | ||
| str( | ||
| api.snapshot_download( | ||
| repo_id, | ||
| repo_type="kernel", | ||
| cache_dir=CACHE_DIR, | ||
| revision=revision, | ||
| local_files_only=True, | ||
| ) | ||
| ) | ||
| ) | ||
| except LocalEntryNotFoundError as e: | ||
| raise FileNotFoundError( | ||
| f"Cannot find a local snapshot for {repo_id} (revision: {revision}). " | ||
| "When Hugging Face Hub is in offline mode the kernel must already " | ||
| "be present in the local cache." | ||
| ) from e | ||
| variants = get_variants_local(local_repo_path / "build") |
There was a problem hiding this comment.
See below, I think with a small change to load_kernel, we could call out to load_kernel here.
Fixes #553