Repository navigation
Studio diffusion/video: share the Hub reachability verdict across cached-load calls - #15059
Conversation
…nreachable The prequant cache freshness check sent a HEAD (5 s timeout) per shard, and a second one per shard on symlink-less caches, on every lookup. Failures were not memoized, so an unreachable but unflagged network (captive portal, dropped packets) paid 5 s per shard per lookup before the cached entry was served. Remember per endpoint that a connect or timeout failure happened and answer later probes as unanswerable for the existing 300 s TTL, the same outcome a failed HEAD already had. HTTP answers (gated, 5xx, rate limit) stay per repo.
…hed-load calls A cached load on a network that drops packets made several metadata calls that ignored the prequant probe's "endpoint did not connect" verdict, and HfApi.model_info has no timeout by default, so the first listing could hang indefinitely before any cache fallback ran. Move the verdict to core/inference/hub_reachability.py (hub_unreachable, note_hub_failure, note_hub_success) and route the cached-load calls through it: - model_info: bounded at 10 s. Size estimates, the gated-base check, the mirror SHA and the component size hint take their existing unknown or fail-open answer without a request while the verdict stands. - Lookups that decide what loads (base_model tag, hosted prequant and pre-cast encoder listings) are always asked, only bounded. - _resolve_gguf_path, the single-file transformer config and the load itself use local_files_only only when the file or pipeline index is already cached; an uncached pick still downloads. - The GGUF compat revision HEAD is skipped under the verdict.
…hability # Conflicts: # studio/backend/core/inference/diffusion_prequant_cache.py # studio/backend/tests/conftest.py [skip ci]
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b44020fe5a
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if kind != "pipeline" and gguf_filename and not _is_local_path(repo_id): | ||
| return _cached_while_hub_unreachable(repo_id, gguf_filename) | ||
| return True |
There was a problem hiding this comment.
Verify the complete load is cached before forcing offline mode
If a download was interrupted after caching model_index.json, a transient Hub timeout makes this predicate return true even though required weights or component configs are still missing. _run_load then forces local_files_only=True for both _prefetch_files and load_pipeline, so the missing files cannot download even if connectivity has already recovered within the 300-second verdict window. The added test even accepts a pipeline cache containing only the manifest and transformer config. Check that all required assets are cached before forcing the entire load offline, or retry online on a cache miss when the caller did not explicitly request offline mode.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a529751. The manifest check stays as the cheap up-front gate, but when Studio (not the caller) forced the load offline and it then fails with a cache miss (OSError, which covers LocalEntryNotFoundError and diffusers missing-file errors), the prefetch and load_pipeline run again once online, so an interrupted download still completes once the network is back. A load the caller asked to run offline is never retried, and a cancelled or superseded load is not either. Tests: test_a_partly_cached_load_forced_offline_retries_online (fails before this commit) and test_a_caller_offline_load_is_not_retried_online.
…s incomplete [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
# Conflicts: # studio/backend/core/inference/diffusion_prequant_cache.py
Stacked on #15039 (base branch
studio-cached-load-hub-probe); review that one first.Summary
#15039 made the prequant cache freshness probe remember, per process and for 300 s, that the Hub endpoint did not connect. Other calls on a fully cached image or video load ignored that verdict.
HfApi.model_infoalso has no timeout by default, so on a network that drops packets the first size-estimate listing hung indefinitely, before any cache fallback could run.This PR moves the verdict into
core/inference/hub_reachability.py(hub_unreachable(),note_hub_failure(exc),note_hub_success()).diffusion_prequant_cachenow uses it, and the cached-load Hub calls go through it:model_inforouted here gets a 10 s timeout (HfApi.model_info(timeout=...), available across the supported huggingface_hub range)._estimate_download_bytes, image and video plan listings), the gated-base check (_assert_base_repo_accessible, which only ever fails open on a transport error), the mirror SHA (_current_sha), the supplied-component size hint (_hub_file_size) and the GGUF compat revision HEAD (diffusion_compat._hub_revision).base_modeltag, the hosted prequant listing and the pre-cast encoder listings. So a network that comes back inside the TTL gets the same pick a healthy one does.local_files_only=Trueis applied only when the file is already cached in the live root. This covers_resolve_gguf_path, the single-file transformerconfigfetch and the load itself (_run_load, when the base pipeline index and, for GGUF / single-file picks, the checkpoint are cached). This matches diffusers' own "Couldn't connect to the Hub" fallback, without its revision lookup andmodel_infocall, which have no timeout either. An uncached pick still goes online, so a first download works.When the Hub answers, nothing changes: same requests, same results.
Details
CPU, cached
hf-internal-testing/tiny-flux-pipeloaded as FLUX.1 throughdownload_planand thenbegin_load(the Images page order). The tiny repo was let past the trusted-repo gate in the harness. Requests were counted athttpx.Client.send. Blackhole isHF_ENDPOINTpointing at a local TCP server that accepts and never answers, withHF_HUB_OFFLINEunset.model_info(size estimate)On a healthy network all three arms send the same 4 requests (two listings and two gated checks). With this PR on a blackhole, the first listing times out once at 10 s. Every later call takes its existing fallback, and the pipeline loads from the cache. Wall time outside the network is CPU model construction. On an idle host it was 8.3 s for this PR on the blackhole and 7.9 s for a healthy load. On the shared, heavily loaded host it varied between 30 s and 100 s in every arm, so it is not compared here.
Tests
tests/test_hub_reachability.py(12 tests). All Hub traffic goes through huggingface_hub's own HTTP stack on anhttpx.MockTransportviaset_client_factory; no socket is opened. It covers: one request shared across the gated check, mirror SHA and estimate on a blackholed Hub; the 10 s bound;base_modeland prequant lookups still asked under the verdict; healthy and HTTP-error answers that never set the verdict; TTL expiry and clearing on success; an uncached gated base keeping today's answers; a cached GGUF read withlocal_files_onlywhile an uncached one still downloads; the compat probe skipped; and the cached-pick rule.model_info, always-asked, cached GGUF, compat probe and cached-pick tests. The healthy-answer, HTTP-error, gated and uncached-download tests pass on both, as they should.tests/conftest.pynow clears the per-process verdict between tests. One existing download-plan test now stubs the speech-pick revision HEAD it was silently sending to the blocked network; that failed connect would otherwise, correctly, skip the stubbed listings after it.