Skip to content

Studio: read a remote image URL on safetensors and MLX models instead of ignoring it - #12243

Merged
Lyxot merged 13 commits into
unslothai:mainfrom
NilayYadav:fetch-remote-images-non-gguf
Sep 29, 2026
Merged

Lyxot merged 13 commits into
unslothai:mainfrom
NilayYadav:fetch-remote-images-non-gguf

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

When a safetensors or MLX vision model was loaded (for example your own vision fine-tune, or any MLX model on a Mac) and an API client sent the usual OpenAI vision request with an https image URL, Studio quietly dropped the picture. The request came back 200 and the model answered as if nothing was attached, so captioning or OCR scripts got made-up answers with no error. GGUF models already fetch these URLs since #11160.

Now the non-GGUF chat path fetches the image the same safe way the GGUF path does and hands it to the model. If the image cannot be fetched, the request fails with the same 400 GGUF returns, and a text-only model says it cannot read images instead of answering without it.

As on GGUF, remote images in earlier turns are fetched too, so one URL that cannot be fetched fails the request. Requests that send the image inline as a data URL, and the chat UI, work as before.

This covers a model that is already loaded. A request that makes Studio switch to a safetensors or MLX model is still refused with "Remote image URLs are not supported" before the switch, as it is today.

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review + reproduction evidence

Pinned review: 0de02f90d9cfbd5312df68779c348c58abb660b8. 4 findings, fixed in e189696, 96ba686, dcc2b9c and 0de02f9. All are pushed to this branch, each with a test that fails on the commit before it.

I reproduced the API client flow (standard OpenAI vision body with an https image_url to /v1/chat/completions) on fresh upstream main and on this branch. Studio was installed with install.sh --local on Modal (L4, unsloth/Qwen2-VL-2B-Instruct, safetensors) and on an Apple Silicon Mac (MLX, mlx-community/SmolVLM-256M-Instruct-bf16), temperature 0:

  • main 501b15f: remote cat photo, safetensors: 200 "Dog", and the log says Dropping a remote image URL while flattening to text. MLX: 200 " The answer is: 100.". The same photo as a data URL: "cat" / " Cat.". An unreachable URL: 200 with a made-up answer. A text-only model with a remote URL: 200 with an empty reply.
  • This branch: remote cat photo: 200 "cat" (safetensors) and " Cat." (MLX). An unreachable URL: 400 Could not fetch the remote image URL. Send the image as a base64 data URL instead. A text-only model: 400 Image provided but current model is text-only. Load a vision model.

PR 12243 before/after

