aboutsummaryrefslogtreecommitdiff
path: root/app/backends/sglomni/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/backends/sglomni/models.py')
-rw-r--r--app/backends/sglomni/models.py41
1 files changed, 39 insertions, 2 deletions
diff --git a/app/backends/sglomni/models.py b/app/backends/sglomni/models.py
index a5211f6..607e36a 100644
--- a/app/backends/sglomni/models.py
+++ b/app/backends/sglomni/models.py
@@ -22,7 +22,8 @@ from pathlib import Path
from typing import List, Optional
from backends import common, envs
-from backends.sglomni.catalog import ModelEntry, entry_by_key, entry_by_repo
+from backends.sglomni.catalog import ModelEntry, entry_by_key, \
+ entry_by_repo, extra_import_name
from backends.sglomni.constants import SERVER_NAME, SGLOMNI_PIP_PKG
from backends.sglomni.pythonenv import SGLOMNI_ENV, prepare_env
@@ -129,6 +130,42 @@ def system_dep_missing(entry: ModelEntry) -> Optional[str]:
return None
+def missing_companions(entry: ModelEntry) -> List[Extra]:
+ """ENTRY's companion packages absent from the sglang-omni venv.
+
+ One import probe per extra (its top-level module, see
+ ``extra_import_name``) against the venv's interpreter, so a model whose
+ weights landed in the shared HF cache by another route — or whose
+ companions failed to pip-install during setup, which install_model only
+ warns about — is detected before the server dies on the import. A venv
+ that does not exist at all yields no verdict: the start flow fails on
+ the missing ``sgl-omni`` executable anyway."""
+ if not entry.extras or not envs.env_exists(SGLOMNI_ENV):
+ return []
+ return [extra for extra in entry.extras
+ if not envs.module_available(extra_import_name(extra[0]),
+ SGLOMNI_ENV)]
+
+
+def install_companions(entry: ModelEntry, *, emit=None, cancel=None) -> int:
+ """pip-install ENTRY's missing companion packages into the venv.
+
+ The same recipe ``install_model`` runs (the catalog's ``--no-deps``
+ flags preserved — the Qwen3-TTS companions must not replace the pinned
+ Transformers 5 stack), limited to what the import probe found absent,
+ so a start-time heal touches as little of the pinned environment as
+ possible. Returns the first failing exit code, 0 when all present."""
+ for spec, no_deps in missing_companions(entry):
+ args = ["--no-deps"] if no_deps else None
+ rc = common.pip_install([spec], emit=emit, cancel=cancel,
+ env_dir=SGLOMNI_ENV, extra_args=args)
+ if rc != 0:
+ print(f"[ERROR] pip install {spec} failed (exit {rc}); "
+ f"install it into {SGLOMNI_ENV} manually")
+ return rc
+ return 0
+
+
def install_model(key: str, *, emit=None, cancel=None) -> int:
"""Install a catalog model: companion packages, then its weights.
@@ -157,7 +194,7 @@ def install_model(key: str, *, emit=None, cancel=None) -> int:
note = sg_status.gpu_fallback_note(entry)
if note:
print(f"[WARNING] {note}")
- for spec, no_deps in entry.extras:
+ for spec, no_deps in missing_companions(entry):
args = ["--no-deps"] if no_deps else None
rc = common.pip_install([spec], emit=emit, cancel=cancel,
env_dir=SGLOMNI_ENV, extra_args=args)