Skip to content

feat: transformers to v5#151

Merged
PeterStaar-IBM merged 6 commits intomainfrom
dev/bump-transformers-to-v5
Mar 27, 2026
Merged

feat: transformers to v5#151
PeterStaar-IBM merged 6 commits intomainfrom
dev/bump-transformers-to-v5

Conversation

@PeterStaar-IBM
Copy link
Copy Markdown
Member

@PeterStaar-IBM PeterStaar-IBM commented Mar 27, 2026

This allows >=4.42.0,<5.0.0 and >=5.4.0,<6.0.0 by excluding the 5.0–5.3 patch ranges which do not support granite-docling correctly.

Two changes were made to docling_ibm_models/tableformer_v2/model.py:

1. Added GenerationMixin to the class inheritance

  # Before
  class TableFormerV2(PreTrainedModel):

  # After
  class TableFormerV2(PreTrainedModel, GenerationMixin):

In transformers v5, PreTrainedModel no longer inherits from GenerationMixin. Any model that defines prepare_inputs_for_generation is expected to explicitly inherit from GenerationMixin (placed after PreTrainedModel in the MRO).

2. Added self.post_init() at the end of init

          self.data_cells = config.data_cells
          self.post_init()  # added

In transformers v5, post_init() is no longer called automatically by PreTrainedModel.init. Each model must call it explicitly at the end of its own init. This method sets several instance attributes that transformers v5 relies on during from_pretrained, including all_tied_weights_keys — the dict that was causing the AttributeError.

Signed-off-by: Peter Staar <taa@zurich.ibm.com>
….3 patch ranges which do not support granite-docling correctly.

Signed-off-by: Peter Staar <taa@zurich.ibm.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 27, 2026

DCO Check Passed

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

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Mar 27, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

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)(?:\(.+\))?(!)?:

@PeterStaar-IBM PeterStaar-IBM mentioned this pull request Mar 27, 2026
3 tasks
Signed-off-by: Peter Staar <taa@zurich.ibm.com>
@PeterStaar-IBM PeterStaar-IBM requested a review from cau-git March 27, 2026 06:37
Signed-off-by: Peter Staar <taa@zurich.ibm.com>
Signed-off-by: Peter Staar <taa@zurich.ibm.com>
Signed-off-by: Peter Staar <taa@zurich.ibm.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...odels/code_formula_model/code_formula_predictor.py 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@dolfim-ibm
Copy link
Copy Markdown
Member

We could add the following but not needed for runtime

from typing import Optional
if TYPE_CHECKING:
    from transformers import GenerationConfig

class TableFormerV2(PreTrainedModel, GenerationMixin):
    # Annotate generation_config to satisfy mypy:
    generation_config: Optional["GenerationConfig"]
    # ... rest of class ...

@PeterStaar-IBM PeterStaar-IBM merged commit 4fa73b9 into main Mar 27, 2026
12 checks passed
@PeterStaar-IBM PeterStaar-IBM deleted the dev/bump-transformers-to-v5 branch March 27, 2026 11:39
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.

2 participants