The API page shows the same request as 42 prompt tokens on main and 188 on this branch, so the image now reaches the model. The screenshot was taken at e189696; the later commits only change which images are fetched, and the same request still answers "cat" at 0de02f9.

  • Fixes on top of the original commit:
    • Single-image models now fetch only the image they actually read. As submitted, an old unreachable URL in history failed the request (404 URL earlier + data-URL cat now: main 200 "cat", submitted 400, now 200 "cat"), and nine history URLs hit the fetch cap (now 200 "cat").
    • On a multi-image (MLX) model only user-turn images are fetched. An unreachable image in an assistant turn went from 400 to 200.
    • Remote images in system or developer messages no longer trip the text-only refusal. A data URL there was already ignored.
    • A turn that a single-image model will refuse for having two images is refused before any fetch: with a slow first host, 10.4 s went to 0.4 s, same 400.
  • Security and limits (same fetcher as GGUF since #11160): https to 127.0.0.1, localhost, [::1], 169.254.169.254, 10.0.0.1, 2130706433, and an https redirect to 127.0.0.1 are all refused with a 400 in about 0.4 s, and http: and file: are refused by scheme. A 696 MB image is refused on its declared length in 0.5 s. A 10 s slow host ends in a 400 after 10.5 s, and a parallel text request still finished in 1.3 s.
  • Unchanged: data URL requests (what the chat UI sends), text-only requests, and GGUF. modal_tests: DISCRIMINATING, 5 new tests fail on main and pass here, 135 unchanged, 140 passed.

Automated review on the mirror NilayYadav#151 converged after 6 rounds. The last two rounds held only rejected items; details are in the next comment.
GitHub Actions A/B did not run: the fork's runners stayed queued for the whole review, and this PR's own checks are still queued, so there is no Actions result to report yet.

Conclusion: real bug, fixed. A remote image on a loaded safetensors or MLX model is now read instead of silently dropped, with the same fetch safeguards as GGUF. Before merge, CI still needs to finish. Open as a follow-up (unchanged from main, opt-in): with auto-switch on, a request that makes Studio switch to a safetensors or MLX model still gets Remote image URLs are not supported.

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex coverage

Mirror: NilayYadav#151, covering upstream head 0de02f90d9cfbd5312df68779c348c58abb660b8 (the mirror head has the same tree, 6befc9f).

Rounds: 6. Converged: rounds 5 and 6 held only rejected items (round 6 was a fresh review of the unchanged head).

  • Round 1 (aabdf3b), P1, fetch remote images before the non-GGUF auto-switch preflight: rejected. Auto-switch is off by default, that path returns the same Remote image URLs are not supported 400 as main, and the PR description scopes it out. Left as a follow-up.
  • Round 2 (e189696), P2, a multi-image model fetched images from every role although the renderer admits only user turns: fixed in 96ba686. On MLX, an unreachable image in an assistant turn went from 400 to 200.
  • Round 3 (96ba686), P2, a remote image in a system message tripped the text-only refusal: fixed in dcc2b9c. On Studio: 400 before, 200 after; the same message with a data URL was already 200.
  • Round 4 (dcc2b9c), P2, a two-image turn on a single-image model fetched before the certain refusal: fixed in 0de02f9. The same 400 now comes in 0.4 s instead of 10.4 s.
  • Round 5 (0de02f9), P2, a remote URL next to a payloadless data:image/png;base64, part on a multi-image model fetches before the 400: rejected. It needs an image part with no payload, the answer is still the correct 400, and the fetch is capped at 60 s and 10 MB.
  • Round 6 (0de02f9), P2, a remote URL repeated in the legacy image_base64 field is read as a second image: rejected. image_base64 is a base64 field, and main already answers this request with 400 Failed to decode image (run on main 501b15f); the branch answers 400 This model takes one image per message.

A seventh item came from my own review, not Codex: single-image models fetched every history image. It was fixed in e189696.

Final Codex result on 0de02f9: one inline suggestion (round 6), rejected above. No open accepted items.

…path

Two chat tests pinned the old behaviour, where a lone remote image URL on a safetensors model was dropped and the turn answered without it. One now uses a payloadless data URL to keep checking that a single unreadable part is not a multi-image call, and the other checks that an unfetchable URL is refused and closes the monitor row. Also cover a single-image model preferring the user's image over a newer assistant one.
On a single-image safetensors or MLX model, a turn with one remote image URL plus a distinct top-level image_base64 is refused as one image per message. The fetch ran first, so the caller waited on the image host and got the fetch error instead when the URL failed. Count the distinct legacy image in the pre-fetch check, as the refusal does.
The switch preflight treated a remote image as unreadable on a safetensors or MLX target: a remote-only request was refused with "Remote image URLs are not supported", and several remote images for a multi-image target were refused as one image per message. The chat path now fetches those URLs, so the same request was served by a resident model but refused when Unsloth Studio had to load it first. Drop the refusal and count https images as fetched when checking the target's image shape; a failed fetch is a 400 after the load, as on a GGUF target.
The chat fetcher now serves safetensors and MLX models too, so its log lines no longer name llama-server.
Route every case through one helper for the scripted safetensors backend and the fetch stubs, and cover a developer-role image beside the system one.
@Lyxot

Lyxot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Pushed a few follow-up commits on top of this:

  • Tests expecting the old drop (86423a6fbd): two tests in test_openai_tool_passthrough.py still expected a remote URL on a safetensors model to be dropped, and three more made real network calls to example.com. That is what failed Repo tests (CPU, studio) here.
  • Refuse before fetching (651506d215): one remote image plus a distinct top-level image_base64 on a single-image model is refused as "one image per message" before any fetch. Previously it waited on the image host and, if the fetch failed, returned the fetch error instead.
  • Auto-switch (15570d7a2d): a request that makes Unsloth Studio load a safetensors or MLX model is no longer refused with "Remote image URLs are not supported". Several https images for a multi-image target are no longer refused as one image per message. The loaded model fetches the URLs exactly as a resident one does, and a failed fetch is a 400 after the load, as on a GGUF target. This changes the last paragraph of the description.
  • Cleanups (cf0c8ffc23, e7a5021a3c): a generic log label for the shared fetcher, and shared setup in the new tests plus a developer-role case.

Checked live with mlx-community/Qwen2-VL-2B-Instruct-4bit:

Request main this branch
https photo of a cat, model already loaded "Dog" (image dropped) "Cat"
URL that cannot be fetched 200 400
cat + dog URLs with auto-switch, model not loaded not applicable "cat, dog" (the previous head of this PR returned 400)

… non-GGUF model

Loading a safetensors or MLX model for a request with an http:, file: or other non-https image URL evicted the resident model, and only the fetch after the load refused the scheme. Check the schemes of the images that model will fetch before the switch: the selected one, and on a multi-image model every user turn's. The fetch and the check now share one list of those parts.
…will

The non-GGUF switch preflight still took the selected image and the legacy-image clause of its multi-image check from the pre-fetch parse, which drops remote URLs. So an older malformed data URL behind a newer https image refused a request the loaded model would serve, and an assistant's https image beside a distinct image_base64 loaded the target before being refused as one image per message. Take both from the image the fetch selects.
…F switch

When the image a non-GGUF target reads is a remote URL, the switch preflight stopped validating a distinct top-level image_base64, so a multi-image target loaded before a malformed one was refused. Validate it again in that case.
@Lyxot

Lyxot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Codex and CI confirmed on head 0e782dcd16. The fork's staging copy of this PR was Lyxot#108.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Remote image URLs are now fetched on safetensors and MLX models through the same fetcher GGUF uses, and a request that auto-switches to one of those models is checked before the switch. Codex converged and CI is green.

@Lyxot
Lyxot merged commit 1783a35 into unslothai:main Sep 29, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants