Skip to content

Fix unexpected position_ids keys when loading OwlViT models#44508

Merged
Rocketknight1 merged 2 commits intohuggingface:mainfrom
KartikPawade:fix/owlvit-ignore-position-ids-unexpected-keys
Mar 18, 2026
Merged

Fix unexpected position_ids keys when loading OwlViT models#44508
Rocketknight1 merged 2 commits intohuggingface:mainfrom
KartikPawade:fix/owlvit-ignore-position-ids-unexpected-keys

Conversation

@KartikPawade
Copy link
Copy Markdown
Contributor

What does this PR do?

Older OwlViT checkpoints stored position_ids as buffers in the text and vision embedding modules. These tensors are simple integer ranges (0 → max sequence length) and are now recomputed dynamically during initialization.

As a result, when loading models such as google/owlvit-base-patch32, the loader reports the following unexpected keys:

  • owlvit.text_model.embeddings.position_ids
  • owlvit.vision_model.embeddings.position_ids

These buffers are not required for correct model behavior and can be safely ignored.

This PR suppresses the warnings by adding the corresponding patterns to _keys_to_ignore_on_load_unexpected in OwlViTPreTrainedModel.

This change does not affect model performance or weights and only prevents unnecessary loading warnings when using older checkpoints.

Fixes #44493

Before submitting

  • This PR fixes a bug (unexpected keys warning when loading OwlViT checkpoints).
  • Did you read the contributor guideline? Yes.
  • Was this discussed/approved via a Github issue or the forum? Yes, discussed in Many models started showing UNEXPECTED Key with position id #44493.
  • Did you make sure to update the documentation with your changes? Not required.
  • Did you write any new necessary tests? Not required (warning suppression only).

Who can review?

@Rocketknight1
@yonigozlan

@KartikPawade
Copy link
Copy Markdown
Contributor Author

Hi @Rocketknight1 , CI is passing now. Happy to make any changes if needed. Thanks!

Copy link
Copy Markdown
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

LGTM but please escape the . in the key names when it's a literal .!

@KartikPawade KartikPawade force-pushed the fix/owlvit-ignore-position-ids-unexpected-keys branch from 68e42a4 to 29a1078 Compare March 14, 2026 08:01
KartikPawade and others added 2 commits March 14, 2026 13:42
Older OwlViT checkpoints saved `position_ids` as buffers in the text and
vision embedding modules. These tensors are simple integer ranges and are
now recomputed dynamically during initialization.

This results in `UNEXPECTED` key warnings when loading models such as
`google/owlvit-base-patch32`.

Add the corresponding patterns to `_keys_to_ignore_on_load_unexpected`
to suppress these warnings.
@KartikPawade KartikPawade force-pushed the fix/owlvit-ignore-position-ids-unexpected-keys branch from 29a1078 to 42a47c8 Compare March 14, 2026 08:26
@github-actions
Copy link
Copy Markdown
Contributor

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

run-slow: owlv2, owlvit

@KartikPawade
Copy link
Copy Markdown
Contributor Author

Hi @Rocketknight1 , I've escaped the dots in the regex patterns as requested and rebased onto latest main. All CI checks are passing. Ready for merge whenever you get a chance!

@KartikPawade
Copy link
Copy Markdown
Contributor Author

Hey @Rocketknight1 just a follow up on this one!.

@Rocketknight1 Rocketknight1 enabled auto-merge March 18, 2026 16:18
@Rocketknight1
Copy link
Copy Markdown
Member

LGTM now, sorry for the delay!

@KartikPawade
Copy link
Copy Markdown
Contributor Author

No, Problem, Thanks!

@Rocketknight1 Rocketknight1 added this pull request to the merge queue Mar 18, 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 d00640b Mar 18, 2026
24 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.

Many models started showing UNEXPECTED Key with position id

3 participants