Skip to content

pip: declare the Studio dependencies the wheel's own modules import - #7493

Merged
danielhanchen merged 6 commits into
pipfrom
fix/studio-pip-deps
Jul 27, 2026
Merged

danielhanchen merged 6 commits into
pipfrom
fix/studio-pip-deps

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

The wheel packages studio/ and studio.backend*, so a plain pip install unsloth puts five commands on PATH, and every one of them imports the backend:

unsloth export / list-checkpoints   FAILS -> No module named 'structlog'
unsloth train                       FAILS -> No module named 'structlog'
unsloth chat                        FAILS -> No module named 'structlog'
unsloth studio                      FAILS -> No module named 'structlog'
unsloth inference                   FAILS -> No module named 'structlog'

None of those imports were declared, so all five ended in a rich traceback. Reported against unsloth export doing an fp16 merge, and it is the same underlying gap as #4701, #5260 and #7147.

unsloth train reaches it unconditionally: train.py:119 calls _create_cli_trainer, which hits from studio.backend.core.training.training import ... at train.py:17, and training.py:24 is import structlog. This hid well because typer defers the import, so --help renders 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 starlette in studio/backend/loggers/handlers.py moves under TYPE_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 of unsloth train).

So:

  • structlog>=24.1.0 becomes a core dependency.
  • The rest of the server stack (fastapi, uvicorn, matplotlib, pandas, pymupdf, boto3 and friends) becomes a studio extra mirroring studio/backend/requirements/studio.txt, which is what install.sh installs.
  • tests/studio/install/test_studio_extra_matches_requirements.py fails if the extra and the requirements file drift apart, and asserts structlog stays in core.
pip install unsloth            -> train / export work
pip install "unsloth[studio]"  -> the server works

Targeting pip because that is the branch the PyPI wheel is built from. The main copy of pyproject.toml gets 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.0 present in core Requires-Dist (28 entries, was 27)
  • Provides-Extra: studio with 22 entries

Before this change, a wheel-metadata job on macOS arm64, macOS x64, Windows and Linux runners reported structlog, fastapi, uvicorn, diceware and pyjwt all declared_anywhere=False while studio/backend/run.py was shipped=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

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
@pre-commit-ci
pre-commit-ci Bot requested review from Datta0 and Etherll as code owners July 27, 2026 10:09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread pyproject.toml
"httpx>=0.27.0",
"fastmcp>=3.0.2",
"sqlite-vec==0.1.9",
"pymupdf==1.27.2.3",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +72 to +73
assert not missing, (
f"studio.txt lists {missing} but the `studio` extra does not. "

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread pyproject.toml
# 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 = [

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment thread pyproject.toml
"boto3>=1.34.0",
"httpx>=0.27.0",
"fastmcp>=3.0.2",
"sqlite-vec==0.1.9",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@danielhanchen
danielhanchen merged commit 735fcde into pip Jul 27, 2026
49 of 54 checks passed
@danielhanchen
danielhanchen deleted the fix/studio-pip-deps branch July 27, 2026 10:44
danielhanchen added a commit that referenced this pull request Jul 27, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant