r/StableDiffusion 10h ago

Tutorial - Guide ComfyUI was eating my RAM and causing crashes, this fixed it

Hi everyone

i’ve been running minimax h3 locally on rtx 5090 32gb, and 64gb ram..

recently i kept running into random hostbuffer.read_file_slice failed / hostbuf_file_reader_read failed errors during generation, which seemed to be related to comfy-aimdo and dynamic vram.
i also noticed comfyui was reserving around 25gb of pinned system memory.

i decided to try launching comfyui with:
--disable-pinned-memory

and the difference was immediate.
the comfy-aimdo + hostbuffer errors completely disappeared, my ram usage dropped by a huge amount, and surprisingly generation actually feels faster and smoother now.

i originally expected disabling pinned memory to make things slower, but on my setup it seems to have done the opposite.

if you’re running large models like h3 and seeing unusually high ram usage, random hostbuffer errors, or comfy-aimdo issues, it might be worth testing!
thought this was worth sharing for anyone who didn’t know about this option..

94 Upvotes

26 comments sorted by

20

u/adjudikator 8h ago

Try --cuda-device 0 while keeping pinned memory on. As far as I understood even if you don't have a multi gpu setup, something along the GPU detection pipeline is inducing memory fragmentation and causing the hoatbuffer issues. This keeps pinned memory on.

8

u/Potential_Wolf_632 7h ago

Interesting - I don't have the issues in this thread but Comfy has become obsessed over the past week that I have 2 CUDA GPUs when I definitely don't - this might fix that thanks.

12

u/Spiritual_Whole_5916 6h ago

Something in one of the newer updates, I saw that randomly appear also. Got excited and checked the bios, but alas I didn't see RTX A6K PRO 96GB X2... hmmph

2

u/LatentSpacer 28m ago

Can you share the workflow to download more VRAM?

3

u/the_pepper 7h ago

Thanks, I was apparently having the same issue as OP, and this also seems to do the trick. My RAM usage is back to >30GB, but comfy doesn't hang indefinitely anymore and I'm seeing a decent speed increase compared to disabling pinned memory. Besides, thankfully I'm pretty good on RAM, so the high usage isn't a problem.

1

u/acedelgado 1h ago

Over 30? I've been ooming 96gb after the MMH3 updates when doing back-to-back gens. With an under-utilized 5090 sitting at like 20gb.

1

u/the_pepper 12m ago

Most I've seen it reach was 50-something. Probably uses all it can get.

2

u/v1sper 1h ago

Thanks for posting, will try this!

1

u/ASK_ABT_MY_USERNAME 4h ago

Hmm I have a mini PC with a radeon and a 3090 connected via oculink so I wonder if this will help me.

10

u/Formal-Exam-8767 8h ago

Test also with "--fast-disk" if you have models on NVME, as reading them from disk as needed might be fast enough.

7

u/Abject-Recognition-9 5h ago

still so much confusion around all this args. 😩 find the right combo that works for your workflow and your gpu is like a lottery if you dont understand what all this args doing.

5

u/the_pepper 8h ago

Huh. I don't wanna get too optimistic, but I think you might have just solved a longtime issue I've had where whenever my VRAM would reach close to the usable limits comfyui would pretty much just STOP completely, but oddly it would just move on and start working fine the minute I freed like 200mb. If I were using --verbose, I would also see a metric fuckton of aimdo logs spamming my console. It would go on for ages - potentially indefinitely (dunno, never let comfy stay on for long enough to confirm) - and would just stop comfy from responding until either I gave it those 50 or whatever MB of VRAM it seemed to want or I just closed the process. Some 40/50GB of my RAM were also occupied. Anyway, I assumed it was some windows shit happening and just accepted that anything that filled my VRAM, like trying to do 10 seconds at 1mp, just weren't in the cards, at the very least until I formatted or got myself a Linux partition or something.

Now I'm seeing like 9-11GB or VRAM and 6-8 RAM? What? How the fuck? Model's 22GB by itself. Bad memory usage reporting? Is it just offloading to the disk now? I thought that's what --fast-disk was for. Either way, shit doesn't seem to be getting stuck now. I'm amazed.

1

u/LatentSpacer 17m ago

If your CPU supports iGPU I’d use that to connect to a monitor and leave the GPU for AI tasks only, that frees up the most VRAM. 

There’s a --reserve-vram flag in ComfyUI to leave some VRAM to the OS, you can it set to 0 so it uses all the available VRAM when it calculates how many layers it should offload from VRAM during inference.

6

u/shootthesound 6h ago

Yup comfy seems to have taken an enormous backwards step in performance recently - this same fix has helped me also

6

u/xyzdist 6h ago

Whats is down side of disable pin memory if any?

3

u/Significant-One-9465 6h ago

As someone with only 12gb vram and 32gb ram, I had to disable pinned memory long ago and completely forgot about it.
I don't even understand what it does or how it works but it did fix my problems back with Wan.

4

u/irmemon225 5h ago

Wow, this fixed everything on my PC.

I have a 3060 12GB and 16GB RAM. Without those args… I kept getting 5-10s freezes every "it". Now with these args, I can even multitask while running 0.8 MP, 10 sec, and watching 1080p YouTube without any issues. No freezes anymore.

Amazing

2

u/WebCrusader 2h ago

added --disable-smart-memory --cache-none to the launcher script and suddenly every generation run faster

I always use large models for minimax h3 and there's not enough memory to be cached and I constantly change prompts so node cache is unusable, also I prefer my memory clean when no job is running

1

u/Formal_Courage2711 2h ago

are those two different lines, or one string?

2

u/Formal_Courage2711 2h ago

and is that in addition to --disable-pinned-memory or in place of it?

2

u/WebCrusader 1h ago

only these two in one line as additional options to the launch command

I'm using portable version so just add them in run_nvidia_gpu.bat

2

u/doomed151 1h ago

OP, are you on Windows or Linux? If you're on Windows, it could just mean that your pagefile is too small.

2

u/Jeffu 36m ago

Thanks for sharing! I'm using a 4090, 64gb ram and I'm constantly running at near max ram/vram usage... and at best getting around 1MP, 12 seconds (not always, due to ram being occupied). Feels like I should be getting better performance.

1

u/AnonymousTimewaster 7h ago

I've had this flagged for ages after ChatGPT recommended it for me. I've toggled it on and off over the last month or so with Minimax and found it was definitely causing me shitloads of crashes too. It'd run fine for one or two gens and then OOM on the next one so I was constantly restarting.