Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: lazy-import matplotlib so the server starts when the wheel is blocked (#6596)
Leo Borcherding69d8a57ee9d2
diff --git a/studio/backend/core/training/training.py b/studio/backend/core/training/training.pyindex 34bb4331a72..290b4090ec7 100644--- a/studio/backend/core/training/training.py+++ b/studio/backend/core/training/training.py@@ -24,9 +24,10 @@ from datetime import datetime, timezonefrom loggers import get_loggerfrom dataclasses import dataclass, fieldfrom pathlib import Path-from typing import Optional, Tuple, Any+from typing import Optional, Tuple, Any, TYPE_CHECKING-import matplotlib.pyplot as plt+if TYPE_CHECKING:+ import matplotlib.pyplot as pltfrom utils.hardware import prepare_gpu_selectionfrom utils.native_path_leases import (native_path_secret_removed_for_child_start,@@ -36,6 +37,30 @@ from utils.paths import outputs_rootlogger = get_logger(__name__)+_pyplot = None+_pyplot_failed = False+++def _load_pyplot():+ """Lazily import matplotlib.pyplot (headless Agg); return it, or None if+ matplotlib is unavailable. Deferred so a blocked native wheel (e.g. Windows+ Smart App Control) never breaks server startup, only loss plotting.+ """+ global _pyplot, _pyplot_failed+ if _pyplot is not None or _pyplot_failed:+ return _pyplot+ try:+ import matplotlib++ matplotlib.use("Agg") # headless backend+ import matplotlib.pyplot as plt++ _pyplot = plt+ except Exception as e:+ _pyplot_failed = True+ logger.warning("matplotlib unavailable; loss plots disabled", error = str(e))+ return _pyplot+def _coerce_seed(value, default = 3407) -> int:"""Normalize None / non-int to `default` (transformers.set_seed(None) raises)."""@@ -655,7 +680,7 @@ class TrainingBackend:plot = self._create_loss_plot(progress, theme)return (plot, progress)- def refresh_plot_for_theme(self, theme: str) -> Optional[plt.Figure]:+ def refresh_plot_for_theme(self, theme: str) -> "Optional[plt.Figure]":"""Refresh plot with new theme."""if theme and isinstance(theme, str) and theme in ["light", "dark"]:self.current_theme = theme@@ -1090,8 +1115,14 @@ class TrainingBackend:self,progress: TrainingProgress,theme: str = "light",- ) -> plt.Figure:- """Create training loss plot with theme-aware styling."""+ ) -> "Optional[plt.Figure]":+ """Create training loss plot with theme-aware styling.++ matplotlib is loaded lazily; returns None if it is unavailable.+ """+ plt = _load_pyplot()+ if plt is None:+ return Noneplt.close("all")LIGHT_STYLE = {diff --git a/studio/backend/requirements/extras.txt b/studio/backend/requirements/extras.txtindex 40737b08764..b56c2dfa402 100644--- a/studio/backend/requirements/extras.txt+++ b/studio/backend/requirements/extras.txt@@ -39,7 +39,7 @@ ftfyimportlib-resourceslibrosamarkdown2-matplotlib+matplotlib==3.10.9pystoisoundfiletensorboarddiff --git a/studio/backend/requirements/studio.txt b/studio/backend/requirements/studio.txtindex 96fef60471b..9efa10faef0 100644--- a/studio/backend/requirements/studio.txt+++ b/studio/backend/requirements/studio.txt@@ -4,7 +4,7 @@ fastapiuvicornpydanticpackaging-matplotlib+matplotlib==3.10.9pandasnest_asynciodatasets==4.3.0