Skip to content

fix: transformers warnings - #4014

Merged
PeterStaar-IBM merged 2 commits into
mainfrom
fix/transformers-warnings
Aug 18, 2026
Merged

fix: transformers warnings#4014
PeterStaar-IBM merged 2 commits into
mainfrom
fix/transformers-warnings

Conversation

@PeterStaar-IBM

@PeterStaar-IBM PeterStaar-IBM commented Aug 17, 2026

Copy link
Copy Markdown
Member

fix: avoid deprecated torch_dtype warnings on transformers 5.x

Description

transformers 5.x renamed the from_pretrained keyword torch_dtype to dtype.
Both Transformers-backed inference engines still passed torch_dtype=torch_dtype
unconditionally, including when the dtype resolved to None.

That is not a no-op on transformers 5.x: the None value is forwarded into the
config kwargs and reaches the deprecated PretrainedConfig.torch_dtype setter,
which emits a deprecation warning on every model load. Users converting documents
with the layout / image-classification stages saw this warning repeatedly in
otherwise clean output.

This PR:

  • Only passes a dtype kwarg when a dtype was actually resolved (torch_dtype is not None),
    so the default path no longer touches the deprecated setter at all.
  • Picks the correct keyword name at runtime based on the installed transformers
    major version (dtype for >= 5, torch_dtype otherwise), keeping both
    transformers 4.x and 5.x working from the same code path.
  • Adds a comment documenting a second, unrelated source of noise: RT-DETRv2 on
    transformers 5.x validates encoder spatial shapes with a tensor condition, which
    causes a torch.compile graph break ("Graph break from Tensor.item()") once per
    compiled region. It is noisy but harmless, and can be silenced with
    TRANSFORMERS_DISABLE_TORCH_CHECK=1 — safe for our fixed-resolution exports.

Files touched:

  • docling/models/inference_engines/image_classification/transformers_engine.py
  • docling/models/inference_engines/object_detection/transformers_engine.py

No behavior change for users on transformers 4.x, and no change to the resolved
dtype in any case — only how (and whether) it is handed to from_pretrained.

@github-actions

Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @PeterStaar-IBM, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ngines/image_classification/transformers_engine.py 60.00% 2 Missing ⚠️
...ce_engines/object_detection/transformers_engine.py 60.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

lgtm

@PeterStaar-IBM
PeterStaar-IBM merged commit ac1f2ce into main Aug 18, 2026
26 checks passed
@PeterStaar-IBM
PeterStaar-IBM deleted the fix/transformers-warnings branch August 18, 2026 07:31
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.

3 participants