Repository navigation
pip: declare the Studio dependencies the wheel's own modules import - #7493
Conversation
The wheel packages studio/ and studio.backend*, so pip install unsloth puts five commands on PATH -- train, export, chat, inference, studio -- and every one of them imports studio.backend.*. None of those imports were declared, so all five ended in a rich traceback at ModuleNotFoundError: No module named 'structlog' (#4701, #5260, #7147). --help rendered fine for all of them because typer defers the import, which is why this went unnoticed. Walking module-level, non-try-guarded imports from each entry point shows structlog is the only hard requirement they share, once starlette's annotation-only import in loggers/handlers.py moves under TYPE_CHECKING. So structlog becomes a core dependency and the rest of the server stack (fastapi, uvicorn, matplotlib, pandas, pymupdf, ...) becomes a [studio] extra mirroring studio/backend/requirements/studio.txt, with a test that fails if the two drift. pip install unsloth -> train / export work pip install "unsloth[studio]" -> the server works
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0d87cfb62
ℹ️ 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".
| "httpx>=0.27.0", | ||
| "fastmcp>=3.0.2", | ||
| "sqlite-vec==0.1.9", | ||
| "pymupdf==1.27.2.3", |
There was a problem hiding this comment.
Keep the Studio extra installable on Python 3.9
When installing on Python 3.9—which the project explicitly supports via requires-python = ">=3.9,<3.15"—pip install "unsloth[studio]" is unsatisfiable because pymupdf==1.27.2.3 declares Requires-Python: >=3.10 (and the pinned pymupdf4llm has the same floor). Either provide Python-3.9-compatible requirements for this extra or raise/otherwise qualify the supported Python floor so users do not encounter a resolver failure.
Useful? React with 👍 / 👎.
| assert not missing, ( | ||
| f"studio.txt lists {missing} but the `studio` extra does not. " |
There was a problem hiding this comment.
Compare requirement specifiers as well as package names
When a dependency pin or bound is changed in only one source, this test still passes because _normalise strips all version specifiers before these lists are compared; for example, datasets==4.3.0 and datasets==4.2.0 both become datasets. That defeats the test's stated purpose of keeping the extra and studio.txt equivalent and can allow the pip and installer environments to drift despite a green test.
Useful? React with 👍 / 👎.
78b4ea5 to
cbdb69c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 45686b9000
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| # studio/backend/requirements/studio.txt (what install.sh installs); | ||
| # tests/studio/install/test_studio_extra_matches_requirements.py catches drift. | ||
| # structlog is also a core dependency, since the CLI needs it without a server. | ||
| studio = [ |
There was a problem hiding this comment.
Let pip-installed Studio run in the current environment
In a normal virtual environment created with pip install "unsloth[studio]", these dependencies are installed into the current sys.prefix, but studio_default only considers environments under STUDIO_HOME/unsloth_studio runnable and otherwise requires the separate interpreter returned by _studio_venv_python (unsloth_cli/commands/studio.py:206-212,1452-1461). Thus unsloth studio still exits with “Unsloth Studio not set up. Run install.sh first,” so the newly advertised pip-only server installation cannot actually launch through the packaged entry point; allow the current environment when the extra is installed or avoid presenting this extra as a supported standalone Studio installation.
Useful? React with 👍 / 👎.
| "boto3>=1.34.0", | ||
| "httpx>=0.27.0", | ||
| "fastmcp>=3.0.2", | ||
| "sqlite-vec==0.1.9", |
There was a problem hiding this comment.
Include an embedding backend in the Studio extra
On a fresh pip-only installation with no installer-managed llama-server binary, the RAG dependencies added here cannot actually ingest or search documents: core/rag/embeddings.py resolves auto to sentence-transformers whenever a GPU is present or no llama binary exists, then imports sentence_transformers, but neither the core dependencies nor this extra installs it—it appears only in extras-no-deps.txt, which pip does not process. The fallback also returns None when the installer has not downloaded llama-server, so the original missing-module error is re-raised; include sentence-transformers or another usable embedding backend in this extra.
Useful? React with 👍 / 👎.
45686b9 to
ab555c5
Compare
unsloth_cli/commands/start.py imports click at module scope, and unsloth_cli/__init__.py imports that module, so every unsloth command needs it. typer carried click through 0.19 and dropped it in 0.27, and the declared floor is typer>=0.12.0, so a fresh resolve gets none. The wheel still works today only because huggingface_hub requires click<9,>=8.4.2, which is luck rather than a declaration. Verified on a wheel built from a dependency list without that transitive provider: every command, including `unsloth --help`, died with ModuleNotFoundError for click. Same class as the structlog gap in #7493, so the drift test covers both now.
Summary
The wheel packages
studio/andstudio.backend*, so a plainpip install unslothputs five commands on PATH, and every one of them imports the backend:None of those imports were declared, so all five ended in a rich traceback. Reported against
unsloth exportdoing an fp16 merge, and it is the same underlying gap as #4701, #5260 and #7147.unsloth trainreaches it unconditionally:train.py:119calls_create_cli_trainer, which hitsfrom studio.backend.core.training.training import ...attrain.py:17, andtraining.py:24isimport structlog. This hid well because typer defers the import, so--helprenders a full page for all five commands before anything fails.Changes
Walking module-level, non-try-guarded imports from each entry point shows structlog is the only hard requirement they share, once
starletteinstudio/backend/loggers/handlers.pymoves underTYPE_CHECKING(it was annotation-only there, and that module is on the import path of every CLI command, so importing it made the whole ASGI stack a hard dependency ofunsloth train).So:
structlog>=24.1.0becomes a core dependency.studioextra mirroringstudio/backend/requirements/studio.txt, which is what install.sh installs.tests/studio/install/test_studio_extra_matches_requirements.pyfails if the extra and the requirements file drift apart, and asserts structlog stays in core.Targeting
pipbecause that is the branch the PyPI wheel is built from. Themaincopy ofpyproject.tomlgets the same change in #7492 so the two stop diverging further.Testing
Built the wheel from this branch and checked the metadata:
structlog>=24.1.0present in coreRequires-Dist(28 entries, was 27)Provides-Extra: studiowith 22 entriesBefore this change, a wheel-metadata job on macOS arm64, macOS x64, Windows and Linux runners reported
structlog,fastapi,uvicorn,dicewareandpyjwtalldeclared_anywhere=Falsewhilestudio/backend/run.pywasshipped=True.The friendly error the CLI now prints when the extra is absent, plus the guards at the import sites, are in #7492.
Related: #4701, #5260, #7147