mirror of
https://github.com/openai/CLIP.git
synced 2026-11-05 01:37:26 +00:00
[GH-ISSUE #132] Batch Sharding Details #120
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#120
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 @Zasder3 on GitHub (Jul 24, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/132
Within the paper you write:
I've seen many different interpretations of this line that vary between repo. How did the sharding function within the training code? Did each device receive the
32768x32768matrix containing the inner-products? Did each device only compute a localNxNmatrix s.t.N << 32768? Did each device recieve only 232768xEmbed_dimmatrices?@jongwook commented on GitHub (Aug 30, 2021):
It was briefly explained in this comment. Each device received the entire embeddings of size
32768 x embed_dimto be matmul'ed with the local embedding vectors, like:where
all_gatheris a function gathering and concatenating the tensors across GPUs. The logits are then used as inputs to the cross entropy loss for 32768-way classification, resulting in a loss value corresponding tolocal_batch_sizeinputs in each GPU.DistributedDataParalleltakes care of averaging these across GPUs, which becomes equivalent to calculating the loss over32768 x 32768similarities.@mutasem-mattar commented on GitHub (Sep 4, 2021):
I have a question about
all_gatherused for training, I know there is two versions forall_gatherthat can be implemented, one which records the gradients from allGPUsand the other one does adetach. I am wondering which one was used for training.@jongwook commented on GitHub (Sep 5, 2021):
@mutasem-mattar the
all_gatherfunction needs a full, undetached backward operation (callingreduce_scatteror similar operations) for training to work most efficiently.@mutasem-mattar commented on GitHub (Sep 26, 2021):
I have one follow up question. How did you manage to
all_gatherthe image embeddings and text embeddings and do dot product without getting OOM problem. specially your batch size is around 32768.@jongwook commented on GitHub (Sep 30, 2021):
The memory that all-gathered features take is:
and the logits after the dot product would take:
so it's manageable.
@zsnoob commented on GitHub (Nov 24, 2023):
I'm confused about trainning implementation. When we do contrastive learning, the diagonal elements are positive samples. But if we calculate the loss locally with shape (local_batch_size, global_batch_size), how do we know the positive samples each GPU?
I have an unconfirmed idea that we may get the local_rank and know the distributed local batch "index" to get the corresponding position of the positive samples. But i don't know whether the local rank is exactly the "local batch index".