← Back to Pull requests

fix(virtualenv): keep the parent huggingface-hub for diffusers models #5715

Closed
unknown closed this pull request without merging on Oct 17, 2026 05:15 UTC
View on GitHub
unknown unknown commented on Oct 16, 2026 22:54 UTC
Author

What happens

With the model virtualenv on (the default), I observed launch failures for sdxl-turbo on 8491418 and sd-turbo on 6aac142, on a host with transformers 5.17.0. The engine's package list pins huggingface-hub<1.0, so the venv installs hub 0.x, which shadows the host's 1.x. Importing the model then fails inside the model process:

ImportError: cannot import name 'is_offline_mode' from 'huggingface_hub' (.../virtualenv/v4/sdxl-turbo/diffusers/...)

The client sees a 500 whose detail includes Remote server unixsocket:///... closed: 0 bytes read on a total of 11 expected bytes. In the sdxl-turbo probe on 8491418, launching with enable_virtual_env=false returned 200.

On a real GPU (RTX 4090; host transformers 5.17.0, diffusers 0.41.0, huggingface_hub 1.33.0), launching sd-turbo with the default virtualenv, after deleting its venv so it is rebuilt:

| | 6aac142 | with this PR |
|---|---|---|
| launch | 500 after 8.6 s (Remote server unixsocket:///... closed); model log: ImportError: cannot import name 'is_offline_mode' from 'huggingface_hub' | 200 after 18 s |
| packages the venv is built from | ['diffusers>=0.32.0', 'huggingface-hub<1.0', 'transformers>=4.51.0', ...] | ['diffusers>=0.32.0', '#system_huggingface-hub#', 'transformers>=4.51.0', ...] |
| huggingface_hub inside the venv | 0.36.2 | 1.33.0, the host's |
| /v1/images/generations, 512x512, 1 step | model not running | 200, a 512x512 JPEG in 1.3 s |

Cause

On 6aac142, ENGINE_VIRTUALENV_PACKAGES["diffusers"] in xinference/core/virtual_env_manager.py lists huggingface-hub<1.0. Model venvs inherit the parent's site-packages. The tested transformers 5.17.0 declares huggingface-hub>=1.5.0,<2.0, so the cap forces an incompatible hub into the venv on that host. #diffusers_dependencies# expands to this list when the diffusers engine is selected (23 built-in image specs use it).

Change

  • Replace the cap with #system_huggingface-hub#, which initially requests the parent's own hub version, as the existing #system_torch# / #system_numpy# markers do for those packages. This also supplies the parent hub constraint when diffusers needs installing. An explicit hub requirement in virtual_env_packages still overrides the default; xoscar's existing retry can relax system pins after a failed install.

  • Rebuild an already affected model virtualenv before retrying: with skip-installed enabled, xoscar checks the parent's packages, so an old hub copy in the child can remain. This change does not add migration of existing environments.

  • Not changed: four specs (Qwen-Image, Qwen-Image-Edit, Qwen-Image-2512, FLUX.1-Kontext-dev) pin diffusers==0.35.1 together with their own huggingface-hub<1.0. On a transformers 5.17.0 parent, diffusers 0.35.1 cannot import its pipelines at any hub version (cannot import name 'FLAX_WEIGHTS_NAME' from 'transformers.utils'), so they need a diffusers bump, which is a separate change.
  • Tests

    xinference/core/tests/test_virtual_env_manager.py:

  • test_diffusers_keeps_parent_hub: four cases cross fake parent versions (hub 0.36.2 with transformers 4.57.3, hub 1.33.0 with transformers 5.17.0) with diffusers present or absent. They exercise placeholder expansion, xoscar's process_packages, and its skip-installed filter. With diffusers absent, the test checks that the parent hub and transformers versions reach the mocked resolver as constraints. These are package-planning tests, not actual installs or pipeline-import compatibility checks;

  • test_diffusers_hub_override_and_other_engine_control: an explicit hub requirement still wins, and the transformers engine's package list is unchanged.
  • In my outside-sandbox runs with the 6aac142 virtual_env_manager.py and the new tests, all 4 test_diffusers_keeps_parent_hub cases fail at assert f"huggingface-hub=={hub}" in packages: the list still contains huggingface-hub<1.0. The override/transformers-engine control passes.

    I ran these outside the sandbox on this branch (Linux under WSL, xoscar 0.12.0):

  • PYTHONPATH=. python -m pytest xinference/core/tests/test_virtual_env_manager.py -q --timeout=300 on Python 3.12.15 and 3.10.12: the 5 new test cases pass, twice on each Python version. The full file has a pre-existing intermittent failure in test_dependency_install_progress_counts_matching_child_distributions, also seen on unmodified 6aac142 (4 of 6 runs).

  • pre-commit run --files xinference/core/virtual_env_manager.py xinference/core/tests/test_virtual_env_manager.py: black, end-of-file, trailing-whitespace, ruff, isort, mypy and codespell pass.
  • The GPU result comes from my own probe (not part of this PR) against xinference-local on 6aac142, first unchanged and then with this change's virtual_env_manager.py, deleting the model's virtualenv before each launch.

    AI assistance: the bug was found and the fix drafted with AI tools (OpenAI Codex, Claude Code).

    🤖 Generated with Claude Code

    https://claude.ai/code/session_019TTGAv6fe859ebbCLLfLHP

    Diff: 636 lines (+477 / -159) across 7 files Reviewer: Jackmeson1 Review duration: 381m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 636 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.386
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5715"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.4% (MEDIUM) · Higher = larger blast radius
    50.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.9% · Safe to merge
    19.9%