Repository navigation
Fix background_color handling across DeepSeek-VL and Janus image processors - #49767
Conversation
|
Thank you for your contribution 🤗! CI Security Gate — waiting for maintainer approvalCI is approved automatically only for authors who already have a contribution merged in this repository. A maintainer will review this PR and approve CI to run on it. |
|
oops sorry, didnt see you were the one who opened the issue and got a "go ahead". The pr description is complete AI text so pls try to explain in your own words what is the goal |
| if kwargs.get("image_mean") is None: | ||
| background_color = (127, 127, 127) | ||
| else: | ||
| background_color = tuple(int(x * 255) for x in kwargs.get("image_mean")) | ||
| background_color = kwargs.get("background_color") | ||
| if background_color is None: | ||
| image_mean = getattr(self, "image_mean", None) | ||
| if image_mean is None: | ||
| background_color = (127, 127, 127) | ||
| else: | ||
| background_color = tuple(int(x * 255) for x in image_mean) |
There was a problem hiding this comment.
huh wait a sec, so the existing code matches ref in Deepseek repo which also infer background from the mean. Why would we need to pop from kwargs if the resulting value supposedly is same
There was a problem hiding this comment.
Yes the values are the same but the parameter relationship is not. Ownership and procedure affects model behavior in this case. That’s the point of this pr. Thank you
There was a problem hiding this comment.
but why would we need to allow background_color as a valid config field if the ref implem doesn't, i.e. in ref they force it to be synced with mean
There was a problem hiding this comment.
You're right, and my earlier reply here was wrong -- sorry for that. Checked the actual reference (VLMImageProcessor.__init__ in deepseek-ai/DeepSeek-VL): it has no background_color parameter at all, always tuple(int(x*255) for x in image_mean), no override path. And the one real checkpoint I checked (deepseek-ai/deepseek-vl-7b-chat's preprocessor_config.json) confirms its saved background_color (122, 116, 104) is exactly that computation over its own (CLIP) image_mean -- a derived snapshot, not an independently meaningful value. So there was no real "ownership/procedure" distinction to preserve; that was me generalizing from the symptom instead of checking the reference's actual contract.
Dropped the background_color-override path entirely -- now it's always derived from self.image_mean, matching the reference. The actual bug (one backend reading kwargs.get("image_mean"), which misses a class default or reloaded config, instead of the already-resolved self.image_mean) is still fixed; that alone reproduces (122, 116, 104) correctly. Trimmed the test to match. Pushed.
…mean only @Reviewer pointed out the reference VLMImageProcessor never accepts background_color independently -- it always computes int(x*255) over image_mean. Checked: the real deepseek-vl-7b-chat checkpoint's saved background_color (122, 116, 104) is exactly int(x*255) over its own (CLIP) image_mean, i.e. a derived snapshot, not an independently meaningful value -- so preserving an explicit/saved background_color was unnecessary scope beyond the actual bug (one backend reading kwargs.get("image_mean") instead of self.image_mean) and diverges from upstream's contract. Dropped the override across all 6 __init__s; the two single-resolution PIL backends already read self.image_mean correctly pre-fix and revert to their original form entirely. image_processing_deepseek_vl.py / image_processing_pil_deepseek_vl.py are generated from modular_deepseek_vl.py, which inherits __init__ from Janus without overriding it -- fixed Janus's two files directly and regenerated DeepSeek-VL's via `utils/checkers.py modular_conversion --fix` instead of hand-editing the generated files (the original commit hand-edited them directly; this corrects that too). Trimmed test_background_color to drop the override-specific assertions; kept the default-value check (catches the 127-vs-122 mismatch directly) and the save/load round-trip check (catches it surviving a reload). Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
[For maintainers] Suggested jobs to run (before merge) run-slow: deepseek_vl, deepseek_vl_hybrid, janus |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Fixes #49625.
What was wrong
background_colorwas discarded and recomputed.kwargsinstead ofself,so the two backends disagreed by default (127 vs 122).
of its saved (122, 116, 104).
What changed
from
self's mean. (Hybrid processors: both low-res and high-res colors,with the backend setup line moved first.)
Effect
Tests
test_background_coloradded in the Janus tests and the DeepSeek-VL-Hybridtests. For each backend they check that the default color equals the CLIP
mean × 255, that a passed color is kept, and that the color survives
save_pretrained→from_pretrained. The Hybrid test also checks thehigh-res color.
70 passed, 15 skipped.
utils/check_modular_conversion.pypasses.ruff checkandruff format --checkpass with pinned ruff 0.14.10.I wrote the fix and the tests by hand.fixed some whitespace, and ran the
checks. I re-ran the tests myself.