[GH-ISSUE #72] how to distill from CLIP to get a tiny model? #66

Closed
opened 2026-10-31 21:10:25 +00:00 by bsakaguchi · 7 comments
Owner

Originally created by @dragen1860 on GitHub (Mar 26, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/72

Dear all:
I want to retain a smaller model from CLIP network. However, when i try to run knowledge distillation from Vit32model, I found model.encode_image(image) get a vector of lenght 512, while model(image_feature, text_feature) network need the text input. I donot know how to get the soft label from CLIP. Anyone get some idea about how to distill knowledge from CLIP? thanks .

Originally created by @dragen1860 on GitHub (Mar 26, 2021). Original GitHub issue: https://github.com/openai/CLIP/issues/72 Dear all: I want to retain a smaller model from CLIP network. However, when i try to run knowledge distillation from Vit32model, I found `model.encode_image(image)` get a vector of lenght 512, while `model(image_feature, text_feature)` network need the text input. I donot know how to get the soft label from CLIP. Anyone get some idea about how to distill knowledge from CLIP? thanks .
Author
Owner

@jongwook commented on GitHub (Apr 8, 2021):

I guess there are different strategies depending on your goals. If you want to make a smaller vision model that encodes image into the feature space similar to CLIP's, so that you can use CLIP's robust representation with the faster encoder, I'd train the student encoder to minimize L2 or cosine distances to CLIP's features.

If your goal is to make a specific zero-shot image classifier faster with a predetermined set of labels, you can train your image encoder to minimize the KL divergence from the probability distribution resulting from the logits returned by the CLIP model.

<!-- gh-comment-id:815592214 --> @jongwook commented on GitHub (Apr 8, 2021): I guess there are different strategies depending on your goals. If you want to make a smaller vision model that encodes image into the feature space similar to CLIP's, so that you can use CLIP's robust representation with the faster encoder, I'd train the student encoder to minimize L2 or cosine distances to CLIP's features. If your goal is to make a specific zero-shot image classifier faster with a predetermined set of labels, you can train your image encoder to minimize the KL divergence from the probability distribution resulting from the logits returned by the CLIP model.
Author
Owner

@dragen1860 commented on GitHub (Apr 13, 2021):

@jongwook Thank you for the detailed tips. I finally get what you mean. Have you test training a mobile backbone using CLIP setting. Is it possible to get a reasonble zero-shot performance?

<!-- gh-comment-id:818379181 --> @dragen1860 commented on GitHub (Apr 13, 2021): @jongwook Thank you for the detailed tips. I finally get what you mean. Have you test training a mobile backbone using CLIP setting. Is it possible to get a reasonble zero-shot performance?
Author
Owner

@jongwook commented on GitHub (Apr 13, 2021):

We don't have results on smaller model sizes than the released ones, and we haven't experimented CLIP on mobile devices. ResNet50 or ViT-B/32 model requires only a few gigaflops for the forward pass, and you might not need distillation at all if it's fine for your use case.

<!-- gh-comment-id:818403411 --> @jongwook commented on GitHub (Apr 13, 2021): We don't have results on smaller model sizes than the released ones, and we haven't experimented CLIP on mobile devices. ResNet50 or ViT-B/32 model requires only a few gigaflops for the forward pass, and you might not need distillation at all if it's fine for your use case.
Author
Owner

@dimitry12 commented on GitHub (Aug 17, 2021):

@dragen1860 have you tried distilling CLIP's image-encoder? If yes, which one (ViT or RN based)?

<!-- gh-comment-id:900702780 --> @dimitry12 commented on GitHub (Aug 17, 2021): @dragen1860 have you tried distilling CLIP's image-encoder? If yes, which one (ViT or RN based)?
Author
Owner

@dimitry12 commented on GitHub (Aug 26, 2021):

I found notes about CLIP's image-encoder distillation in https://tech.pic-collage.com/distillation-of-clip-model-and-other-experiments-f8394b7321ce but authors report loss of model behavior.

<!-- gh-comment-id:905992703 --> @dimitry12 commented on GitHub (Aug 26, 2021): I found notes about CLIP's image-encoder distillation in https://tech.pic-collage.com/distillation-of-clip-model-and-other-experiments-f8394b7321ce but authors report loss of model behavior.
Author
Owner

@ZJJHYM commented on GitHub (Jan 7, 2023):

Hello, Can you share me the weight after distill or the code about distill the clip model? My email is 13816267895@163.com
Thank you very much!

<!-- gh-comment-id:1374408080 --> @ZJJHYM commented on GitHub (Jan 7, 2023): Hello, Can you share me the weight after distill or the code about distill the clip model? My email is 13816267895@163.com Thank you very much!
Author
Owner

@justlike-prog commented on GitHub (Aug 2, 2023):

@dragen1860 did you manage to make a succesful distillation?

<!-- gh-comment-id:1661976731 --> @justlike-prog commented on GitHub (Aug 2, 2023): @dragen1860 did you manage to make a succesful distillation?
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#66
No description provided.