Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions studio/backend/tests/test_vision_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ def test_subprocess_called_once_with_cache(self, mock_needs_t5, mock_subprocess)
mock_subprocess.assert_called_once()
assert _vision_detection_cache[("unsloth/Qwen3.5-2B", None)] is True

@patch("utils.models.model_config._raw_config_has_vision_config", return_value = True)
@patch("utils.models.model_config._is_vision_model_subprocess", return_value = None)
@patch("utils.transformers_version.needs_transformers_5", return_value = True)
def test_subprocess_none_falls_back_to_raw_vision_config(
self, mock_needs_t5, mock_subprocess, mock_raw_config
):
assert is_vision_model("unsloth/gemma-4-E4B-it") is True
assert is_vision_model("unsloth/gemma-4-E4B-it") is True

mock_subprocess.assert_called_once()
mock_raw_config.assert_called_once_with("unsloth/gemma-4-E4B-it", hf_token = None)


# ---------------------------------------------------------------------------
# Exception handling — cache the False fallback
Expand Down Expand Up @@ -223,6 +235,20 @@ def test_vision_config_attr_detected_and_cached(
assert is_vision_model("Qwen/Qwen2-VL-7B") is True
mock_load_config.assert_called_once()

@patch("utils.transformers_version.needs_transformers_5", return_value = False)
@patch("utils.models.model_config.load_model_config")
def test_model_type_prefix_detected_and_cached(
self, mock_load_config, mock_needs_t5
):
cfg = MagicMock(spec = [])
cfg.model_type = "gemma4audio"
cfg.architectures = ["Gemma4AudioForCausalLM"]
mock_load_config.return_value = cfg

assert is_vision_model("google/gemma-4-audio") is True
assert is_vision_model("google/gemma-4-audio") is True
mock_load_config.assert_called_once()

@patch("utils.transformers_version.needs_transformers_5", return_value = False)
@patch("utils.models.model_config.load_model_config")
def test_audio_model_excluded_and_cached(self, mock_load_config, mock_needs_t5):
Expand Down
4 changes: 3 additions & 1 deletion studio/backend/utils/models/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,9 @@ def load_model_config(

# Pre-computed .venv_t5 paths and backend dir for subprocess version switching.
# Vision check uses 5.5.0 (newest, recognizes all architectures).
_VENV_T5_DIR = str(Path.home() / ".unsloth" / "studio" / ".venv_t5_550")
from utils.paths.storage_roots import studio_root as _studio_root # noqa: E402

_VENV_T5_DIR = str(_studio_root() / ".venv_t5_550")
_BACKEND_DIR = str(Path(__file__).resolve().parent.parent.parent)

# Inline script executed in a subprocess with transformers 5.x activated.
Expand Down
Loading