Repository navigation
Studio diffusion: one bounded Hub probe per process when the Hub is unreachable - #15039
Merged
Merged
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.
Member
Author
|
@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. |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Oct 24, 2026
…hed-load calls (unslothai#15059) Stacked on unslothai#15039 (base branch `studio-cached-load-hub-probe`); review that one first. ## Summary unslothai#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) | | unslothai#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 | | unslothai#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 unslothai#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. - unslothai#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 unslothai#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.
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
On a cache hit, the prequant cache freshness check added in #13715 sends a Hub HEAD request (5 s timeout) for every source shard, and a second one per shard when the Hub cache has no symlinks. A failed request was not remembered, so every later lookup asked again. With the network unreachable but not flagged offline (captive portal, a firewall that drops packets, slow DNS), a cached load paid about 5 s per shard per lookup before the cached entry was served.
This change remembers, per Hub endpoint and per process, that a request failed at the transport level (connection refused or reset, connect or read timeout). For the existing 300 s TTL, later probes return "unanswerable" at once. That is the same result a failed HEAD already produced: the local snapshot stands, which is also what
huggingface_hubdoes when its HEAD fails on a cached file. The first successful answer clears the verdict.Details
httpx.ConnectError/httpx.TimeoutException, therequestsequivalents on olderhuggingface_hub, and plain socket errors count as unreachable. These are the same classeshuggingface_hubtreats as "connection down". Proxy errors and HTTP answers (gated, 404, 5xx, rate limit) are per repo and do not silence other checks.maincheck and the symlink-free commit check are unchanged. A network that comes back gets checked again once the TTL runs out.Measured on CPU, real
huggingface_hub1.33 HTTP stack.HF_ENDPOINTpoints at a local TCP server that accepts and never answers.HF_HUB_OFFLINEis unset. The cached snapshot ishf-internal-testing/tiny-flux-transformer(1 shard) and a 4-shard snapshot with the same layout:Tests
test_a_blackholed_hub_costs_one_probe_per_process_not_one_per_shard_per_lookup: anhttpx.MockTransportthat times out every request is installed throughhuggingface_hub.set_client_factory, then 4 shards go through 3 lookups. It fails on main (assert 12 == 1) and passes here.test_an_http_answer_is_not_taken_for_an_unreachable_hub(a 503 does not set the verdict) andtest_the_hub_is_asked_again_once_the_unreachable_verdict_expires(the TTL expires and the movedmainis detected again).tests/test_diffusion_prequant_cache.py,tests/test_diffusion_pipeline_prequant.pyandtests/test_video_prequant.py: 282 passed, 1 skipped (CPU).