Skip to content

Fix background_color handling across DeepSeek-VL and Janus image processors - #49767

Merged
zucchini-nlp merged 2 commits into
huggingface:mainfrom
tritsystem:fix/janus-bg-color
Oct 21, 2026
Merged

zucchini-nlp merged 2 commits into
huggingface:mainfrom
tritsystem:fix/janus-bg-color

Conversation

@tritsystem

@tritsystem tritsystem commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🤗 Transformers CI

Fixes #49625.

What was wrong

  • A given or saved background_color was discarded and recomputed.
  • The torchvision processors read the mean from kwargs instead of self,
    so the two backends disagreed by default (127 vs 122).
  • As a result, deepseek-vl-7b-chat padded its low-res branch with 127 instead
    of its saved (122, 116, 104).

What changed

  • All 6 processors now keep a passed or saved color; otherwise they compute it
    from self's mean. (Hybrid processors: both low-res and high-res colors,
    with the backend setup line moved first.)
  • DeepSeek-VL files regenerated from the modular files.

Effect

  • deepseek-vl-7b-chat now uses its saved color (122, 116, 104).
  • mean-0.5 checkpoints (Janus-Pro, 1.3b) are unchanged.

Tests

  • test_background_color added in the Janus tests and the DeepSeek-VL-Hybrid
    tests. 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 the
    high-res color.
  • Red on main, green with the fix.
  • Janus, DeepSeek-VL, and DeepSeek-VL-Hybrid image-processing tests:
    70 passed, 15 skipped. utils/check_modular_conversion.py passes.
    ruff check and ruff format --check pass with pinned ruff 0.14.10.
  • The slow 7B GPU tests were not run.

I wrote the fix and the tests by hand.fixed some whitespace, and ran the
checks. I re-ran the tests myself.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution 🤗!

CI Security Gate — waiting for maintainer approval

CI 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.

@zucchini-nlp

Copy link
Copy Markdown
Member

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
I will review now

Comment on lines +58 to +64
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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]>
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: deepseek_vl, deepseek_vl_hybrid, janus

@zucchini-nlp zucchini-nlp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, lgtm now!

@zucchini-nlp
zucchini-nlp added this pull request to the merge queue Oct 21, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

Merged via the queue into huggingface:main with commit 3f91ebf Oct 21, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Janus / DeepSeek-VL image processors ignore background_color; deepseek-vl-7b-chat's low-res branch pads with 127 instead of its saved (122, 116, 104)

3 participants