fix(virtualenv): keep the parent huggingface-hub for diffusers models #5715
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
Jackmeson1
What happens
With the model virtualenv on (the default), I observed launch failures for sdxl-turbo on
8491418and sd-turbo on6aac142, on a host with transformers 5.17.0. The engine's package list pinshuggingface-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:The client sees a
500whose detail includesRemote server unixsocket:///... closed: 0 bytes read on a total of 11 expected bytes. In the sdxl-turbo probe on8491418, launching withenable_virtual_env=falsereturned200.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 |
500after 8.6 s (Remote server unixsocket:///... closed); model log:ImportError: cannot import name 'is_offline_mode' from 'huggingface_hub'|200after 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_hubinside 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"]inxinference/core/virtual_env_manager.pylistshuggingface-hub<1.0. Model venvs inherit the parent's site-packages. The tested transformers 5.17.0 declareshuggingface-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
#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 invirtual_env_packagesstill overrides the default; xoscar's existing retry can relax system pins after a failed install.diffusers==0.35.1together with their ownhuggingface-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'sprocess_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
6aac142virtual_env_manager.pyand the new tests, all 4test_diffusers_keeps_parent_hubcases fail atassert f"huggingface-hub=={hub}" in packages: the list still containshuggingface-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=300on 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 intest_dependency_install_progress_counts_matching_child_distributions, also seen on unmodified6aac142(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-localon6aac142, first unchanged and then with this change'svirtual_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