[GH-ISSUE #409] How to Access the CLIP-pre-trained model KQV values? #349

Open
opened 2026-10-31 21:14:14 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @dmrangak on GitHub (Dec 11, 2023).
Original GitHub issue: https://github.com/openai/CLIP/issues/409

hi,
i am working with a CLIP-pre-trained model. To develop my algorithm, I want to access the KQV values. How should I access these values within this model? i use this pre-trained model

from PIL import Image
import requests

from transformers import CLIPProcessor, CLIPModel

model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")

Originally created by @dmrangak on GitHub (Dec 11, 2023). Original GitHub issue: https://github.com/openai/CLIP/issues/409 hi, i am working with a CLIP-pre-trained model. To develop my algorithm, I want to access the KQV values. How should I access these values within this model? i use this pre-trained model from PIL import Image import requests from transformers import CLIPProcessor, CLIPModel model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32") processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
Author
Owner

@data-node commented on GitHub (Apr 29, 2024):

hi, i am working with a CLIP-pre-trained model. To develop my algorithm, I want to access the KQV values. How should I access these values within this model? i use this pre-trained model

from PIL import Image import requests

from transformers import CLIPProcessor, CLIPModel

model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32") processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")

Assuming you want the KQV for layer number zero (0-11), then do this:

model.vision_model.encoder.layers[0].self_attn.k_proj.weight.data
model.vision_model.encoder.layers[0].self_attn.q_proj.weight.data
model.vision_model.encoder.layers[0].self_attn.v_proj.weight.data
<!-- gh-comment-id:2083623967 --> @data-node commented on GitHub (Apr 29, 2024): > hi, i am working with a CLIP-pre-trained model. To develop my algorithm, I want to access the KQV values. How should I access these values within this model? i use this pre-trained model > > from PIL import Image import requests > > from transformers import CLIPProcessor, CLIPModel > > model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32") processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32") Assuming you want the KQV for layer number zero (0-11), then do this: ``` model.vision_model.encoder.layers[0].self_attn.k_proj.weight.data model.vision_model.encoder.layers[0].self_attn.q_proj.weight.data model.vision_model.encoder.layers[0].self_attn.v_proj.weight.data ```
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openai/CLIP#349
No description provided.