automatic icon indicating copy to clipboard operation
automatic copied to clipboard

[Issue]: Ram keeps getting filled on AMD Rocm

Open CoutHi opened this issue 1 year ago • 13 comments

Issue Description

Each generation fills up my ram more and more, vram usage during generation will be around 8-9/16 with my settings but the ram gets slowly filled up after each image, it will start out around ~10G of usage and will climb up to 22-23 where it overflows, and this is purely from generating images, I don't need to load a different model or lora or anything like that. Haven't tested Flux etc. this is my experience with SDXL.

If I for example increase the batch count to 8, all 8 images will be generated without the ram increasing beyond what the initial loading requires, but if I do batches of 1 one after the other each image will just fill the ram more and more without anything getting freed I guess.

Version Platform Description

OS: Fedora 42 Browser: Firefox GPU: Rx 9070 with Rocm-6.3

17:28:37-695352 INFO Starting SD.Next
17:28:37-697976 INFO Logger: file="/intenso/AI/sdnext/sdnext.log" level=INFO host="fedora-desktop" size=725041 mode=append
17:28:37-698707 INFO Python: version=3.11.0 platform=Linux bin="/intenso/AI/sdnext/venv/bin/python3" venv="/intenso/AI/sdnext/venv"
17:28:37-714981 INFO Version: app=sd.next updated=2025-06-16 hash=72eb0132 branch=master url=https://github.com/vladmandic/sdnext/tree/master ui=main
17:28:38-188912 INFO Version: app=sd.next latest=2025-06-16T19:42:26Z hash=72eb0132 branch=master
17:28:38-191213 INFO Platform: arch=x86_64 cpu= system=Linux release=6.14.11-300.fc42.x86_64 python=3.11.0 locale=('en_IE', 'UTF-8') docker=False
17:28:38-192220 INFO Args: []
17:28:38-282514 INFO ROCm: AMD toolkit detected
17:28:38-284226 WARNING ROCm: no agent was found
17:28:38-284723 INFO ROCm: version=6.3
17:28:38-285190 INFO ROCm: HSA_OVERRIDE_GFX_VERSION auto config skipped: device=None version=None
17:28:38-333758 WARNING Modified files: ['.python-version']
17:28:38-350579 INFO Install: verifying requirements
17:28:38-361262 INFO Extensions: disabled=['Lora']
17:28:38-361881 INFO Extensions: path="extensions-builtin" enabled=['sd-extension-system-info', 'sd-webui-agent-scheduler', 'stable-diffusion-webui-rembg',
'sdnext-modernui', 'sd-extension-chainner']
17:28:38-363175 INFO Extensions: path="extensions" enabled=['sd-webui-prompt-all-in-one']
17:28:38-364139 INFO Startup: standard
17:28:38-364547 INFO Verifying submodules
17:28:42-593549 INFO Extensions enabled: ['sd-extension-system-info', 'sd-webui-agent-scheduler', 'stable-diffusion-webui-rembg', 'sdnext-modernui',
'sd-extension-chainner', 'sd-webui-prompt-all-in-one']
17:28:42-594213 INFO Install: verifying requirements
17:28:42-595688 INFO Installer time: total=5.45 sd-webui-prompt-all-in-one=3.94 latest=0.49 git=0.25 submodules=0.20 base=0.19 torch=0.09 log=0.05 branch=0.05
17:28:42-596381 INFO Command line args: [] args=[]
17:28:50-240766 INFO Torch: torch==2.7.1+rocm6.3 torchvision==0.22.1+rocm6.3
17:28:50-242415 INFO Packages: diffusers==0.34.0.dev0 transformers==4.52.4 accelerate==1.7.0 gradio==3.43.2 pydantic==1.10.21
17:28:58-871866 INFO Device detect: memory=15.9 default=balanced
17:28:58-873797 INFO Engine: backend=Backend.DIFFUSERS compute=rocm device=cuda attention="Split attention" mode=no_grad
17:28:59-363129 INFO Torch parameters: backend=rocm device=cuda config=FP16 dtype=torch.float16 context=no_grad nohalf=False nohalfvae=False upcast=False
deterministic=False tunable=[False, True] fp16=pass bf16=pass optimization="Split attention"
17:28:59-364203 INFO Device: device=AMD Radeon Graphics n=1 hip=6.3.42131-fa1d09cbd
17:28:59-522873 INFO Available VAEs: path="models/VAE" items=0
17:28:59-523692 INFO Available UNets: path="models/UNET" items=0
17:28:59-524273 INFO Available TEs: path="models/Text-encoder" items=0
17:28:59-525179 INFO Available Models: safetensors="models/Stable-diffusion":10 diffusers="models/Diffusers":0 items=10 time=0.00
17:28:59-532904 INFO Available LoRAs: path="models/Lora" items=34 folders=2 time=0.00
17:28:59-547665 INFO Available Styles: path="models/styles" items=288 time=0.01
17:28:59-593856 INFO Available Detailer: path="models/yolo" items=10 downloaded=1
17:28:59-594686 INFO Load extensions
17:29:00-239263 INFO Extension: script='extensions-builtin/sd-webui-agent-scheduler/scripts/task_scheduler.py' Using sqlite file:
extensions-builtin/sd-webui-agent-scheduler/task_scheduler.sqlite3
17:29:00-250342 INFO Extension: script='extensions/sd-webui-prompt-all-in-one/scripts/on_app_started.py' sd-webui-prompt-all-in-one background API service started successfully.
17:29:00-257014 INFO Available Upscalers: items=71 downloaded=0 user=0 time=0.01 types=['None', 'Resize', 'Latent', 'AsymmetricVAE', 'DCC', 'VIPS', 'ChaiNNer',
'AuraSR', 'SwinIR', 'SCUNet', 'RealESRGAN', 'Diffusion', 'ESRGAN']
17:29:00-260764 INFO UI locale: name="Auto"
17:29:00-262312 INFO UI theme: type=Standard name="invoked" available=13

