Skip to content

Studio: self-heal unsloth namespace shadows; clearer failed-load messages - #6532

Merged
danielhanchen merged 4 commits into
mainfrom
studio-clearer-load-failure-messages
Jun 22, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
studio-clearer-load-failure-messages

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Jun 21, 2026 •

Copy link
Copy Markdown
Member

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_zoo namespace-package shadows

A directory named unsloth (or unsloth_zoo) without an __init__.py on PYTHONPATH / sys.path (a stray source checkout, or launching Studio from a directory that contains one) 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. This extracts that helper into a shared, dependency-free core/import_guards.py and calls it before the Unsloth import in every subprocess. Rather than just raising a clearer error, it recovers: 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 keeping its own copy.

Covers both unsloth and unsloth_zoo, and both namespace origin forms (None and "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 lastModelLoadError to the chat runtime store, set only when an actual load attempt fails (not on refresh/list/status/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 report a failed load and point at the server logs:

The last model failed to load. Check the server logs, then load a model before adding images.

The gates still block in exactly the same cases.

Testing

  • Backend: the existing PR Studio: keep training from failing when a namespace-package shadows unsloth #6269 namespace-shadow test (test_namespace_shadow_guard_pr6269.py) now exercises the shared ensure_real_packages and passes (7 passed). It verifies recovery, unsloth-before-unsloth_zoo import order, sys.path restoration (even when invalidate_caches raises), and ModuleNotFoundError when the package is genuinely absent. py_compile passes on all changed backend files.
  • Frontend: tsc -b typecheck and vite build pass. The eslint problem count on the changed files is unchanged before/after, so the diff adds no new lint issues.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

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.
@danielhanchen
danielhanchen force-pushed the studio-clearer-load-failure-messages branch from ce5e189 to c91b268 Compare June 21, 2026 11:54
@danielhanchen danielhanchen changed the title Studio: clearer messages when a model load fails Studio: self-heal unsloth namespace shadows; clearer failed-load messages Jun 21, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 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

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

@danielhanchen
danielhanchen merged commit cba7345 into main Jun 22, 2026
33 of 34 checks passed
@danielhanchen
danielhanchen deleted the studio-clearer-load-failure-messages branch June 22, 2026 05:43
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