Fix unexpected position_ids keys when loading OwlViT models#44508
Merged
Rocketknight1 merged 2 commits intohuggingface:mainfrom Mar 18, 2026
Merged
Conversation
4 tasks
Contributor
Author
|
Hi @Rocketknight1 , CI is passing now. Happy to make any changes if needed. Thanks! |
Rocketknight1
approved these changes
Mar 9, 2026
Member
Rocketknight1
left a comment
There was a problem hiding this comment.
LGTM but please escape the . in the key names when it's a literal .!
68e42a4 to
29a1078
Compare
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.
29a1078 to
42a47c8
Compare
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: owlv2, owlvit |
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! |
Contributor
Author
|
Hey @Rocketknight1 just a follow up on this one!. |
Member
|
LGTM now, sorry for the delay! |
Contributor
Author
|
No, Problem, Thanks! |
|
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. |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Older OwlViT checkpoints stored
position_idsas 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_idsowlvit.vision_model.embeddings.position_idsThese 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_unexpectedinOwlViTPreTrainedModel.This change does not affect model performance or weights and only prevents unnecessary loading warnings when using older checkpoints.
Fixes #44493
Before submitting
Who can review?
@Rocketknight1
@yonigozlan