Repository navigation
Qwen3VL: apply the sRGB tone curve in the image preprocess path - #411
Merged
davidkoski merged 1 commit intoJul 13, 2026
Merged
Conversation
CoreImage filters run in a linear-light working space and asMLXArray renders with a nil colorSpace, so the image path fed the model linearized values instead of the gamma-encoded sRGB bytes the HF reference preprocesses. Bright content survives that error; dark content does not — near-black text (luminance 23/255 on a 6/255 background) reached the ViT with ~12x less contrast than reference and was unreadable. The sibling Qwen25VL/Qwen2VL image paths and this file's own video path already apply the tone-curve step; the port dropped it in the image path. Measured on the incident screenshot: faint-band signal vs background was 0.011 without the step, 0.126 with it (reference: 0.133). Adds a regression test pinning the model-side extrema of a faint dark-theme fixture to the gamma-encoded reference values. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
davidkoski
reviewed
Jul 13, 2026
| let resampled = processed.map { | ||
| MediaProcessing.resampleBicubic( | ||
| MediaProcessing.inSRGBToneCurveSpace($0), to: targetSize) | ||
| } |
Member
There was a problem hiding this comment.
I wonder if other models have the same issue? From a quick scan it looks like Idefics3, MistralV3, and Paligemma might.
Qwen25VL, Gemma3 and Gemma4 all do the resample in gamma space (incorrect, but probably matches the python code) so they won't have this issue.
davidkoski
approved these changes
Jul 13, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Change looks good. See comment on other models. Thank you.
dkgv
pushed a commit
to dkgv/mlx-swift-lm
that referenced
this pull request
Jul 30, 2026
…xplore#411) CoreImage filters run in a linear-light working space and asMLXArray renders with a nil colorSpace, so the image path fed the model linearized values instead of the gamma-encoded sRGB bytes the HF reference preprocesses. Bright content survives that error; dark content does not — near-black text (luminance 23/255 on a 6/255 background) reached the ViT with ~12x less contrast than reference and was unreadable. The sibling Qwen25VL/Qwen2VL image paths and this file's own video path already apply the tone-curve step; the port dropped it in the image path. Measured on the incident screenshot: faint-band signal vs background was 0.011 without the step, 0.126 with it (reference: 0.133). Adds a regression test pinning the model-side extrema of a faint dark-theme fixture to the gamma-encoded reference values. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
div0-space
pushed a commit
to LibraxisAI/mlx-swift-lm
that referenced
this pull request
Nov 29, 2026
Composition: a request with a reasoning budget stays target-only. Its guard sits in mtpHistoryEligible, which mtpBasicEligible includes, so a budgeted row neither drafts nor keeps assistant history, exactly as on ml-explore#411 alone (where mtpBasicEligible gated both). Budgeted requests carry no token constraint (EngineV2 refuses the pair), so they never reach grammar verification or free spans.
div0-space
pushed a commit
to LibraxisAI/mlx-swift-lm
that referenced
this pull request
Nov 29, 2026
test-shards.json: both new groups kept (native-reasoning-budget from ml-explore#411, gemma-quoted-number-enabled from ml-explore#408), each scheduled once.
div0-space
pushed a commit
to LibraxisAI/mlx-swift-lm
that referenced
this pull request
Nov 29, 2026
On the cumulative SDK ml-explore#416 (ml-explore#409 + ml-explore#413 + ml-explore#411 + ml-explore#408 on main 859f641). test-shards.json: gemma-reopened-thought-enabled kept beside gemma-quoted-number-enabled as its own extra run in the same shard (the shard tool refuses one run mixing different env). Every other file merges unchanged: the merge adds exactly ml-explore#407's lines.
div0-space
pushed a commit
to LibraxisAI/mlx-swift-lm
that referenced
this pull request
Nov 29, 2026
…ion) into the cumulative SDK Only .github/test-shards.json conflicted. Resolution = ml-explore#414's replanned map (4 native shards + the hosted audio shard, hosted_tests, rest run in shard 4) byte for byte, plus what this branch had added to the old map, each once: - groups native-reasoning-budget (ml-explore#411) and gemma-quoted-number-enabled (ml-explore#408, extra pass with DARKBLOOM_GEMMA_SCHEMA_COERCION=1), unchanged; - a run for each group (shards 1 and 2) and one units run in shard 3 for CBv2FreeSpanTests + QwenFreeSpanHistoryTests (ml-explore#413, was its own shard) and CBv2GrammarNonFiniteTests + CBv2GrammarQwen4Tests (ml-explore#409, was the rest run); - estimated_seconds of those three shards raised accordingly. Every other ml-explore#414 file is main's version; no Swift file differs from the cumulative head eaed116. Checked: test_shards.py load_map/resolve_runs (36 groups each used once, one rest run, no unit listed twice; each new suite selected by exactly one main run); test_shards_test.py 27/27 OK.
div0-space
pushed a commit
to LibraxisAI/mlx-swift-lm
that referenced
this pull request
Nov 29, 2026
Cumulative SDK for provider 0.10.13: ml-explore#409 + ml-explore#413 + ml-explore#411 + ml-explore#408 (opt-in)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #410.
The Qwen3VL image path hands the model CoreImage's linear-light working-space values instead of the gamma-encoded sRGB values the HF reference preprocesses: CoreImage filters run in linear light and
MediaProcessing.asMLXArrayrenders with a nil colorSpace. The siblingQwen25VL/Qwen2VLimage paths and this file's own video path all apply the linear→sRGB tone-curve step; the Qwen3VL port dropped it in the image path.Bright content survives the error; dark content does not — near-black text (luminance 23/255 on a 6/255 background) reaches the ViT with ~12× less contrast than reference and is unreadable. Measured on the incident screenshot (text-vs-background signal after mean/std-0.5 normalization): 0.011 without the step, 0.126 with it, HF reference 0.133. Before/after screenshots in #410.
The change is the one-line
inSRGBToneCurveSpacewrap at the resample site, plus a regression test (Qwen3VLToneCurveTests) that runs a synthetic faint dark-theme fixture throughpreprocessand pins the model-side extrema to the gamma-encoded reference values — the linear-space failure mode lands far outside the tolerances.Note: textually adjacent to #398 (both touch the resample site); whichever lands second is a trivial rebase.