Fix unexpected position_ids keys when loading OwlViT models#44508
Open
KartikPawade wants to merge 2 commits intohuggingface:mainfrom
Open
Fix unexpected position_ids keys when loading OwlViT models#44508KartikPawade wants to merge 2 commits intohuggingface:mainfrom
position_ids keys when loading OwlViT models#44508KartikPawade wants to merge 2 commits intohuggingface:mainfrom
Conversation
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.
4 tasks
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: owlv2, owlvit |
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 .!
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