Running on CPU #118

Open
opened 2026-01-29 21:42:52 +00:00 by claunia · 2 comments
Owner

Originally created by @bochkarev-artem on GitHub (Dec 12, 2021).

Hi, i am missing option to run inference on cpu. I have low memory on my GPU, so its useless with it. How can i avoid running this on GPU with CUDA?
Even if i run this:

from basicsr.archs.rrdbnet_arch import RRDBNet
            from realesrgan import RealESRGANer
            model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
            bg_upsampler = RealESRGANer(
                scale=2,
                model_path='https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth',
                model=model,
                tile=args.bg_tile,
                tile_pad=10,
                pre_pad=0,
                half=False)  # need to set False in CPU mode

i get:

miniconda3\lib\site-packages\torch\nn\functional.py:3679: UserWarning: The default behavior for interpolate/upsample with float scale_factor changed in 1.6.0 to align with other frameworks/libraries, and now uses scale_factor directly, instead of relying on the computed output size. If you wish to restore the old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details.
  warnings.warn(
        Failed inference for GFPGAN: CUDA out of memory. Tried to allocate 128.00 MiB (GPU 0; 2.00 GiB total capacity; 805.62 MiB already allocated; 25.72 MiB free; 942.00 MiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF.
        Failed inference for GFPGAN: CUDA out of memory. Tried to allocate 128.00 MiB (GPU 0; 2.00 GiB total capacity; 805.62 MiB already allocated; 25.72 MiB free; 942.00 MiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF.

Setting PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:21 seems to be not enough for my GPU (1 GB). I cant provide value smaller than 21 mb

Originally created by @bochkarev-artem on GitHub (Dec 12, 2021). Hi, i am missing option to run inference on cpu. I have low memory on my GPU, so its useless with it. How can i avoid running this on GPU with CUDA? Even if i run this: ``` from basicsr.archs.rrdbnet_arch import RRDBNet from realesrgan import RealESRGANer model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2) bg_upsampler = RealESRGANer( scale=2, model_path='https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth', model=model, tile=args.bg_tile, tile_pad=10, pre_pad=0, half=False) # need to set False in CPU mode ``` i get: ``` miniconda3\lib\site-packages\torch\nn\functional.py:3679: UserWarning: The default behavior for interpolate/upsample with float scale_factor changed in 1.6.0 to align with other frameworks/libraries, and now uses scale_factor directly, instead of relying on the computed output size. If you wish to restore the old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details. warnings.warn( Failed inference for GFPGAN: CUDA out of memory. Tried to allocate 128.00 MiB (GPU 0; 2.00 GiB total capacity; 805.62 MiB already allocated; 25.72 MiB free; 942.00 MiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF. Failed inference for GFPGAN: CUDA out of memory. Tried to allocate 128.00 MiB (GPU 0; 2.00 GiB total capacity; 805.62 MiB already allocated; 25.72 MiB free; 942.00 MiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF. ``` Setting `PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:21` seems to be not enough for my GPU (1 GB). I cant provide value smaller than 21 mb
Author
Owner

@bolshoytoster commented on GitHub (Dec 13, 2021):

Unfortunately, as said in this stackoverflow answer:

CUDA toolkits since at least CUDA 4.0 have not supported an ability to run cuda code without a GPU.

You used to be able to use the --multicore flag but it's not available anymore.

@bolshoytoster commented on GitHub (Dec 13, 2021): Unfortunately, as said in [this stackoverflow answer](https://stackoverflow.com/a/21946786): > CUDA toolkits since at least CUDA 4.0 have not supported an ability to run cuda code without a GPU. You used to be able to use the `--multicore` flag but it's not available anymore.
Author
Owner

@soulteary commented on GitHub (May 20, 2022):

There is a simple solution, you can refer to here. https://github.com/TencentARC/GFPGAN/issues/194

In addition, you can actually take the code out of the container and use it, in the current version, it does not need to use GPU acceleration.

@bolshoytoster @bochkarev-artem

@soulteary commented on GitHub (May 20, 2022): There is a simple solution, you can refer to here. https://github.com/TencentARC/GFPGAN/issues/194 In addition, you can actually take the code out of the container and use it, in the current version, it does not need to use GPU acceleration. @bolshoytoster @bochkarev-artem
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TencentARC/GFPGAN#118