fix(studio): load run.py by path for editable installs#5909
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a dynamic module loader, _load_run_module, in unsloth_cli/commands/studio.py to load studio.backend.run directly by its file path. This change prevents import conflicts where partial site-packages installations shadow editable installs. The command functions have been refactored to use this dynamic loader instead of static imports. Feedback was provided to optimize the loader by avoiding unnecessary path resolution when the module is not already loaded, and to defensively clean up sys.modules if the module execution fails.
|
The one Codex item (null-check before resolving Pushed f39dee5 to resolve the merge conflict. The No requested reviewers are set on this PR — could a maintainer assign reviewers and approve the |
`studio update` can leave a partial site-packages/studio/backend/ tree (plugin build artefacts only). That shadowed tree wins over an editable install and breaks `from studio.backend.run import ...`. Loading run.py by file path via importlib sidesteps the conflict. The module is cached in _RUN_MODULE so repeated calls are cheap. If exec_module fails, the module is removed from sys.modules before re-raising so a subsequent retry starts clean. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
f39dee5 to
74b7805
Compare
for more information, see https://pre-commit.ci
|
Pushed 58bb422 which handles one edge case: if a partial shadow tree leaves |
|
Synced with latest
Waiting on maintainer review/approval. pre-commit.ci is the only automated gate visible from fork PRs; GitHub Actions still require maintainer approval for first-time contributors. |
|
Ran cross-platform simulations (isolated uv venv + real-filesystem reproduction) and found two issues in the editable-install module loaders, now fixed:
Filesystem sim also confirms the core fix: the original |
|
@jimdawdy-hub Appreciate the PR - this works! |
Summary
_load_run_module()inunsloth_cli/commands/studio.pyto importstudio/backend/run.pyby file path via the existing_find_run_py()helper, instead offrom studio.backend.run import …._load_run_module()in bothstudio runand plainunsloth studiostartup paths (server launch, shutdown hooks, external-IP display).This fixes
ModuleNotFoundError: No module named 'studio.backend.run'when developing withpip install -eafterunsloth studio update --local.Root cause
studio update/ plugin build steps can leave a partial package tree under the Studio venv:Python’s import machinery can resolve
studio/studio.backendto that shadow tree instead of the editable checkout at…/Projects/unsloth/studio/backend/run.py. The CLI then crashes at:because
run.pynever existed in the shadow directory._find_run_py()already locates the realrun.pywithout relying on CWD; this PR uses it for the actual import as well.Related PRs
Independent of the chat race / mmproj fixes:
llama_extra_argsand honor--no-mmprojNo file overlap with those PRs (this change is CLI-only).
Reproduction (before fix)
Environment: Arch Linux, dual RTX 5060 Ti, editable install (
pip install -e /home/jim/Projects/unsloth), Studio venv at~/.unsloth/studio/unsloth_studio.Command:
Result: immediate crash — CLI never reaches model load:
Note:
--variantis a llama-server pass-through flag (invalid for this repo’s CLI). Use--gguf-variantfor the Studio quant selector. The failure above occurs before llama-server starts, on the import line.Workaround without this patch:
rm -rf ~/.unsloth/studio/unsloth_studio/lib/python3.13/site-packages/studio(Must be repeated after
studio updaterecreates the shadow tree.)Verification (after fix)
Same machine, same editable install, with partial shadow tree present at
site-packages/studio/backend/plugins/(norun.py):Successful
studio run(correct Studio flag):No
ModuleNotFoundError. Model loads with--no-mmprojhonored (no mmproj download; llama-server launched with--no-mmprojonly).Test plan
pip install -e .into Studio venv, rununsloth studio update --local, confirm partialsite-packages/studio/backend/existsunsloth studio run -m <gguf-repo> --gguf-variant <variant> --no-mmprojstarts without import errorunsloth studio -p 8888still starts and shuts down cleanly (Ctrl+C)pip install .) installs unaffected —_find_run_py()still resolvesrun.pyunder site-packages when presentMade with Cursor