stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

support cuda malloc

Open wkpark opened this issue 1 year ago • 5 comments

imported from comfy: https://github.com/comfyanonymous/ComfyUI/blob/f1d6cef71c70719cc3ed45a2455a4e5ac910cd5e/cuda_malloc.py

original commits:

  • https://github.com/comfyanonymous/ComfyUI/commit/799c08a: Auto disable cuda malloc on some GPUs on windows.
  • https://github.com/comfyanonymous/ComfyUI/commit/D39c58b: Disable cuda malloc on GTX 750 Ti.
  • https://github.com/comfyanonymous/ComfyUI/commit/85a8900: Disable cuda malloc on regular GTX 960.
  • https://github.com/comfyanonymous/ComfyUI/commit/30de083: Disable cuda malloc on all the 9xx series.
  • https://github.com/comfyanonymous/ComfyUI/commit/7c0a5a3: Disable cuda malloc on a bunch of quadro cards.
  • https://github.com/comfyanonymous/ComfyUI/commit/5a90d3c: GeForce MX110 + MX130 are maxwell.
  • https://github.com/comfyanonymous/ComfyUI/commit/fc71cf6: Add some 800M gpus to cuda malloc blacklist.
  • https://github.com/comfyanonymous/ComfyUI/commit/861fd58: Add a warning if a card that doesn't support cuda malloc has it enabled.
  • https://github.com/comfyanonymous/ComfyUI/commit/192ca06: Add some more cards to the cuda malloc blacklist.
  • https://github.com/comfyanonymous/ComfyUI/commit/caddef8: Auto disable cuda malloc on unsupported GPUs on Linux.
  • https://github.com/comfyanonymous/ComfyUI/commit/2f93b91: Add Tesla GPUs to cuda malloc blacklist.

Description

detect supported GPUs and add PYTORCH_CUDA_ALLOC_CONF=backend:cudaMallocAsync automatically.

  • [x] support cuda_malloc
  • [x] add -cuda-malloc, --disable-cuda-malloc cmd args

Checklist:

wkpark avatar Oct 12 '24 13:10 wkpark

@wkpark thank you so much

can you explain what cuda malloc exactly does and brings performance or memory optimization?

FurkanGozukara avatar Oct 12 '24 13:10 FurkanGozukara

@wkpark thank you so much

can you explain what cuda malloc exactly does and brings performance or memory optimization?

Please refer to the following articles: https://iamholumeedey007.medium.com/memory-management-using-pytorch-cuda-alloc-conf-dabe7adec130

and https://github.com/comfyanonymous/ComfyUI/commit/50bf66e5c44fe3637f29999034c10a0c083c7600

wkpark avatar Oct 12 '24 14:10 wkpark

@wkpark ty so much

why comfyui made it disabled by default do you know? we are all moved to torch 2.4

FurkanGozukara avatar Oct 12 '24 14:10 FurkanGozukara

@wkpark ty so much

why comfyui made it disabled by default do you know? we are all moved to torch 2.4

that's not the latest change. already reverted two month ago. https://github.com/comfyanonymous/ComfyUI/commits/master/cuda_malloc.py

wkpark avatar Oct 12 '24 15:10 wkpark

Just wanted to let devs know. I've been using this PR with the startup tag active for three months now without issue. Running a RTX2070 laptop. https://github.com/aleph23/auto1111/pull/7

aleph23 avatar Jun 13 '25 15:06 aleph23