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
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
"""Tests for :func:`utils.models.model_config.detect_mmproj_file` (#5347)."""
from __future__ import annotations
from pathlib import Path
import struct
import pytest
from utils.models.model_config import (
_detect_family_token,
detect_mmproj_file,
mmproj_matches_model_family,
)
_GGUF_MAGIC = 0x46554747
def _gguf_with_general(path: Path, fields: dict) -> Path:
"""Write a minimal GGUF with string and unsigned integer KVs."""
body = b""
for k, v in fields.items():
kb = k.encode("utf-8")
body += struct.pack("<Q", len(kb)) + kb
if isinstance(v, list):
body += struct.pack("<IIQ", 9, 7, len(v)) + bytes(v)
elif isinstance(v, int):
body += struct.pack("<II", 4, v)
else:
vb = v.encode("utf-8")
body += struct.pack("<I", 8)
body += struct.pack("<Q", len(vb)) + vb
header = struct.pack("<IIQQ", _GGUF_MAGIC, 3, 0, len(fields))
path.parent.mkdir(parents = True, exist_ok = True)
path.write_bytes(header + body)
return path
def _touch(path: Path) -> Path:
"""Headerless GGUF stub, non-empty since zero bytes now means an interrupted download."""
path.parent.mkdir(parents = True, exist_ok = True)
path.write_bytes(b"\0" * 32)
return path
def test_returns_none_when_no_mmproj(tmp_path: Path):
model = _touch(tmp_path / "Qwen3.5-9B-Q4_K_M.gguf")
assert detect_mmproj_file(str(model)) is None
def test_single_matching_family_mmproj_picked(tmp_path: Path):
"""Single same-family projector is returned (historical behaviour)."""
model = _touch(tmp_path / "Qwen3.5-9B-Q4_K_M.gguf")
mmproj = _touch(tmp_path / "Qwen3.5-9B-BF16-mmproj.gguf")
assert detect_mmproj_file(str(model)) == str(mmproj.resolve())
def test_hf_style_unprefixed_mmproj_still_works(tmp_path: Path):
"""HF convention: weight + ``mmproj-F16.gguf`` sibling."""
model = _touch(tmp_path / "model.gguf")
mmproj = _touch(tmp_path / "mmproj-F16.gguf")
assert detect_mmproj_file(str(model)) == str(mmproj.resolve())
def test_blocks_single_cross_family_projector(tmp_path: Path):
"""#5347 core: Qwen weight + lone Gemma mmproj returns None."""
model = _touch(tmp_path / "Qwen3.5-9B-Q4_K_M.gguf")
_touch(tmp_path / "gemma-4-26B-A4B-it.mmproj-q8_0.gguf")
assert detect_mmproj_file(str(model)) is None
def test_picks_matching_family_among_mixed_candidates(tmp_path: Path):
"""Mixed Qwen + Gemma projectors: pick Qwen, drop Gemma."""
model = _touch(tmp_path / "Qwen3.5-9B-Q4_K_M.gguf")
qwen_mm = _touch(tmp_path / "Qwen3.5-9B-BF16-mmproj.gguf")
_touch(tmp_path / "gemma-4-26B-A4B-it.mmproj-q8_0.gguf")
assert detect_mmproj_file(str(model)) == str(qwen_mm.resolve())
def test_prefers_longest_prefix_within_same_family(tmp_path: Path):
"""Same family, different sizes: longest shared stem prefix wins."""
model = _touch(tmp_path / "Qwen3.5-35B-A3B-UD-Q4_K_L.gguf")
_touch(tmp_path / "Qwen3.5-9B-BF16-mmproj.gguf")
big_mm = _touch(tmp_path / "Qwen3.5-35B-A3B-BF16-mmproj.gguf")
assert detect_mmproj_file(str(model)) == str(big_mm.resolve())
def test_unrecognised_family_does_not_break_detection(tmp_path: Path):
"""Unknown model family must not return None on a sole candidate."""
model = _touch(tmp_path / "MyCustomBrand-7B-Q4_K_M.gguf")
mmproj = _touch(tmp_path / "MyCustomBrand-7B-BF16-mmproj.gguf")
assert detect_mmproj_file(str(model)) == str(mmproj.resolve())
def test_directory_path_returns_first_candidate(tmp_path: Path):
"""Directory path: no model stem to compare; legacy first-candidate."""
_touch(tmp_path / "Qwen3.5-9B-BF16-mmproj.gguf")
_touch(tmp_path / "gemma-4-26B-A4B-it.mmproj-q8_0.gguf")
result = detect_mmproj_file(str(tmp_path))
assert result is not None
assert "mmproj" in Path(result).name.lower()
def test_search_root_walk_still_works(tmp_path: Path):
"""Snapshot layout: weight in quant subdir, mmproj at snapshot root."""
snapshot = tmp_path / "snapshot"
weight = _touch(snapshot / "BF16" / "Qwen3.5-9B-BF16.gguf")
mmproj = _touch(snapshot / "Qwen3.5-9B-BF16-mmproj.gguf")
result = detect_mmproj_file(str(weight), search_root = str(snapshot))
assert result == str(mmproj.resolve())
def test_family_token_phi_does_not_match_sapphire():
"""``phi`` substring inside ``sapphire`` must not tag Phi."""
assert _detect_family_token("sapphire-7b-q4_k_m.gguf") is None
def test_family_token_yi_does_not_match_tinyish_names():
"""``yi`` must not cross letter boundaries (``yip``)."""
assert _detect_family_token("yip-7b.gguf") is None
assert _detect_family_token("yi-vl-6b.gguf") == "yi"
def test_family_token_mimo_does_not_match_mimosa():
"""``mimo`` must not tag ``mimosa``."""
assert _detect_family_token("mimosa-rosa-7b.gguf") is None
assert _detect_family_token("MiMo-VL-7B-RL-BF16.gguf") == "mimo"
def test_family_token_mistral_does_not_match_ministral():
"""Pin Mistral-derivative tagging."""
assert _detect_family_token("Ministral-3-8B-Instruct-2512-BF16.gguf") == "ministral"
assert _detect_family_token("Mistral-7B-Instruct-v0.3.gguf") == "mistral"
assert _detect_family_token("Magistral-Small-2506-BF16.gguf") == "magistral"
assert _detect_family_token("Devstral-Small-2-24B-Instruct-2512-BF16.gguf") == "devstral"
def test_family_token_picks_leftmost_when_multiple_present():
"""Leftmost family token wins, not tuple order."""
assert _detect_family_token("llama-phi-merge.gguf") == "llama"
assert _detect_family_token("phi-llama-merge.gguf") == "phi"
assert _detect_family_token("llama3-3b-instruct.gguf") == "llama"
def test_family_token_new_families_recognised():
"""Catalogue-audit additions tag correctly."""
assert _detect_family_token("NVIDIA-Nemotron-3-Nano-Omni-30B.gguf") == "nemotron"
assert _detect_family_token("Kimi-K2.6-BF16.gguf") == "kimi"
assert _detect_family_token("Nanonets-OCR-s-BF16.gguf") == "nanonets"
assert _detect_family_token("Cosmos-Reason1-7B-BF16.gguf") == "cosmos"
assert _detect_family_token("Apriel-1.5-15b-Thinker-BF16.gguf") == "apriel"
assert _detect_family_token("LFM2.5-VL-1.6B-BF16.gguf") == "lfm"
def test_blocks_cross_family_for_new_token_pair(tmp_path: Path):
"""Nemotron weight + lone Gemma projector returns None."""
model = _touch(tmp_path / "NVIDIA-Nemotron-3-Nano-Omni-30B-A3B-Reasoning-MXFP4_MOE.gguf")
_touch(tmp_path / "gemma-4-26B-A4B-it.mmproj-q8_0.gguf")
assert detect_mmproj_file(str(model)) is None
def test_picks_devstral_mmproj_in_mixed_dir(tmp_path: Path):
"""Devstral weight + Devstral mmproj + a Qwen mmproj: pick Devstral."""
model = _touch(tmp_path / "Devstral-Small-2-24B-Instruct-2512-BF16.gguf")
dev_mm = _touch(tmp_path / "Devstral-Small-2-mmproj-bf16.gguf")
_touch(tmp_path / "Qwen3.5-9B-BF16-mmproj.gguf")
assert detect_mmproj_file(str(model)) == str(dev_mm.resolve())
def test_mmproj_family_guard_blocks_cross_family():
assert (
mmproj_matches_model_family(
"/models/Qwen3.5-9B-Q4_K_M.gguf",
"/models/gemma-4-26B-A4B-it.mmproj-q8_0.gguf",
)
is False
)
def test_mmproj_family_guard_allows_same_family():
assert (
mmproj_matches_model_family(
"/models/Qwen3.5-9B-Q4_K_M.gguf",
"/models/Qwen3.5-9B-BF16-mmproj.gguf",
)
is True
)
def test_mmproj_family_guard_allows_generic_hf_mmproj():
"""No family token on the projector: wildcard."""
assert (
mmproj_matches_model_family(
"/models/Qwen3.5-9B-Q4_K_M.gguf",
"/models/mmproj-F16.gguf",
)
is True
)
def test_mmproj_family_guard_allows_unrecognised_model_family():
"""No family token on the model: wildcard."""
assert (
mmproj_matches_model_family(
"/models/Apriel-1.5-15b-Thinker-BF16.gguf",
"/models/mmproj-F16.gguf",
)
is True
)
def test_metadata_url_match_picked_over_filename_lookalike(tmp_path: Path):
"""URL match beats a longer-prefix sibling."""
weight = _gguf_with_general(
tmp_path / "Qwen3.5-9B-Q4_K_M.gguf",
{
"general.architecture": "qwen2vl",
"general.type": "model",
"general.basename": "Qwen3.5",
"general.base_model.0.repo_url": "https://huggingface.co/Qwen/Qwen3.5-9B",
},
)
_gguf_with_general(
tmp_path / "Qwen3.5-9B-mmproj-bf16.gguf",
{
"general.architecture": "clip",
"general.type": "mmproj",
"general.basename": "Qwen3.5",
"general.base_model.0.repo_url": "https://huggingface.co/Qwen/Qwen3.5-1.5B",
},
)
correct = _gguf_with_general(
tmp_path / "mmproj-BF16.gguf",
{
"general.architecture": "clip",
"general.type": "mmproj",
"general.basename": "Qwen3.5",
"general.base_model.0.repo_url": "https://huggingface.co/Qwen/Qwen3.5-9B",
},
)
assert detect_mmproj_file(str(weight)) == str(correct.resolve())
def test_metadata_url_mismatch_dropped(tmp_path: Path):
"""Filenames match family but metadata disagrees: returns None."""
weight = _gguf_with_general(
tmp_path / "qwen-9b.gguf",
{
"general.architecture": "qwen2vl",
"general.type": "model",
"general.base_model.0.repo_url": "https://huggingface.co/Qwen/Qwen3.5-9B",
},
)
_gguf_with_general(
tmp_path / "qwen-9b-mmproj.gguf",
{
"general.architecture": "clip",
"general.type": "mmproj",
"general.base_model.0.repo_url": "https://huggingface.co/google/gemma-3-9B",
},
)
assert detect_mmproj_file(str(weight)) is None
def test_metadata_url_derivative_repack_accepts_base_mmproj(tmp_path: Path):
"""#6305: LM Studio repack/derivative GGUF + base-projector is valid."""
weight = _gguf_with_general(
tmp_path / "gemma-4-26B-A4B-it-qat-q4_0-uncensored-heretic-Q4_0.gguf",
{
"general.architecture": "gemma4",
"general.type": "model",
"general.basename": "gemma-4-26B-A4B-it",
"general.base_model.0.repo_url": (
"https://huggingface.co/lmstudio-community/gemma-4-26B-A4B-it-GGUF"
),
},
)
mmproj = _gguf_with_general(
tmp_path / "mmproj-F16.gguf",
{
"general.architecture": "clip",
"general.type": "mmproj",
"general.basename": "gemma-4-26B-A4B-it",
"general.base_model.0.repo_url": "https://huggingface.co/google/gemma-4-26B-A4B-it",
},
)
assert detect_mmproj_file(str(weight)) == str(mmproj.resolve())
def test_metadata_identifies_mmproj_without_filename_hint(tmp_path: Path):
"""Projector named ``vision-projector.gguf`` discovered via header."""
weight = _gguf_with_general(
tmp_path / "Qwen3.5-9B.gguf",
{
"general.architecture": "qwen2vl",
"general.type": "model",
"general.basename": "Qwen3.5",
"general.base_model.0.repo_url": "https://huggingface.co/Qwen/Qwen3.5-9B",
},
)
projector = _gguf_with_general(
tmp_path / "vision-projector.gguf",
{
"general.architecture": "clip",
"general.type": "mmproj",
"general.basename": "Qwen3.5",
"general.base_model.0.repo_url": "https://huggingface.co/Qwen/Qwen3.5-9B",
},
)
assert detect_mmproj_file(str(weight)) == str(projector.resolve())
def test_metadata_score_outranks_filename_prefix(tmp_path: Path):
"""Score 100 (URL match) beats score 0 (long filename prefix)."""
weight = _gguf_with_general(
tmp_path / "Qwen3.5-9B-Q4_K_M.gguf",
{
"general.architecture": "qwen2vl",
"general.type": "model",
"general.basename": "Qwen3.5",
"general.base_model.0.repo_url": "https://huggingface.co/Qwen/Qwen3.5-9B",
},
)
_touch(tmp_path / "Qwen3.5-9B-Q4_K_M-mmproj.gguf")
correct = _gguf_with_general(
tmp_path / "mmproj-BF16.gguf",
{
"general.architecture": "clip",
"general.type": "mmproj",
"general.base_model.0.repo_url": "https://huggingface.co/Qwen/Qwen3.5-9B",
},
)
assert detect_mmproj_file(str(weight)) == str(correct.resolve())
def test_a_zero_byte_projector_is_not_offered_to_the_loader(tmp_path: Path):
"""llama-server cannot open an interrupted download, and the inventory already reports such
a row text-only, so handing the path over would fail the whole load."""
weight = _touch(tmp_path / "Model-Q4_K_M.gguf")
(tmp_path / "mmproj-F16.gguf").write_bytes(b"")
assert detect_mmproj_file(str(weight)) is None
assert detect_mmproj_file(str(tmp_path)) is None
def test_a_zero_byte_projector_does_not_shadow_a_whole_one(tmp_path: Path):
"""Control: only the empty one is skipped, so a projector beside it is still found."""
weight = _touch(tmp_path / "Model-Q4_K_M.gguf")
(tmp_path / "mmproj-F16.gguf").write_bytes(b"")
whole = _touch(tmp_path / "mmproj-Q8_0.gguf")
assert detect_mmproj_file(str(weight)) == str(whole.resolve())
def test_trusted_companion_snapshot_finds_nested_projector(tmp_path: Path):
weights = tmp_path / "weights"
sibling = tmp_path / "companion"
weights.mkdir()
(sibling / "vision").mkdir(parents = True)
weight = _touch(weights / "Model-Q4_K_M.gguf")
projector = _touch(sibling / "vision" / "mmproj-Model-F16.gguf")
assert detect_mmproj_file(str(weight), search_root = str(sibling)) is None
assert detect_mmproj_file(
str(weight), search_root = str(sibling), allow_disjoint_search_root = True
) == str(projector.resolve())
def test_a_containing_trusted_root_does_not_recurse_into_a_sibling_quant(tmp_path: Path):
"""Root widening must not enter sibling quants, or a foreign projector wins the tie."""
snapshot = tmp_path / "snapshots" / "rev"
weight = _touch(snapshot / "UD-Q4_K_XL" / "Qwen3-VL-235B-UD-Q4_K_XL.gguf")
mine = _touch(snapshot / "UD-Q4_K_XL" / "mmproj-UD-Q4_K_XL.gguf")
_touch(snapshot / "UD-IQ1_S" / "Qwen3-VL-235B-UD-IQ1_S.gguf")
_touch(snapshot / "UD-IQ1_S" / "mmproj-UD-IQ1_S.gguf")
assert detect_mmproj_file(
str(weight), search_root = str(snapshot), allow_disjoint_search_root = True
) == str(mine.resolve())
def test_a_containing_trusted_root_keeps_its_own_root_level_projector(tmp_path: Path):
"""Ancestor walk must reach root-level projectors; foreign quants must not win on prefix."""
snapshot = tmp_path / "snapshots" / "rev"
weight = _touch(snapshot / "UD-Q4_K_XL" / "vision-model-UD-Q4_K_XL.gguf")
root_level = _touch(snapshot / "mmproj-F16.gguf")
_touch(snapshot / "UD-IQ1_S" / "mmproj-vision-model-UD-Q4_K_XL-F16.gguf")
assert detect_mmproj_file(
str(weight), search_root = str(snapshot), allow_disjoint_search_root = True
) == str(root_level.resolve())
def test_finds_the_projector_hermes_stages_under_assets(tmp_path: Path):
"""Hermes keeps a download's mmproj in models/assets/ so its router never lists it as a
model; the weight sits one level up. A sibling-only walk loads Qwen3.8-27B text-only."""
model = _touch(tmp_path / "Qwen3.8-27B-UD-Q4_K_M.gguf")
mmproj = _touch(tmp_path / "assets" / "mmproj-Qwen3.8-27B-BF16.gguf")
assert detect_mmproj_file(str(model)) == str(mmproj.resolve())
def test_assets_holding_several_projectors_still_pairs_by_family(tmp_path: Path):
"""Shared assets/ holds many families' projectors; the family gate picks the right one."""
model = _touch(tmp_path / "gemma-4-26B-A4B-it-UD-Q4_K_M.gguf")
_touch(tmp_path / "assets" / "mmproj-Qwen3.8-27B-BF16.gguf")
gemma = _touch(tmp_path / "assets" / "mmproj-gemma-4-26B-A4B-it-BF16.gguf")
assert detect_mmproj_file(str(model)) == str(gemma.resolve())
def test_assets_holding_two_same_family_projectors_pairs_by_name(tmp_path: Path):
"""Without header metadata, same-family projectors survive the gate, so the name tie-break must
skip the mmproj- marker; raw stems tie and the shorter, wrong name wins."""
model = _touch(tmp_path / "Qwen3.6-35B-A3B-UD-Q4_K_M.gguf")
_touch(tmp_path / "assets" / "mmproj-Qwen3.8-27B-BF16.gguf")
mine = _touch(tmp_path / "assets" / "mmproj-Qwen3.6-35B-A3B-BF16.gguf")
assert detect_mmproj_file(str(model)) == str(mine.resolve())
def test_a_draft_model_under_assets_is_not_mistaken_for_a_projector(tmp_path: Path):
model = _touch(tmp_path / "Qwen3.8-27B-UD-Q4_K_M.gguf")
_touch(tmp_path / "assets" / "Qwen3.8-0.8B-draft-Q4_K_M.gguf")
assert detect_mmproj_file(str(model)) is None
@pytest.mark.parametrize("projection_dim", [5376, 2560, 0])
@pytest.mark.parametrize("identity_matches", [False, True])
def test_gemma4_finetune_pairs_by_functional_metadata(tmp_path, projection_dim, identity_matches):
model = _gguf_with_general(
tmp_path / "gembrain.gguf",
{
"general.architecture": "gemma4",
"general.basename": "Gemma-4" if identity_matches else "Gemma-4-Gembrain",
"general.base_model.0.repo_url": (
"https://huggingface.co/google/gemma-4-31B-it"
if identity_matches
else "https://huggingface.co/community/Gembrain"
),
"gemma4.embedding_length": 5376,
},
)
projector = _gguf_with_general(
tmp_path / "mmproj-gemma-4-31B-it-BF16.gguf",
{
"general.architecture": "clip",
"general.type": "mmproj",
"general.basename": "Gemma-4",
"general.base_model.0.repo_url": "https://huggingface.co/google/gemma-4-31B-it",
"clip.vision.projector_type": "gemma4v",
"clip.vision.projection_dim": projection_dim,
},
)
expected = (
str(projector)
if projection_dim == 5376 or (projection_dim == 0 and identity_matches)
else None
)
assert detect_mmproj_file(str(model)) == expected
if projection_dim:
assert mmproj_matches_model_family(str(model), str(projector)) == (projection_dim == 5376)
@pytest.mark.parametrize("arch", ["qwen35", "qwen35moe"])
@pytest.mark.parametrize(
"projection_dim, deepstack, paired",
[(2048, [False, False], True), (1024, [False, False], False), (2048, [False, True], False)],
)
def test_qwen35_projector_from_another_quantizer_pairs_by_function(
tmp_path, arch, projection_dim, deepstack, paired
):
"""#6305: an LM Studio Qwen3.6 weight next to Unsloth's projector; Qwen3-VL's deepstack one stays out."""
model = _gguf_with_general(
tmp_path / "Qwen3.6-35B-A3B-Q4_K_M.gguf",
{
"general.architecture": arch,
"general.basename": "Qwen_Qwen3.6",
f"{arch}.embedding_length": 2048,
},
)
projector = _gguf_with_general(
tmp_path / "mmproj-F16.gguf",
{
"general.architecture": "clip",
"general.type": "mmproj",
"general.basename": "Qwen3.6-35B-A3B",
"general.base_model.0.repo_url": "https://huggingface.co/Qwen/Qwen3.6-35B-A3B",
"clip.projector_type": "qwen3vl_merger",
"clip.vision.projection_dim": projection_dim,
"clip.vision.is_deepstack_layers": deepstack,
},
)
assert detect_mmproj_file(str(model)) == (str(projector.resolve()) if paired else None)
assert mmproj_matches_model_family(str(model), str(projector)) == paired
@pytest.mark.parametrize("weight_name", ["Qwen_Qwen3.5 35B A3B", "Qwen3.5 Uncensored"])
def test_qwen35_same_width_projector_of_another_size_is_not_picked(tmp_path, weight_name):
"""Qwen3.5 2B and 35B-A3B share width 2048, not vision towers; bartowski-style names tie otherwise."""
model = _gguf_with_general(
tmp_path / "Qwen3.5-35B-A3B-Q4_K_M.gguf",
{
"general.architecture": "qwen35moe",
"general.name": weight_name,
"general.basename": "Qwen_Qwen3.5",
"qwen35moe.embedding_length": 2048,
},
)
projectors = {}
for size in ("2B", "35B-A3B"):
projectors[size] = _gguf_with_general(
tmp_path / f"mmproj-Qwen_Qwen3.5-{size}-bf16.gguf",
{
"general.architecture": "clip",
"general.type": "mmproj",
"general.name": f"Qwen3.5 {size.replace('-', ' ')}",
"general.basename": "Qwen3.5",
"clip.projector_type": "qwen3vl_merger",
"clip.vision.projection_dim": 2048,
"clip.vision.is_deepstack_layers": [False, False],
},
)
assert detect_mmproj_file(str(model)) == str(projectors["35B-A3B"].resolve())
def test_size_names_do_not_override_an_exact_repo_match(tmp_path):
"""Converters name MoE sizes differently; the shared base_model URL is authoritative."""
url = "https://huggingface.co/Qwen/Qwen3.6-35B-A3B"
model = _gguf_with_general(
tmp_path / "Qwen3.6-35B-A3B-Q4_K_M.gguf",
{
"general.architecture": "qwen35moe",
"general.name": "Qwen3.6 35B",
"general.base_model.0.repo_url": url,
"qwen35moe.embedding_length": 2048,
},
)
projector = _gguf_with_general(
tmp_path / "mmproj-F16.gguf",
{
"general.architecture": "clip",
"general.type": "mmproj",
"general.name": "Qwen3.6 A3B",
"general.base_model.0.repo_url": url,
"clip.projector_type": "qwen3vl_merger",
"clip.vision.projection_dim": 2048,
"clip.vision.is_deepstack_layers": [False, False],
},
)
assert detect_mmproj_file(str(model)) == str(projector.resolve())
def test_mmproj_rejection_names_mismatched_fields(tmp_path, capsys):
model = _gguf_with_general(tmp_path / "model.gguf", {"general.basename": "Foo"})
_gguf_with_general(tmp_path / "mmproj.gguf", {"general.basename": "Bar"})
assert detect_mmproj_file(str(model)) is None
output = capsys.readouterr().out
assert "general.basename" in output
assert "Foo" in output and "Bar" in output
@pytest.mark.parametrize("projection_dim", [None, 3840, 4096])
def test_hf_repo_case_mismatch_keeps_compatible_projector(tmp_path, projection_dim):
"""#6305: repo URL casing must not reject a projector without dimension metadata."""
model = _gguf_with_general(
tmp_path / "gemma-4-12b-it-Q4_K_M.gguf",
{
"general.architecture": "gemma4",
"general.base_model.0.repo_url": "https://huggingface.co/google/gemma-4-12B-it",
"gemma4.embedding_length": 3840,
},
)
fields = {
"general.architecture": "clip",
"general.type": "mmproj",
"general.base_model.0.repo_url": "https://huggingface.co/google/gemma-4-12b-it",
}
if projection_dim is not None:
fields.update(
{"clip.vision.projector_type": "gemma4v", "clip.vision.projection_dim": projection_dim}
)
projector = _gguf_with_general(tmp_path / "mmproj-F16.gguf", fields)
expected = None if projection_dim == 4096 else str(projector.resolve())
assert detect_mmproj_file(str(model)) == expected