mirror of
https://github.com/openai/CLIP.git
synced 2026-11-05 01:37:26 +00:00
[GH-ISSUE #37] Can't get GPU speedup #35
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#35
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 @steremma on GitHub (Feb 8, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/37
It appears that the code fails to utilise GPUs on my setup: 8 V100 GPUs | nvidia driver 450 | cuda 11.0.
While torch correctly identifies the GPU (the 0th one but I can tweak this with
CUDA_VISIBLE_DEVICESexternally), when running nvidia-smi during calls tomodel.forwardorencode_imagesI observe the GPU memory filling up but utilization stays at 0, whilehtopshows my cpu cores running. As a result I get the same timing results when device is"cpu"or"cuda", the only difference being thatdevice = "cuda"will fail with GPU memory error if called for more than 500-1000 images.Is this expected, or do you have any idea how to troubleshoot this?
@jongwook commented on GitHub (Feb 12, 2021):
GPU usage can be low depending on various factors, especially when the batch size is small, and it's normal to see a CPU core hitting 100% in
htopduring active communications between GPU.Also,
nvidia-smicalls may not give an accurate measurement and might not be measured at the exact moment when the GPU kernels are being executed.Can you see if the issue persists when you run multiple batches in a loop, such as the CIFAR-100 example in README.md, using the code before the logistic regression? I see that on our V100 GPU it takes ~80 seconds to calculate
train_featuresin GPU and ~15 minutes in CPU.You can also try NVIDIA Visual Profiler to get a better sense of what's happening in GPU.
@steremma commented on GitHub (Mar 3, 2021):
My code actually resembles the linked one as I am indeed trying to embed many (100k - 10m) images in a loop. The only difference is that I do
.cpu()at the end of each batch in order to write to the file and release the memory. I tuned the batch size to 256 just below where it results in GPU-OOM error. Here is the simplified code:@nreimers commented on GitHub (Mar 19, 2021):
For me the bottleneck is the preprocess(Image.open()), this is sadly an extremely slow operation which is executed on the CPU.
Sadly did not find a solution yet how to speed up preprocess
@jongwook commented on GitHub (Mar 23, 2021):
@steremma I suspect the string operations and file writing operations crammed in the last line are taking long and making the GPU underutilized. I'd recommend saving them in a
.ptor.npyformat, and use a separate conversion script if you must have the text format. It will probably work better if you collect the embeddings in a list and save all of them outside theforloop.@nreimers That can be a problem when images are large. Pillow-SIMD may give you 2-3x boost in throughput, but in case you're working on a fixed dataset, I'd recommend resizing the images offline to match the model's input resolution (224px for smaller models), so that you can drop the expensive bicubic resize operations while loading the images. It'll load faster if you use PNG or npy format to save the resized images.
@steremma commented on GitHub (Mar 28, 2021):
The issue was indeed related to Image IO and preprocessing, thanks for all
the tips!
On Sun 28. Mar 2021 at 08:32, Jong Wook Kim @.***>
wrote: