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.

Studio: resolve repo-relative image paths in the simple image+text VLM converter (#11897)

breken52b822c79809
diff --git a/studio/backend/tests/test_vlm_repo_relative_image_paths.py b/studio/backend/tests/test_vlm_repo_relative_image_paths.py
new file mode 100644
index 00000000000..b1faba1be27
--- /dev/null
+++ b/studio/backend/tests/test_vlm_repo_relative_image_paths.py
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+from datasets import Dataset
+from PIL import Image
+
+from utils.datasets import format_conversion
+
+
+def _fake_hub(monkeypatch, tmp_path, repo_files):
+ local = tmp_path / "a.png"
+ Image.new("RGB", (4, 4)).save(local)
+ fetched = []
+
+ def _download(repo_id, filename, **kwargs):
+ fetched.append(filename)
+ return str(local)
+
+ # String targets resolve the live sys.modules entry, which a sibling test may have replaced.
+ monkeypatch.setattr(
+ "huggingface_hub.HfApi.list_repo_files", lambda self, *a, **k: list(repo_files)
+ )
+ monkeypatch.setattr("huggingface_hub.hf_hub_download", _download)
+ # The all-failed path asks the helper model for a friendlier message; keep it offline.
+ from utils.datasets import llm_assist
+
+ monkeypatch.setattr(llm_assist, "llm_generate_dataset_warning", lambda *a, **k: None)
+ return fetched
+
+
+def test_simple_image_text_resolves_a_repo_relative_image_path(monkeypatch, tmp_path):
+ # convert_sharegpt_with_images_to_vlm_format keys its lookup by the full relative path too;
+ # the simple {image, text} converter has to resolve the same "images/a.png" value.
+ fetched = _fake_hub(monkeypatch, tmp_path, ["README.md", "images/a.png"])
+ ds = Dataset.from_dict({"image": ["images/a.png"], "text": ["a cat"]})
+
+ out = format_conversion.convert_to_vlm_format(
+ ds, instruction = "Describe.", dataset_name = "org/ds"
+ )
+
+ assert fetched == ["images/a.png"]
+ assert len(out) == 1
+ image = next(
+ part["image"] for part in out[0]["messages"][0]["content"] if part.get("type") == "image"
+ )
+ assert image.size == (4, 4)
+
+
+def test_simple_image_text_still_resolves_a_bare_filename(monkeypatch, tmp_path):
+ fetched = _fake_hub(monkeypatch, tmp_path, ["images/a.png"])
+ ds = Dataset.from_dict({"image": ["a.png"], "text": ["a cat"]})
+
+ out = format_conversion.convert_to_vlm_format(
+ ds, instruction = "Describe.", dataset_name = "org/ds"
+ )
+
+ assert fetched == ["images/a.png"]
+ assert len(out) == 1
diff --git a/studio/backend/utils/datasets/format_conversion.py b/studio/backend/utils/datasets/format_conversion.py
index b0b165d3195..a315a53805a 100644
--- a/studio/backend/utils/datasets/format_conversion.py
+++ b/studio/backend/utils/datasets/format_conversion.py
@@ -491,6 +491,10 @@ def convert_to_vlm_format(
for f in repo_files
if any(f.lower().endswith(ext) for ext in _IMAGE_EXTS)
}
+ # Also key by the full relative path, e.g. "images/0001.jpg", as the ShareGPT converter does.
+ for f in repo_files:
+ if any(f.lower().endswith(ext) for ext in _IMAGE_EXTS):
+ _image_lookup[f] = f
if first_image in _image_lookup:
logger.info(
f"✅ Matched {len(_image_lookup)} image files in repo (e.g. '{first_image}' → '{_image_lookup[first_image]}')"