Relevant log output


Backend

Diffusers

Compute

AMD ROCm

UI

ModernUI

Branch

Master

Model

StableDiffusion XL

Acknowledgements

  • [x] I have read the above and searched for existing issues
  • [x] I confirm that this is classified correctly and its not an extension issue

CoutHi avatar Jun 21 '25 15:06 CoutHi

Use TCMalloc: https://vladmandic.github.io/sdnext-docs/Malloc/

And your GPU isn't supported with ROCm 6.3, use ROCm 6.4.1 with --use-nightly (PyTorch 2.8 with ROCm 6.4)

Disty0 avatar Jun 21 '25 22:06 Disty0

Yes, use tcmalloc from gperftools. I had no success with jemalloc.

mr44er avatar Jun 22 '25 19:06 mr44er

run sdnext with --debug --monitor 5 which will log memory usage in sdnext.log every 5 seconds so we can monitor the growth.

vladmandic avatar Jun 26 '25 13:06 vladmandic

Use TCMalloc: https://vladmandic.github.io/sdnext-docs/Malloc/

And your GPU isn't supported with ROCm 6.3, use ROCm 6.4.1 with --use-nightly (PyTorch 2.8 with ROCm 6.4)

I made the changes you recommended and it seems to have helped a bit but I was still going up to 26 Gigs out of 27, I'll try the whole thing again in the official amd rocm docker container and let you guys know

CoutHi avatar Jun 27 '25 02:06 CoutHi

I have a similar problem on NVidia. Using tcmalloc does not help

alerikaisattera avatar Jul 04 '25 17:07 alerikaisattera

@alerikaisattera same comment like I left earlier - we need specific logs.

vladmandic avatar Jul 04 '25 18:07 vladmandic

@CoutHi any updates?

vladmandic avatar Jul 10 '25 16:07 vladmandic

@CoutHi any updates?

Okay so I finally got around to testing it from docker, i installed ubuntu 24.04 in a container and installed rocm6.4.1 and google-perftools in it for tcmalloc. Afterwards I copied the repo and first installed torch 2.9 with rocm6.4.1 myself in the venv since it defaulted to 6.3 otherwise, afterwards I went ahead normally with the install (./webui.sh --listen --use-rocm).

The behavior was the same, It started out with 14GBs of RAM used, after running a prompt with a batch count of 8, it went up to ~19GBs and wasn't released after generation, successive prompts only added to this usage and ram never got freed.

The startup log:

