Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Roland Tannous
737017a511 fix(studio): lazy-import extract_model_size_b in llama_cpp to fix transformers 5.x version switch
PR #4769 (e4d14992) added a module-level `from utils.models import
extract_model_size_b` to llama_cpp.py.  Since core/inference/__init__.py
eagerly imports llama_cpp, the spawn subprocess now hits:

  core.inference.__init__  →  llama_cpp  →  utils.models  →
  model_config (line 8: `from transformers import AutoConfig`)

…before _activate_transformers_version() has a chance to prepend
.venv_t5/ to sys.path.  Python caches transformers 4.57.6 in
sys.modules, and no subsequent sys.path change can override it.

Fix: replace the eager import with a thin wrapper that defers the
import to first call.  This breaks the transitive chain so
transformers is not loaded until after version activation.
2026-04-02 21:42:56 +00:00

View file

@ -52,8 +52,15 @@ _REPROMPT_MAX_CHARS = 2000
_SHARD_FULL_RE = re.compile(r"^(.*)-(\d{5})-of-(\d{5})\.gguf$") _SHARD_FULL_RE = re.compile(r"^(.*)-(\d{5})-of-(\d{5})\.gguf$")
_SHARD_RE = re.compile(r"^(.*)-\d{5}-of-\d{5}\.gguf$") _SHARD_RE = re.compile(r"^(.*)-\d{5}-of-\d{5}\.gguf$")
# Model size extraction (shared with routes/inference.py) # Model size extraction — lazy import to avoid pulling in transformers
from utils.models import extract_model_size_b as _extract_model_size_b # at module level (utils.models.model_config imports AutoConfig).
# This module is imported by core/inference/__init__.py, which runs
# before the subprocess version-activation code, so an eager import
# here would cache transformers 4.x in sys.modules and break the
# 5.x version switch.
def _extract_model_size_b(model_id: str):
from utils.models import extract_model_size_b
return extract_model_size_b(model_id)
# ── Pre-compiled patterns for tool XML stripping ───────────── # ── Pre-compiled patterns for tool XML stripping ─────────────
_TOOL_CLOSED_PATS = [ _TOOL_CLOSED_PATS = [