Skip to content

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.

Fix case-sensitive Hugging Face projector pairing (#13161)

Lee Jackson4e7615916745
diff --git a/studio/backend/tests/test_detect_mmproj_file.py b/studio/backend/tests/test_detect_mmproj_file.py
index 2b84ac16c9e..fb440c9271d 100644
--- a/studio/backend/tests/test_detect_mmproj_file.py
+++ b/studio/backend/tests/test_detect_mmproj_file.py
@@ -498,3 +498,28 @@ def test_mmproj_rejection_names_mismatched_fields(tmp_path, capsys):
output = capsys.readouterr().out
assert "general.basename" in output
assert "Foo" in output and "Bar" in output
+
+
[email protected]("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
diff --git a/studio/backend/tests/test_gguf_metadata.py b/studio/backend/tests/test_gguf_metadata.py
index d7e6d4cb7f7..db1dff0ae8f 100644
--- a/studio/backend/tests/test_gguf_metadata.py
+++ b/studio/backend/tests/test_gguf_metadata.py
@@ -562,6 +562,60 @@ def test_pairing_score_rejects_qualifier_without_separator():
assert pairing_score(weight, mmproj) == -1
+ "left,right",
+ [
+ (
+ "https://huggingface.co/google/gemma-4-12B-it",
+ "https://huggingface.co/google/gemma-4-12b-it",
+ ),
+ (
+ "HTTPS://HUGGINGFACE.CO/Google/Gemma-4-12B-it.git/",
+ "http://huggingface.co/google/gemma-4-12b-it",
+ ),
+ ("https://huggingface.co/Google/Gemma-4-12B-it", "google/gemma-4-12b-it"),
+ ("Google/Gemma-4-12B-it", "https://huggingface.co/google/gemma-4-12b-it"),
+ ],
+)
+def test_pairing_score_hf_repo_case_insensitive(left, right):
+ key = "general.base_model.0.repo_url"
+ assert pairing_score({key: left}, {key: right}) == 100
+
+
[email protected]("host", ["huggingface.co", "huggingface.co.example.com"])
+def test_pairing_score_rejects_distinct_hf_repositories(host):
+ key = "general.base_model.0.repo_url"
+ assert (
+ pairing_score(
+ {key: f"https://{host}/google/gemma-4-12B-it"},
+ {key: f"https://{host}/google/gemma-4-27b-it"},
+ )
+ == -1
+ )
+
+
+def test_pairing_score_preserves_case_on_hf_lookalike_host():
+ key = "general.base_model.0.repo_url"
+ assert (
+ pairing_score(
+ {key: "https://huggingface.co.example.com/Google/Model"},
+ {key: "https://huggingface.co.example.com/google/model"},
+ )
+ == -1
+ )
+
+
+def test_pairing_score_preserves_case_in_hf_file_paths():
+ key = "general.base_model.0.repo_url"
+ assert (
+ pairing_score(
+ {key: "https://huggingface.co/google/model/blob/main/Config.json"},
+ {key: "https://huggingface.co/google/model/blob/main/config.json"},
+ )
+ == -1
+ )
+
+
def test_pairing_score_preserves_case_sensitive_repo_paths():
weight = {
"general.base_model.0.repo_url": "https://git.example.com/Org/Model",
diff --git a/studio/backend/utils/models/gguf_metadata.py b/studio/backend/utils/models/gguf_metadata.py
index 0eaa07ab37e..d472d639b6c 100644
--- a/studio/backend/utils/models/gguf_metadata.py
+++ b/studio/backend/utils/models/gguf_metadata.py
@@ -945,7 +945,11 @@ def _normalize_url(url: str) -> Optional[str]:
if not has_url_host:
return value
host, separator, path = value.partition("/")
- return host.lower() + (separator + path if separator else "")
+ host = host.lower()
+ # Hugging Face owner/repo IDs are case-insensitive, but arbitrary host, file, and revision paths are not.
+ if host == "huggingface.co" and len(path.split("/")) == 2:
+ path = path.casefold()
+ return host + (separator + path if separator else "")
def _repo_path_from_url(url: str) -> Optional[str]:
@@ -970,7 +974,13 @@ def _same_repo_reference(left: str, right: str) -> bool:
return False
hosted = left_normalized if left_is_url else right_normalized
host, _, _ = hosted.partition("/")
- return host == "huggingface.co" and _repo_path_from_url(left) == _repo_path_from_url(right)
+ if host != "huggingface.co":
+ return False
+ left_path = _repo_path_from_url(left)
+ right_path = _repo_path_from_url(right)
+ if left_path and right_path and len(left_path.split("/")) == len(right_path.split("/")) == 2:
+ return left_path.casefold() == right_path.casefold()
+ return left_path == right_path
def _hf_repo_slug_from_url(url: str) -> Optional[str]: