Skip to content

Studio diffusion/video: share the Hub reachability verdict across cached-load calls - #15059

Merged
danielhanchen merged 10 commits into
mainfrom
studio-load-hub-reachability
Oct 24, 2026
Merged

danielhanchen merged 10 commits into
mainfrom
studio-load-hub-reachability

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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_info also 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_cache now uses it, and the cached-load Hub calls go through it:

  • Every model_info routed here gets a 10 s timeout (HfApi.model_info(timeout=...), available across the supported huggingface_hub range).
  • Calls that already have an "unknown" or fail-open answer return it without a request while the verdict stands. These are the size estimate (_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).
  • Lookups whose answer picks what loads are still always asked, only bounded. These are the GGUF base_model tag, 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=True is applied only when the file is already cached in the live root. This covers _resolve_gguf_path, the single-file transformer config fetch 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 and model_info call, 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-pipe loaded as FLUX.1 through download_plan and then begin_load (the Images page order). The tiny repo was let past the trusted-repo gate in the harness. Requests were counted at httpx.Client.send. Blackhole is HF_ENDPOINT pointing at a local TCP server that accepts and never answers, with HF_HUB_OFFLINE unset.

Arm Network Hub requests Time on the network Result
main (89d6805) blackhole 1, never returns killed at 300 s hangs in the first model_info (size estimate)
#15039 (7f10392) blackhole 1, never returns killed at 300 s same hang
this PR blackhole 1 (one 10 s ReadTimeout) 10.0 s (3 of 3 runs) loads from the cache
main healthy 4 0.19 to 0.33 s loads
#15039 healthy 4 0.21 to 1.99 s loads
this PR healthy 4 0.20 to 2.91 s loads

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

  • New tests/test_hub_reachability.py (12 tests). All Hub traffic goes through huggingface_hub's own HTTP stack on an httpx.MockTransport via set_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_model and 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 with local_files_only while an uncached one still downloads; the compat probe skipped; and the cached-pick rule.
  • On Studio diffusion: one bounded Hub probe per process when the Hub is unreachable #15039's head, the behavioural tests fail: the shared-timeout, bounded 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.
  • Studio diffusion: one bounded Hub probe per process when the Hub is unreachable #15039's own prequant cache tests pass unchanged. tests/conftest.py now 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.
  • Related diffusion, video and prequant suites: the failing test IDs on this branch match Studio diffusion: one bounded Hub probe per process when the Hub is unreachable #15039's head (pre-existing failures in attention install, multi-GPU, memory and compile tests). Files that hit the 25 min cap on both sides (VAE tiling, hires, comfy block) are unrelated to Hub calls.

…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.
@danielhanchen danielhanchen self-assigned this Oct 24, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T01:47:32.328147Z a529751 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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: 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".

Comment on lines +14772 to +14774
if kind != "pipeline" and gguf_filename and not _is_local_path(repo_id):
return _cached_while_hub_unreachable(repo_id, gguf_filename)
return True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: a529751e49

ℹ️ 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".

Base automatically changed from studio-cached-load-hub-probe to main October 24, 2026 03:28
# Conflicts:
#	studio/backend/core/inference/diffusion_prequant_cache.py
@danielhanchen
danielhanchen merged commit d497ab2 into main Oct 24, 2026
43 of 46 checks passed
@danielhanchen
danielhanchen deleted the studio-load-hub-reachability branch October 24, 2026 05:26
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