ibrahimethemhamamci / CT2Rep

MICCAI 2024 & CT2Rep: Automated Radiology Report Generation for 3D Medical Imaging
20 stars 3 forks source link

torch.cuda.OutOfMemoryError: CUDA out of memory #4

Open xiweideng opened 2 months ago

xiweideng commented 2 months ago

Dear author, Thank you for your great work! But when I try to replicate your work in a RTX 4090 GPU, it throw an error ,CUDA out of memory. How can I reduce the memory usage? image

sezginerr commented 2 months ago

Hello @xiweideng, you can increase the patch sizes in model files e.g. ct2rep.py. It is currently 24 for spatial and 12 for temporal. They should be divisible to volume dimensions. Make sure to arrange kernel size here self.avg_fnt = torch.nn.AvgPool3d(kernel_size=20, stride=1, padding=0) in visual extractor. Kernel size is number of patches in each dimension here (which is 20 for now). You can also arrange volume dimensions in dataloader and then arrange kernel size accordingly. I can also integrate 16 bit precision to this but it might take a while to test. Let's put that as a TODO.

xiweideng commented 2 months ago

Hello @sezginerr , Thank you for the swift response and the practical suggestions to reduce memory usage. I appreciate the guidance on adjusting the patch sizes in the ct2rep.py file and the advice on arranging the kernel size in the visual extractor. I'll make sure the dimensions are divisible to maintain compatibility. The idea of potentially integrating 16-bit precision sounds promising, and I understand it may take time to test thoroughly.

In the meantime, I will experiment with your current recommendations and adjust the volume dimensions in the dataloader accordingly. I’m optimistic these changes will help mitigate the CUDA out of memory error I’ve been experiencing on the RTX 4090. I look forward to any future updates and am happy to contribute to testing if needed.

Thank you once again for your support and for being open to further enhancements like the 16-bit precision integration. It’s clear these steps could significantly impact the efficiency and accessibility of your work on more platforms. Best regards,

xiweideng commented 2 months ago

I wanted to update you on my progress and express my immense gratitude for your assistance. After following your advice, I have successfully modified the patch sizes to 48, the temporal patch size to 24, and the kernel size to 10. These changes have allowed the code to run smoothly on the RTX 4090 without encountering the previous CUDA out of memory error.

Your recommendations were incredibly helpful and made a significant difference. Thank you very much!