mirror of
https://github.com/openai/CLIP.git
synced 2026-11-05 01:37:26 +00:00
[GH-ISSUE #280] Discussion on the transposing trick used in transformer #243
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openai/CLIP#243
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Joy-Lunkad on GitHub (Aug 12, 2022).
Original GitHub issue: https://github.com/openai/CLIP/issues/280
I was hoping to understand the benefits of the "double transpose trick" employed in model.py and its potential effects on layernorm inside and outside the transformer.
I would greatly appreciate if you could point me towards a good resource that explains this.
Thank you!
@jongwook commented on GitHub (Aug 12, 2022):
Hi, it was just to conform with the input shape expected by the
nn.MultiheadAttentionmodule, which is(L=sequence length, N=batch size, D=model width)by default. I just noticed that PyTorch has added thebatch_first=Trueoption in 1.9.0 which would eliminate the need to transpose.@Joy-Lunkad commented on GitHub (Aug 13, 2022):
Thank you for your reply! I have just a couple more questions :)
LN inside transformer:-
LN outside transformer:-
Am I missing something obvious here since these do not inform the layer norm module which axis is the batch axis that it needs to ignore?
There is also ln_1 directly after ln_pre which makes me wonder what benefits might taking the norm of a norm have.
@jongwook commented on GitHub (Aug 13, 2022):
The LayerNorm module will use the last dimension(s), and in our case the model width is always the last dimension before or after the transposes.
It was pointed out in #152 (with a similar discussion about the redundancy of
ln_pre) that common implementations of vision transformers don't useln_pre. Model-wise, there's a slight difference with and withoutln_pre, but I think it wouldn't make much difference when trained withoutln_pre.