Zdafeng / SwinFIR

Other
73 stars 4 forks source link

CUDA is out of memory #4

Open FengJin2023 opened 6 months ago

FengJin2023 commented 6 months ago

Hello,

I am trying the run inference code for test data. However I got below runtime error for CUDA memory. I only changed the test data file path in the code. I tried both RTXA6000(Memory:48GB) and RTX3090Ti(24GB), but both got the same error. My data is 960x540 images. Furthermore, I cropped the size to 60x60, but still got the same error.

What could be the possible reason for this problem?

Best regards,

Feng Jin

Testing 0 0007_gt Traceback (most recent call last): File "inference/inference_swinfir.py", line 150, in main() File "inference/inference_swinfir.py", line 51, in main output = model(img) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, kwargs) File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfir_arch.py", line 508, in forward x = self.conv_after_body(self.forward_features(x)) + x File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfir_arch.py", line 493, in forward_features x = layer(x, x_size) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, *kwargs) File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfir_arch.py", line 305, in forward return self.patch_embed(self.conv(self.patch_unembed(self.residual_group(x, x_size), x_size))) + x File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(input, kwargs) File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfir_arch.py", line 218, in forward x = blk(x, x_size) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, kwargs) File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfir_arch.py", line 124, in forward attn_windows = self.attn(x_windows, mask=self.calculate_mask(x_size).to(x.device)) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, *kwargs) File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfirutils.py", line 166, in forward qkv = self.qkv(x).reshape(b, n, 3, self.num_heads, c // self.num_heads).permute(2, 0, 3, 1, 4) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(input, kwargs) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/linear.py", line 93, in forward return F.linear(input, self.weight, self.bias) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/functional.py", line 1692, in linear output = input.matmul(weight.t()) RuntimeError: CUDA out of memory. Tried to allocate 16.83 GiB (GPU 0; 47.54 GiB total capacity; 27.21 GiB already allocated; 12.37 GiB free; 27.23 GiB reserved in total by PyTorch)

Hyeeji commented 6 months ago

In my case, the CUDA out of memory error occurred due to file size limitations. When I attempted to process an 865kb image, it resulted in a RuntimeError: CUDA out of memory. However, a 300kb image was processed successfully.

starzero-hhh commented 1 month ago

Hello,

I am trying the run inference code for test data. However I got below runtime error for CUDA memory. I only changed the test data file path in the code. I tried both RTXA6000(Memory:48GB) and RTX3090Ti(24GB), but both got the same error. My data is 960x540 images. Furthermore, I cropped the size to 60x60, but still got the same error.

What could be the possible reason for this problem?

Best regards,

Feng Jin

Testing 0 0007_gt Traceback (most recent call last): File "inference/inference_swinfir.py", line 150, in main() File "inference/inference_swinfir.py", line 51, in main output = model(img) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, kwargs) File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfir_arch.py", line 508, in forward x = self.conv_after_body(self.forward_features(x)) + x File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfir_arch.py", line 493, in forward_features x = layer(x, x_size) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, *kwargs) File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfir_arch.py", line 305, in forward return self.patch_embed(self.conv(self.patch_unembed(self.residual_group(x, x_size), x_size))) + x File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(input, kwargs) File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfir_arch.py", line 218, in forward x = blk(x, x_size) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, kwargs) File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfir_arch.py", line 124, in forward attn_windows = self.attn(x_windows, mask=self.calculate_mask(x_size).to(x.device)) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, *kwargs) File "/home/imglab3/feng/Research/SwinFIR-main/swinfir/archs/swinfirutils.py", line 166, in forward qkv = self.qkv(x).reshape(b, n, 3, self.num_heads, c // self.num_heads).permute(2, 0, 3, 1, 4) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(input, kwargs) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/modules/linear.py", line 93, in forward return F.linear(input, self.weight, self.bias) File "/home/michael/feng/anaconda3/envs/SwinFIR/lib/python3.8/site-packages/torch/nn/functional.py", line 1692, in linear output = input.matmul(weight.t()) RuntimeError: CUDA out of memory. Tried to allocate 16.83 GiB (GPU 0; 47.54 GiB total capacity; 27.21 GiB already allocated; 12.37 GiB free; 27.23 GiB reserved in total by PyTorch)

I also tried to run the inference code for the test data. However, I am also encountering the following runtime error with CUDA memory, have you resolved the memory error yet?