Repository navigation
Studio: self-heal unsloth namespace shadows; clearer failed-load messages - #6532
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
… workers A directory named `unsloth` (or `unsloth_zoo`) without an __init__.py on PYTHONPATH/sys.path, a stray source checkout or a polluted PYTHONPATH, makes `import unsloth` resolve to an empty namespace package, so a worker's `from unsloth import FastLanguageModel` dies with a cryptic "cannot import name ... (unknown location)". The LLM training path already recovered from this via `_ensure_real_packages` in trainer.py (PR #6269), but the inference, export, and embedding-training subprocesses imported Unsloth directly with no guard. Extract that helper into a shared, dependency-free core/import_guards.py and call it before the Unsloth import in every subprocess: it drops the offending sys.path entries, imports the real packages (unsloth before unsloth_zoo so the pre-zoo GPU fixes run), then restores sys.path. trainer.py now imports the shared helper instead of its local copy. Covers both unsloth and unsloth_zoo and both namespace origin forms (None and "namespace"). The existing PR #6269 test now exercises the shared helper.
…ates A failed load never sets the checkpoint, so the image and audio attach gates fell through to "Load a model before adding images/audio", which reads as if the user simply forgot to pick a model rather than that the load errored. Add a dedicated lastModelLoadError to the chat runtime store, set only when an actual load attempt fails (not on refresh, list, status, or unload errors, which keep using modelsError) and cleared when the next load starts. The image gate (all three call sites) and the audio gate now use it to report a failed load and point at the server logs, while still blocking in exactly the same cases.
ce5e189 to
c91b268
Compare
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fff58c0f28
ℹ️ 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".
| const message = | ||
| error instanceof Error ? error.message : "Failed to load model"; | ||
| setModelsError(message); | ||
| setLastModelLoadError(message); // load-specific failure for the attach gates |
There was a problem hiding this comment.
Avoid marking preflight rejections as load failures
When validateModel() rejects an invalid identifier or the user declines the remote-code/security review, this outer catch still runs before loadModel() was ever called, and setting lastModelLoadError makes the image/audio attach gates later say “The last model failed to load. Check the server logs...” whenever no model is loaded. In those preflight/cancel paths there is no failed server-side load to diagnose, so track whether the actual load request started or keep those errors only in modelsError to avoid sending users to irrelevant logs.
Useful? React with 👍 / 👎.
Summary
Two independent Studio fixes that turn a failed model load from a confusing dead end into something the user can act on, hardened after an internal multi-reviewer pass. Both came out of a real case where loading a non-GGUF model failed and the only visible symptom was the chat composer saying "Load a model before adding images.", which looks like the user simply forgot to pick a model.
1. Backend: self-heal
unsloth/unsloth_zoonamespace-package shadowsA directory named
unsloth(orunsloth_zoo) without an__init__.pyonPYTHONPATH/sys.path(a stray source checkout, or launching Studio from a directory that contains one) makesimport unslothresolve to an empty namespace package, so a worker'sfrom unsloth import FastLanguageModeldies with a crypticcannot import name ... (unknown location).The LLM training path already recovered from this via
_ensure_real_packagesintrainer.py(PR #6269), but the inference, export, and embedding-training subprocesses imported Unsloth directly with no guard. This extracts that helper into a shared, dependency-freecore/import_guards.pyand calls it before the Unsloth import in every subprocess. Rather than just raising a clearer error, it recovers: it drops the offendingsys.pathentries, imports the real packages (unsloth before unsloth_zoo so the pre-zoo GPU fixes run), then restoressys.path.trainer.pynow imports the shared helper instead of keeping its own copy.Covers both
unslothandunsloth_zoo, and both namespace origin forms (Noneand"namespace").2. Frontend: distinguish a failed load from "no model picked"
A failed load never sets the checkpoint, so the image and audio attach gates fell through to "Load a model before adding images/audio", which reads as if the user simply forgot to pick a model rather than that the load errored. This adds a dedicated
lastModelLoadErrorto the chat runtime store, set only when an actual load attempt fails (not on refresh/list/status/unload errors, which keep usingmodelsError) and cleared when the next load starts. The image gate (all three call sites) and the audio gate now report a failed load and point at the server logs:The gates still block in exactly the same cases.
Testing
test_namespace_shadow_guard_pr6269.py) now exercises the sharedensure_real_packagesand passes (7 passed). It verifies recovery, unsloth-before-unsloth_zoo import order,sys.pathrestoration (even wheninvalidate_cachesraises), andModuleNotFoundErrorwhen the package is genuinely absent.py_compilepasses on all changed backend files.tsc -btypecheck andvite buildpass. The eslint problem count on the changed files is unchanged before/after, so the diff adds no new lint issues.