Repository navigation
Studio: lazy-import matplotlib so the server starts when the wheel is blocked - #6596
danielhanchen merged 5 commits into
Conversation
… blocked matplotlib.pyplot was imported at the top of core/training/training.py, on the server boot path. When matplotlib's native extension fails to load (e.g. an unsigned wheel blocked by Windows Smart App Control), that import crashed the whole Studio server at startup instead of just disabling loss plots. Move it into a lazy _load_pyplot() helper called from _create_loss_plot, using the headless Agg backend, and return None when matplotlib is unavailable so plotting degrades gracefully. The plot return was already Optional, so callers need no changes. Keep the type-only import under TYPE_CHECKING and quote the annotations. Fixes unslothai#6588
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
One thing worth flagging for awareness: matplotlib is unpinned in |
|
The failing check "Core / llama.cpp build + smoke" looks unrelated to this PR. AssertionError: llama-cli not found at '/home/runner/.unsloth/llama.cpp/llama-cli' The job pulled the prebuilt app-b9739-mix-2d6bd50-linux-x64-cpu bundle and it |
Pin matplotlib to the current latest so a new unsigned release does not reintroduce the Smart App Control block on Windows. Belt-and-suspenders on top of the lazy import. Pinned in both studio.txt and extras.txt.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d467d2c5d
ℹ️ 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".
| pydantic | ||
| packaging | ||
| matplotlib | ||
| matplotlib==3.11.0 |
There was a problem hiding this comment.
Keep Studio installable on Python 3.10
This pin makes pip install -r studio/backend/requirements/studio.txt unsatisfiable on Python 3.10 because matplotlib 3.11.0 declares Requires-Python >=3.11; the backend CI matrix still includes Python 3.10 and installs this exact file (.github/workflows/studio-backend-ci.yml:53,68), and pyproject.toml still advertises support below 3.11. Users on supported 3.10 will fail during dependency install before the lazy-import fallback can help; use a 3.10-compatible upper bound or a Python-version marker instead.
Useful? React with 👍 / 👎.
matplotlib 3.11.0 requires Python >=3.11, so the pin had no installable wheel on Python 3.10 (still supported) and pip install failed there. 3.10.9 is the latest 3.10.x (requires-python >=3.10) and covers Python 3.10 through 3.13. Also tighten the lazy-import docstrings.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Pushed a small fix on top: pinned
Verified on Windows and Ubuntu across Python 3.10 and 3.13: the module still imports with matplotlib blocked, The other red checks look unrelated to this change:
Also tightened the lazy-import docstrings while here. |
Issue
On Windows with Smart App Control enabled, Studio fails to start.
matplotlib.pyplotwas imported at the top ofstudio/backend/core/training/training.py, which is on the server boot path (main->routes->core.training->training). When matplotlib's native extension cannot load, that import raises and takes down the whole server.A common trigger is Smart App Control blocking matplotlib's unsigned
_c_internal_utilswheel, but any environment where matplotlib's native libs are missing or broken hits the same crash. matplotlib is also unpinned, so a fresh release can reintroduce it at any time. See #6588 for the full write-up.Fix
Make matplotlib lazy so it never loads during server startup:
_load_pyplot()helper called on first plot, using the headlessAggbackend.Nonewhen matplotlib is unavailable, so loss plotting degrades gracefully instead of crashing._create_loss_plotalready returned an optional figure, so callers need no changes.TYPE_CHECKINGand quote the annotations.Testing
_load_pyplot()returnsNoneand logs a warning._load_pyplot()returns pyplot on theAggbackend.--localinstall on Windows + AMD ROCm (gfx1200): server now reaches "Application startup complete"; training, chat, and export all work.Fixes #6588