Skip to content

Studio diffusion: one bounded Hub probe per process when the Hub is unreachable - #15039

Merged
danielhanchen merged 3 commits into
mainfrom
studio-cached-load-hub-probe
Oct 24, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-cached-load-hub-probe

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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_hub does when its HEAD fails on a cached file. The first successful answer clears the verdict.

Details

  • Only httpx.ConnectError / httpx.TimeoutException, the requests equivalents on older huggingface_hub, and plain socket errors count as unreachable. These are the same classes huggingface_hub treats as "connection down". Proxy errors and HTTP answers (gated, 404, 5xx, rate limit) are per repo and do not silence other checks.
  • The freshness check still runs whenever the Hub answers. Revision pinning, the moved-main check and the symlink-free commit check are unchanged. A network that comes back gets checked again once the TTL runs out.
  • The same files load: the change only skips requests whose result was already "unanswerable, keep the local snapshot".

Measured on CPU, real huggingface_hub 1.33 HTTP stack. HF_ENDPOINT points at a local TCP server that accepts and never answers. HF_HUB_OFFLINE is unset. The cached snapshot is hf-internal-testing/tiny-flux-transformer (1 shard) and a 4-shard snapshot with the same layout:

Case main: requests / wall this PR: requests / wall
Blackholed, 1 shard, 3 lookups 3 / 15.1 s (5.0 s each) 1 / 5.0 s (then 0.00 s)
Blackholed, 4 shards, per lookup 4 / 20.0 s every lookup 1 / 5.0 s first lookup, 0 / 0.00 s after
Blackholed, 4 shards, 3 lookups (mocked transport test) 12 requests 1 request
Healthy endpoint, 4 shards, 2 lookups 4 / 0.04 s, then memoized 4 / 0.04 s, then memoized

Tests

  • New test_a_blackholed_hub_costs_one_probe_per_process_not_one_per_shard_per_lookup: an httpx.MockTransport that times out every request is installed through huggingface_hub.set_client_factory, then 4 shards go through 3 lookups. It fails on main (assert 12 == 1) and passes here.
  • New test_an_http_answer_is_not_taken_for_an_unreachable_hub (a 503 does not set the verdict) and test_the_hub_is_asked_again_once_the_unreachable_verdict_expires (the TTL expires and the moved main is detected again).
  • tests/test_diffusion_prequant_cache.py, tests/test_diffusion_pipeline_prequant.py and tests/test_video_prequant.py: 282 passed, 1 skipped (CPU).

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

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-23T22:37:41.731170Z 7f10392 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 7f10392c1c

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

@danielhanchen
danielhanchen merged commit 5b2bc06 into main Oct 24, 2026
41 of 42 checks passed
@danielhanchen
danielhanchen deleted the studio-cached-load-hub-probe branch October 24, 2026 03:28
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant