Skip to content

🚨Fix floating-point precision in JanusImageProcessor resize - #43187

Merged
yonigozlan merged 9 commits into
huggingface:mainfrom
raimbekovm:fix-janus-image-processor-precision
Feb 2, 2026
Merged

yonigozlan merged 9 commits into
huggingface:mainfrom
raimbekovm:fix-janus-image-processor-precision

Conversation

@raimbekovm

Copy link
Copy Markdown
Contributor

Fixes #43186

What does this PR do?

Fixes floating-point precision issue in JanusImageProcessor.resize() where int() truncation caused incorrect output dimensions.

Problem:

height = 2522, size = 384
delta = 384 / 2522 = 0.15225218081681999...
height * delta = 383.9999999999...
int(height * delta) = 383  # Wrong!
round(height * delta) = 384  # Correct!

Solution:
Replace int() with round() for proper rounding of scaled dimensions.

Why edit modular_janus.py?

The file image_processing_deepseek_vl.py (mentioned in the issue) is auto-generated from modular_janus.py. The header states:

🚨 This file was automatically generated from src/transformers/models/janus/modular_janus.py.
   Do NOT edit this file manually...

DeepseekVL imports JanusImageProcessor, so fixing the source fixes all dependent models:

  • Janus
  • DeepseekVL
  • DeepseekVL Hybrid

@Rocketknight1

Copy link
Copy Markdown
Member

Bug seems legit but I'd like someone with more image processor experience to check that we're still matching the behaviour that these models expect, because sometimes models are trained with slightly buggy preprocessing code and it becomes important to match that behaviour later. cc @molbap @yonigozlan @zucchini-nlp

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

Makes sense to me, we need the sides to be exactly 'size' length. Can you run make fix-repo to convert modular files?

@raimbekovm

Copy link
Copy Markdown
Contributor Author

Done. Ran the modular converter and pushed the regenerated file.

Note: The same int() truncation issue exists in two other places:

  • image_processing_deepseek_vl.py (generated from modular_deepseek_vl.py which inherits from JanusImageProcessor)
  • image_processing_janus_fast.py (not a modular file)

Should I include these in this PR or handle them separately?

@zucchini-nlp

Copy link
Copy Markdown
Member

Should I include these in this PR or handle them separately?

Running make fix-repo should have auto-fixed those, no? I see the CI is still complaining about these models

@raimbekovm

Copy link
Copy Markdown
Contributor Author

Fixed. Added the missing changes for deepseek_vl and janus_fast.

@zucchini-nlp

Copy link
Copy Markdown
Member

@bot /repo

@github-actions

github-actions Bot commented Jan 13, 2026 •

Copy link
Copy Markdown
Contributor

Repo. Consistency fix runs successfully without any file modified.

@yonigozlan

Copy link
Copy Markdown
Contributor

run-slow: deepseek_vl, janus, deepseek_vl_hybrid

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

@zucchini-nlp

Copy link
Copy Markdown
Member

run-slow: deepseek_vl, janus, deepseek_vl_hybrid

@zucchini-nlp

Copy link
Copy Markdown
Member

slow tests cannot be triggered 😢

@molbap

molbap commented Jan 29, 2026

Copy link
Copy Markdown
Collaborator

run-slow: deepseek_vl, deepseek_vl_hybrid, janus

@github-actions

Copy link
Copy Markdown
Contributor

This comment contains run-slow, running the specified jobs:

models: ["models/deepseek_vl", "models/deepseek_vl_hybrid", "models/janus"]
quantizations: []

@github-actions

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Model CI Report

❌ Failed tests

  • deepseek_vl_hybrid:
    tests/models/deepseek_vl_hybrid/test_modeling_deepseek_vl_hybrid.py::DeepseekVLHybridIntegrationTest::test_model_text_generation

  • janus:
    tests/models/janus/test_modeling_janus.py::JanusIntegrationTest::test_model_text_generation

@yonigozlan

Copy link
Copy Markdown
Contributor

I got similar results locally with slow tests now failing due to this changes. However it seems to me that the processing now works as it's supposed to , so ok to change the expected values (and add a 🚨 as it breaks BC a bit)? @molbap @zucchini-nlp

@zucchini-nlp

Copy link
Copy Markdown
Member

Yeah, sounds good to me. Let's just update test values with the new ones and merge as breaking

@yonigozlan yonigozlan changed the title Fix floating-point precision in JanusImageProcessor resize 🚨Fix floating-point precision in JanusImageProcessor resize Feb 2, 2026
@yonigozlan

Copy link
Copy Markdown
Contributor

run-slow: deepseek_vl, deepseek_vl_hybrid, janus

@github-actions

github-actions Bot commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

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

run-slow: deepseek_vl, deepseek_vl_hybrid, janus

@yonigozlan
yonigozlan enabled auto-merge (squash) February 2, 2026 18:43
@yonigozlan
yonigozlan merged commit 56c4b5e into huggingface:main Feb 2, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Floating-point precision issues in iamge_processing_deepseek_vl.py

6 participants