aiman@01163e23424f:~/sdnext$ ./webui.sh --listen --use-rocm Activate python venv: /home/aiman/sdnext/venv Launch: venv/bin/python3 03:04:09-239116 INFO Starting SD.Next
03:04:09-240634 INFO Logger: file="/home/aiman/sdnext/sdnext.log" level=INFO host="01163e23424f" size=73304 mode=append
03:04:09-241145 INFO Python: version=3.12.3 platform=Linux bin="/home/aiman/sdnext/venv/bin/python3" venv="/home/aiman/sdnext/venv"
03:04:09-251908 INFO Version: app=sd.next updated=2025-07-06 hash=d5d857aa branch=master url=https://github.com/vladmandic/sdnext/tree/master ui=main
03:04:09-576532 INFO Version: app=sd.next latest=2025-07-06T00:17:54Z hash=d5d857aa branch=master
03:04:09-578705 INFO Platform: arch=x86_64 cpu=x86_64 system=Linux release=6.15.5_1 python=3.12.3 locale=('C', 'UTF-8') docker=False
03:04:09-579620 INFO Args: ['--listen', '--use-rocm']
03:04:09-655188 INFO ROCm: AMD toolkit detected
03:04:09-673720 INFO ROCm: agents=['gfx1201', 'gfx1036']
03:04:09-674215 INFO ROCm: version=6.4, using agent gfx1201
03:04:09-722310 INFO Install: verifying requirements
03:04:09-723708 WARNING Install: package="numpy" installed=2.2.6 required=1.26.4 version mismatch
03:04:11-326941 INFO Extensions: disabled=[]
03:04:11-327429 INFO Extensions: path="extensions-builtin" enabled=['Lora', 'sdnext-modernui', 'sd-extension-system-info', 'sd-extension-chainner',
'sd-webui-agent-scheduler', 'stable-diffusion-webui-rembg']
03:04:11-328339 INFO Extensions: path="extensions" enabled=[]
03:04:11-328742 INFO Startup: standard
03:04:11-329026 INFO Verifying submodules
03:04:11-582033 INFO Extensions enabled: ['Lora', 'sdnext-modernui', 'sd-extension-system-info', 'sd-extension-chainner', 'sd-webui-agent-scheduler',
'stable-diffusion-webui-rembg']
03:04:11-582585 INFO Install: verifying requirements
03:04:11-583869 INFO Installer time: total=5.93 requirements=1.61 install=1.60 pip=1.59 latest=0.34 git=0.20 submodules=0.18 torch=0.11 base=0.08
03:04:11-584491 INFO Command line args: ['--listen', '--use-rocm'] listen=True use_rocm=True args=[]
03:04:15-698198 INFO Torch: torch==2.9.0 torchvision==0.24.0.dev20250710+rocm6.4
03:04:15-699661 INFO Packages: diffusers==0.35.0.dev0 transformers==4.53.0 accelerate==1.8.1 gradio==3.43.2 pydantic==1.10.21
03:04:28-455325 INFO Device detect: memory=15.9 default=balanced
03:04:28-457193 INFO Engine: backend=Backend.DIFFUSERS compute=rocm device=cuda attention="Scaled-Dot-Product" mode=no_grad
03:04:28-725009 INFO Torch parameters: backend=rocm device=cuda config=Auto dtype=torch.bfloat16 context=no_grad nohalf=False nohalfvae=False
upcast=False deterministic=False tunable=[False, True] fp16=pass bf16=pass optimization="Scaled-Dot-Product"
03:04:28-725981 INFO Device: device=AMD Radeon RX 9070 n=1 hip=6.4.43483-a187df25c
03:04:28-833681 INFO Available VAEs: path="models/VAE" items=0
03:04:28-834247 INFO Available UNets: path="models/UNET" items=0
03:04:28-834676 INFO Available TEs: path="models/Text-encoder" items=0
03:04:28-837656 INFO Available Models: safetensors="models/Stable-diffusion":1 diffusers="models/Diffusers":0 items=1 time=0.00
03:04:28-841208 INFO Available LoRAs: path="models/Lora" items=0 folders=2 time=0.00
03:04:28-845814 INFO Available Styles: path="models/styles" items=288 time=0.00
03:04:28-877106 INFO Available Detailer: path="models/yolo" items=10 downloaded=0
03:04:28-877790 INFO Load extensions
03:04:29-218236 INFO Extension: script='extensions-builtin/sd-webui-agent-scheduler/scripts/task_scheduler.py' Using sqlite file:
extensions-builtin/sd-webui-agent-scheduler/task_scheduler.sqlite3
03:04:29-224013 INFO Available Upscalers: items=72 downloaded=0 user=0 time=0.00 types=['None', 'Resize', 'Latent', 'AsymmetricVAE', 'DCC', 'VIPS',
'ChaiNNer', 'Diffusion', 'SCUNet', 'ESRGAN', 'SwinIR', 'AuraSR', 'RealESRGAN']
03:04:29-226172 INFO UI locale: name="Auto"
03:04:29-226634 INFO UI theme: type=Standard name="black-teal" available=13

CoutHi avatar Jul 11 '25 01:07 CoutHi

You did exactly this?

sudo apt install google-perftools
sudo ldconfig  
export LD_PRELOAD=libtcmalloc.so.4
./webui.sh --listen --use-rocm --debug --monitor 5

mr44er avatar Jul 11 '25 05:07 mr44er

I have a similar problem on NVidia. Using tcmalloc does not help

Correction: it does seem to help actually. RAM use still creeps up initially but doesn't creep much beyond that

alerikaisattera avatar Jul 11 '25 09:07 alerikaisattera

@CoutHi

I went ahead normally with the install (./webui.sh --listen --use-rocm)

i did state 2 weeks ago to add command line params --debug --monitor 5 so we can see extra messages and memory monitoring!

vladmandic avatar Jul 11 '25 13:07 vladmandic

I went ahead normally with the install (./webui.sh --listen --use-rocm)

i did state 2 weeks ago to add command line params --debug --monitor 5 so we can see extra messages and memory monitoring!

Whoops, sorry about that, I ran with those commands but I don't think further action here is necessary, LD_PRELOAD=libtcmalloc.so.4 fixed it, I thought it would be enough to install it but launching with it seems to be the way to make it work properly. All is good for me now.

CoutHi avatar Jul 12 '25 00:07 CoutHi

thanks for confirming

vladmandic avatar Jul 12 '25 01:07 vladmandic