Skip to content

Many models started showing UNEXPECTED Key with position id #44493

Closed

Description

@weathon

System Info

  • transformers version: 5.0.0
  • Platform: Linux-6.6.113+-x86_64-with-glibc2.35
  • Python version: 3.12.12
  • Huggingface_hub version: 1.5.0
  • Safetensors version: 0.7.0
  • Accelerate version: 1.12.0
  • Accelerate config: not found
  • DeepSpeed version: not installed
  • PyTorch version (accelerator?): 2.10.0+cu128 (CUDA)
  • Using distributed or parallel set-up in script?:
  • Using GPU in script?:
  • GPU type: NVIDIA A100-SXM4-40GB

Who can help?

Many models, including google/owlvit-base-patch32 and a few LLMs started showing unexpecting keys. For example, I got this

import torch
from transformers import AutoModelForZeroShotObjectDetection, AutoProcessor
from transformers.image_utils import load_image


# Prepare processor and model
# model_id = "google/owlv2-large-patch14-ensemble"
model_id = "google/owlvit-base-patch32"
device = "cuda" if torch.cuda.is_available() else "cpu"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForZeroShotObjectDetection.from_pretrained(model_id).to(device)
OwlViTForObjectDetection LOAD REPORT from: google/owlvit-base-patch32
Key                                         | Status     |  | 
--------------------------------------------+------------+--+-
owlvit.text_model.embeddings.position_ids   | UNEXPECTED |  | 
owlvit.vision_model.embeddings.position_ids | UNEXPECTED |  | 

Notes:
- UNEXPECTED	:can be ignored when loading from different task/architecture; not ok if you expect identical arch.

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

Loading some models that could trigger this, example code as below

import torch
from transformers import AutoModelForZeroShotObjectDetection, AutoProcessor
from transformers.image_utils import load_image


# Prepare processor and model
# model_id = "google/owlv2-large-patch14-ensemble"
model_id = "google/owlvit-base-patch32"
device = "cuda" if torch.cuda.is_available() else "cpu"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForZeroShotObjectDetection.from_pretrained(model_id).to(device)

Expected behavior

It should load correctly with no unexpected keys as they are the same unmodified model

Activity

  1. Rocketknight1 commented on Mar 6, 2026

    @Rocketknight1
    Member

    This is annoying, but it thankfully shouldn't affect model performance! I believe what's happening here is that owlvit used to save self.position_ids as a buffer, but this was not the position embeddings, it was just an integer range tensor from 0 to the max sequence length. Obviously, there's not much point in saving this in the checkpoints, since it can easily be recomputed on the fly.

    At some point the model was likely updated to recompute the key, but then we were left with these extra keys in the checkpoints and the loader is complaining about them. The right solution is to add those keys to keys_to_ignore_on_load_unexpected for owlvit to suppress those warnings - would you like to make a PR?

  2. KartikPawade commented on Mar 6, 2026

    @KartikPawade
    Contributor

    Hi @Rocketknight1 , I’ve opened a PR to address this by adding the corresponding patterns to _keys_to_ignore_on_load_unexpected in OwlViTPreTrainedModel.

    PR: #44508

    Please let me know if any adjustments are needed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions