Skip to content

feat: auto-detect model download hub between Hugging Face and ModelScope - #5265

Open
OliverBryant wants to merge 4 commits into
xorbitsai:mainfrom
OliverBryant:feat/auto-download-hub
Open

feat: auto-detect model download hub between Hugging Face and ModelScope#5265
OliverBryant wants to merge 4 commits into
xorbitsai:mainfrom
OliverBryant:feat/auto-download-hub

Conversation

@OliverBryant

Copy link
Copy Markdown
Collaborator

What do these changes do?

Currently users have to manually choose between Hugging Face and ModelScope as the model download source (via --download_hub or XINFERENCE_MODEL_SRC), and the implicit default is guessed from the system locale (zh_CN → ModelScope). This guess is often wrong: users in China with a working proxy still get ModelScope, while users whose Hugging Face access is blocked but locale is not zh_CN get Hugging Face and the download fails.

This PR adds an auto download hub option and makes automatic detection the default, so users no longer need to pick a source:

  • New auto_detect_download_hub() in xinference/model/utils.py: probes whether the Hugging Face endpoint is reachable (honoring HF_ENDPOINT mirrors and HTTP(S)_PROXY proxies) with a short timeout, picks huggingface if reachable and falls back to modelscope otherwise. The result is cached per process so the probe runs at most once, and the timeout is tunable via XINFERENCE_HUB_DETECT_TIMEOUT (default 3s).
  • download_hub="auto" is accepted through the whole launch chain (REST API → supervisor → worker → create_model_instance) and resolved to a concrete hub before spec matching.
  • When download_hub is not specified at all, detection also runs — unless the user pinned a source via XINFERENCE_MODEL_SRC or provided a local model_path (no download needed, no probe).
  • XINFERENCE_MODEL_SRC=auto is also supported.
  • Web UI: the download hub dropdown now offers auto alongside the existing options.
  • Docs updated (models/sources/sources.rst, getting_started/environments.rst).

Behavior priority: explicit --download_hub > XINFERENCE_MODEL_SRC env > automatic connectivity detection. The locale heuristic is kept as the fallback inside download_from_modelscope() for code paths that never receive a resolved hub.

Verification

  • Added unit tests in xinference/model/tests/test_utils.py covering detection (reachable/unreachable/cached), resolve_download_hub priorities, and XINFERENCE_MODEL_SRC=auto — all pass.
  • Full xinference/model/tests/test_utils.py passes locally (one pre-existing network-flaky download test passed on re-run).
  • pre-commit (black/ruff/isort/mypy/codespell) passes on the changed files; frontend file passes Prettier and ESLint.
  • Manual sanity check on a machine with Hugging Face access: detection returns huggingface; resolve_download_hub("auto")/resolve_download_hub(None) resolve accordingly and explicit hubs pass through untouched.

Add an "auto" download_hub option and make automatic detection the
default: probe whether the Hugging Face endpoint is reachable (honoring
HF_ENDPOINT mirrors and HTTP(S)_PROXY proxies) and pick huggingface if
so, otherwise fall back to modelscope. The probe result is cached per
process and its timeout is tunable via XINFERENCE_HUB_DETECT_TIMEOUT.

Priority: explicit --download_hub > XINFERENCE_MODEL_SRC env (which now
also accepts "auto") > connectivity detection. A local model_path skips
detection since no download is needed.
@XprobeBot XprobeBot added this to the v3.x milestone Jul 31, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces automatic detection of the model download hub (Hugging Face vs. ModelScope) by probing Hugging Face endpoint connectivity. It adds support for an "auto" download hub option, caches the detection result, and allows configuring the probe timeout. Feedback on the changes includes addressing a bug in resolve_download_hub when XINFERENCE_MODEL_SRC is set to "auto" and download_hub is None, catching broader exceptions during the connectivity probe to prevent unexpected crashes, and adding a test case to verify the resolution logic under the "auto" environment variable setting.

Comment thread xinference/model/utils.py Outdated
Comment thread xinference/model/utils.py Outdated
Comment thread xinference/model/tests/test_utils.py
- resolve_download_hub now resolves XINFERENCE_MODEL_SRC="auto" to a
  concrete hub itself instead of relying on the legacy fallback inside
  download_from_modelscope (review feedback), with a test for it
- probe failures now swallow any exception, not just RequestException,
  so a malformed HF_ENDPOINT/proxy config cannot break a model launch
- pass a narrowly-typed resolved hub to downstream create_*_model_instance
  functions to fix mypy arg-type errors in CI
Comment thread xinference/model/utils.py Outdated
Comment thread doc/source/models/sources/sources.rst
Comment thread xinference/model/core.py
@OliverBryant OliverBryant self-assigned this Aug 3, 2026
- treat HTTP error responses (403/407 blocking proxies, 5xx broken
  mirrors) from the reachability probe as unreachable, since downloads
  would fail anyway; documented and covered by tests
- default XINFERENCE_MODEL_SRC to "auto" in the Docker Compose
  deployment (and .env.example / docs) so the main deployment path gets
  auto detection instead of a pinned huggingface source
- image/video/embedding/rerank matchers no longer let the
  XINFERENCE_MODEL_SRC fallback override an explicitly requested
  download_hub; the env is consulted only when no hub is given, matching
  the documented priority order, with an end-to-end priority test
Comment thread xinference/deploy/docker/docker-compose.yml
Offline / air-gapped Compose deployments set HF_HUB_OFFLINE=1 and read
model weights from a pre-populated local Hugging Face cache. Probing
there necessarily fails and auto detection would fall back to
modelscope, whose spec bypasses that cache and attempts a real
download. When HF_HUB_OFFLINE / TRANSFORMERS_OFFLINE is enabled,
detection now skips the probe and selects huggingface directly, so the
offline profile keeps working with the default XINFERENCE_MODEL_SRC=auto.
Documented in sources.rst and offline.env.example (including how to pin
modelscope via .env when the local cache is a ModelScope one), with
offline regression tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants