[GH-ISSUE #152] Redundant ln_pre #131

Open
opened 2026-10-31 21:11:31 +00:00 by bsakaguchi · 5 comments
Owner

Originally created by @carefree0910 on GitHub (Sep 12, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/152

First of all, thanks for your great work!

And I found out that the ln_pre seems to be a redundant component:

github.com/openai/CLIP@3b473b0e68/clip/model.py (L212)

Because you've already applied pre_norm mechanism in ResidualAttentionBlock.

I'm just wondering whether this is intended or some kinds of 'typo', thanks in advance!

Originally created by @carefree0910 on GitHub (Sep 12, 2021). Original GitHub issue: https://github.com/openai/CLIP/issues/152 First of all, thanks for your great work! And I found out that the `ln_pre` seems to be a redundant component: https://github.com/openai/CLIP/blob/3b473b0e682c091a9e53623eebc1ca1657385717/clip/model.py#L212 Because you've already applied `pre_norm` mechanism in `ResidualAttentionBlock`. I'm just wondering whether this is intended or some kinds of 'typo', thanks in advance!
Author
Owner

@jongwook commented on GitHub (Sep 24, 2021):

I think they're not completely redundant because the 'identity' connection in ResidualAttentionBlock does not go through layernorms.

<!-- gh-comment-id:926324323 --> @jongwook commented on GitHub (Sep 24, 2021): I think they're not completely redundant because the 'identity' connection in `ResidualAttentionBlock` does not go through layernorms.
Author
Owner

@russelldc commented on GitHub (Sep 24, 2021):

I'm not sure this is relevant to this specific issue, but I found a significant difference while using CLIP to guide image generation.
I tried removing the use of that ln_pre in the VisionTransformer's forward(). It was no longer able to guide the generation to anything other than red/green stripes.

<!-- gh-comment-id:926329247 --> @russelldc commented on GitHub (Sep 24, 2021): I'm not sure this is relevant to this specific issue, but I found a significant difference while using CLIP to guide image generation. I tried removing the use of that ln_pre in the VisionTransformer's forward(). It was no longer able to guide the generation to anything other than red/green stripes.
Author
Owner

@carefree0910 commented on GitHub (Sep 24, 2021):

I think they're not completely redundant because the 'identity' connection in ResidualAttentionBlock does not go through layernorms.

I agree with you that it has impact on the model, but I'm not sure whether this is 'intended', because other main stream implementations don't have this kind of ln_pre before the 'identity' connection 😉

<!-- gh-comment-id:926388409 --> @carefree0910 commented on GitHub (Sep 24, 2021): > I think they're not completely redundant because the 'identity' connection in `ResidualAttentionBlock` does not go through layernorms. I agree with you that it has impact on the model, but I'm not sure whether this is 'intended', because other main stream implementations don't have this kind of `ln_pre` before the 'identity' connection 😉
Author
Owner

@carefree0910 commented on GitHub (Sep 24, 2021):

I'm not sure this is relevant to this specific issue, but I found a significant difference while using CLIP to guide image generation.
I tried removing the use of that ln_pre in the VisionTransformer's forward(). It was no longer able to guide the generation to anything other than red/green stripes.

Not sure if I get you right, but when I say 'redundant' I mean maybe we can re-train the model without it.

If you are using a pre-trained model, the ln_pre is definitely useful because the pre-trained weights are trained based on it 😆

<!-- gh-comment-id:926389906 --> @carefree0910 commented on GitHub (Sep 24, 2021): > I'm not sure this is relevant to this specific issue, but I found a significant difference while using CLIP to guide image generation. > I tried removing the use of that ln_pre in the VisionTransformer's forward(). It was no longer able to guide the generation to anything other than red/green stripes. Not sure if I get you right, but when I say 'redundant' I mean maybe we can re-train the model without it. If you are using a pre-trained model, the `ln_pre` is definitely useful because the pre-trained weights are trained based on it 😆
Author
Owner

@jongwook commented on GitHub (Oct 2, 2021):

We had it since when we initially iterated on transformer language model where it had ResNet features as prefix (LM RN50 in paper), and it got kinda stuck in the code for the contrastive version. I agree with you that it's not particularly necessary in the text encoder when training from scratch.

<!-- gh-comment-id:932673798 --> @jongwook commented on GitHub (Oct 2, 2021): We had it since when we initially iterated on transformer language model where it had ResNet features as prefix (LM RN50 in paper), and it got kinda stuck in the code for the contrastive version. I agree with you that it's not particularly necessary in the text encoder when training from scratch.
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#131
No description provided.