Repository navigation
Studio: show the model a phone photo the right way up - #12241
Conversation
NilayYadav
left a comment
There was a problem hiding this comment.
Review + reproduction evidence
Pinned review: 520cdfe3ae0c51e75365d2925593ec9e9b9cad54. 1 finding, fixed in 520cdfe3.
I reproduced the chat flow on fresh upstream main (Studio installed with install.sh --local on Linux, NVIDIA L4, Chromium 1440x900). I logged in, loaded the model from the picker, attached a JPEG stored 800x600 with EXIF Orientation 6 through "Add photos & files", and asked "Is the red half at the top, bottom, left or right of the picture? Then read the word written on the red half." The composer and the message bubble show the photo upright (red TOP above blue BOTTOM) on both sides.
- main
501b15fb, Qwen3-VL-2B-Instruct-GGUF Q4_K_M: "a red half on the left and a blue half on the right ... it reads "보통" ... the red half is at the left of the picture." - main
501b15fb, Qwen3-VL-2B-Instruct-unsloth-bnb-4bit: "The red half is on the left. The word written on the red half is "TOP"." - PR
520cdfe3, GGUF: "the red half is located at the top of the picture. The word written on the red half is TOP." - PR
520cdfe3, transformers: "The red half is at the top of the picture. The word written on the red half is "TOP"."
- Unchanged paths: the same picture without the tag gives "top / TOP" on both sides and both backends. Untagged and Orientation 1 JPEG and PNG still reach llama-server byte for byte (checked across JPEG, grayscale, CMYK, RGBA, palette, 16-bit PNG, WebP and GIF). A follow-up turn in the same chat works, and the re-encode is deterministic, so the prompt cache still matches on history replay.
- Tests: the new file fails on main (11 failed, 7 passed) and passes on the PR (18 passed). With the four related image test files, main has 11 failed and 499 passed; the PR has 510 passed.
- Cost: on a 12 MP tagged JPEG the llama path takes about +29 ms per request (30.8 ms to 59.7 ms, median of 5), and the output is +0.6% in size. Untagged photos are unchanged (43.7 ms vs 43.6 ms).
- Browser parity: I checked the rendered size in Chromium, Firefox and WebKit. A tagged JPEG or PNG is turned in all three; a tagged WebP is turned only in WebKit. That matches the WebP skip already used for image editing in #10553.
Fix pushed (520cdfe3): for a tagged PNG, or a JPEG that stb_image cannot read, _llama_image_data_url threw away the turned raster and decoded and turned the file a second time. On a 24 MP tagged PNG that cost 681 MB peak and 1.4 s. It now encodes the raster it already has: 578 MB and 1.17 s, with byte-identical output. A test checks that the file is decoded once.
Conclusion: the issue is real on main for both GGUF and transformers vision models and fixed on this branch. Remaining before merge: Actions A/B on fresh main (PR head, fix reverted, expected to fail) and upstream CI. All of those jobs were still queued when I posted this.
NilayYadav
left a comment
There was a problem hiding this comment.
Codex review coverage
Mirror: NilayYadav#155 (base is the PR's merge base d670959f, so the diff is this PR only). It covers upstream head 520cdfe3ae0c51e75365d2925593ec9e9b9cad54, and the mirror head has the same tree (f0cf85df).
Rounds: 2. Converged because Codex reported "Didn't find any major issues" on the mirror head 520cdfe3.
- Round 1 (
398012c5), P2, a tagged non-JPEG was decoded and turned twice while the first turned raster was still alive: fixed in520cdfe3(measured on a 24 MP tagged PNG: 681 MB peak and 1.4 s before, 578 MB and 1.17 s after, same output bytes; a test checks for a single decode). - Round 1 (
398012c5), P2, a re-encoded JPEG could exceed the 10 MiB remote image limit: rejected. That limit mirrors llama-server's cap on its own http downloads, and llama-server does not cap base64 data URLs, which is what Studio sends. Main already forwards larger inline images unchanged.
Final Codex result on 520cdfe3: "Didn't find any major issues."
…at images The chat decode carried a copy of the orientation rule image editing already used, without its step that drops the consumed tag, so a turned chat image still reported its old orientation. Both now call one exif_upright helper.
…id 1 Pillow keeps only the dict keys 0..n-1 of a qtables dict, so re-encoding such a tagged JPEG raised and the request failed with HTTP 400. The tables are now passed as a list in id order. The tests also check that the source's quantization tables survive the re-encode.
|
Pushed two small follow-up commits:
I also checked that the MLX path gets the upright image. MLX runs in the worker, which takes the image from |
|
Staging review and CI for head
The failures on this PR's own CI are not from this change:
|
Lyxot
left a comment
There was a problem hiding this comment.
LGTM. It fixes a real problem, and GGUF, transformers and MLX all get the photo the right way up, turned once. Codex converged and staging CI is green on b4b43bf. The remaining CI failures on this PR are not from this change.

A photo taken on a phone is usually stored sideways with a tag that says how to turn it. The chat composer and the message bubble honour that tag, so the photo looks upright, but the model was given the stored pixels. Questions about text, layout or left and right in the photo came back wrong, and nothing showed that the model saw it rotated. This happened with GGUF models and with transformers models alike.
Chat images are now turned the way the tag says before they reach the model, the same way image editing already does since #10553. A tagged JPEG is saved again as a JPEG with the same quality settings as the original, so it stays about the same size. Images without a rotation tag are still sent byte for byte, unchanged.