-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing L2-norm in contrastive loss (L2-norm already present in CosSim) #6550
Conversation
…ne-similarity computation) Signed-off-by: Lucas Robinet <[email protected]>
0a1cc81
to
34e84a3
Compare
/build |
Hi @Lucas-rbnt, when the L2 norms are large values (e.g. for high dimensional embeddings) do you think this might be less stable numerically, have you tested this PR in end-to-end trainings? |
seems to be addressed in pytorch 1.12 for the same pytorch/pytorch@9e137ee |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it looks good to me. (probably less stable for early versions of pytorch but more efficient for the recent versions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it looks good to me. (probably less stable for early versions of pytorch but more efficient for the recent versions)
Hi @wyli! I am currently running a SimCLR training on BraTS21 data centered on tumor to compare before and after the commit. |
/build |
Description
The
forward
method of theContrastiveLoss
performs L2-normalization before computing cosine similarity. Thetorch.nn.functional.cosine_similarity
method already handles this pre-processing to make sure thatinput
andtarget
lie on the surface of the unit hypersphere. This step involves an unnecessary cost and, thus, can be removed.Types of changes
./runtests.sh -f -u --net --coverage
../runtests.sh --quick --unittests --disttests
.