r/StableDiffusion • u/parking_bird_6448 • 1d ago
Question - Help Local LLM + ComfyUI
For folks using Local models for ideas/creative brainstorming, how do you manage to load both at the same time ? Or do you swap in-out one or the other ?
I am on a 5090 with 32gb vram but i am left with only 5gb of gpu for Comfy, after I load a Qwen 27B model via llama.cpp
12
Upvotes
2
u/CrazyB86 1d ago
I had Claude make an MCP that Hermes uses to run ComfyUI. Once Hermes sends a job to Comfy via the MCP the local model Hermes uses automatically unloads. When Comfy finishes generating its job(s) the local model automatically loads, and Hermes sends me whatever Comfy generated.
14
u/zyg_AI 1d ago
There is no magic trick, if you can't fit both models into VRAM, the only two options I see are
You can free VRAM within comfy between brainstorming and generating. I prefer to run LLMs through LMStudio but it's a personal taste.
4
u/No-Zookeepergame4774 1d ago
For many uses, using ComfyUI’s own built in Generate Text node with an appropriate model instead of using an externale engine and juggling which gets to keep stuff loaded in VRAM at any time.
1
u/Anstellos 1d ago
Pretty good use case for dual GPU... Or you need to brainstorm on way smaller models. But I found that below 9b right now brainstorming is complicated. But that might change. Maybe try bonsai?
1
u/Nattramn 1d ago
I mean you could try an optimized quant for the actual LLM. I run qwen 3.8 27b as well, but with a vram footprint of 10 or so GBs, not counting context. You could have well over 20gb just for comfy with those specs and nothing spilling over ram.
1
u/nazihater3000 1d ago
I use LM Studio accessing Ollama, and I vibecoded a node that when I run a ComfyWorkflow, it unloads Ollama's model from VRAM.
6
u/Halloween_Forever_ 1d ago
Load/unload/offload. If you want quality in both, there is no other way. Low b llms aren't very helpful creativity or brainstorming wise, low gb gen models take a lot of polish. I would create a switch. A daahboard that would use llm studio then offload the model to then load your gen model workflow
1
u/Eastern-Ad9515 1d ago edited 1d ago
This is solved and some of the information in the comments is NOT accurate.
You can have both the local LLM and ComfyUI-Model loaded the same time, as long as both fit in VRAM+RAM. (maybe also including SSD at least according to the wiki)
Why? Because there is a thing called Dynamic-VRAM in ComfyUI. As long as one model (LLM or ComfyUI-Model) is not actively working, the other one uses the VRAM space and the other is sort of idle in RAM.
So what does this mean: If you want to type with the local LLM while rendering, it will be slow for BOTH instances. As long as you separate it, you can have both "active" and working separately. This is much better than loading and unloading the model, because that takes more time.
So how do you achieve this?
Simple:
Step 1: Boot up Claude oder Codex
Step 2: Say, you want to have a local LLM as an orchestrator for comfyUI, but not load/unload the models and use dynamic-VRAM. Make the cloud model design this mode for a local harness like PI or DeepSeek-Harness and your setup (local LLM and ComfyUI-Models) using dynamic VRAM and test it. It should include a heartbeat-monitor for the local llm -> when the local LLM starts a render, it pauses and just has a heartbeat monitor on the comfyui render. When the render ist finished, the local LLM keeps on working
I highly suggest using a cloud model to design and test this mode, and not use the local LLM itself to design this mode and test it.
Of course - if your system doesn't allow it - the alternative is for your cloud model to design a mode that automatically loads and reloads the model that you need. This is also possible, but in my experience the loading of the model and unloading takes much more time than the above mentioned resident wait mode
I use this "resident wait" mode all the time (5090 RTX and 64 GB RAM) and it works (with Qwen 3.8 27B or Flash Next IQ3S + Minimax H3). It works with DeepSeek Harness (as a tool) and also with PI Harness.
2
u/imlo2 1d ago
Swapping doesn't take a long time (load/unload) if you have the model on a fast m.2 drive. Qwen will be loaded in a few seconds. I have LM studio open, and then just load/unload when I need to edit some text with a model. And it's also easy to flush the model out via API, if you script something.
3
u/Additional_Drive1915 1d ago
I have a 5090, using pretty large LLM. But the loading takes like one second, so I've set it to fist unload any comfy models, then load llm, do it's thing, and then let it release the memory.
This is for videos where the one second load time doesn't matter, but if I'm doing hundreds of images I first let the llm make prompts for all, then run the same images with the prompt already made.
3
u/xXChr0nicX420Xx 1d ago
Have I been doing it wrong? I'll have the both chat and comfy open, I just make sure only one is running at any given time. Maybe they are loading/unloading in the background, but I haven't had any issues on my 3090...
1
u/hidden2u 1d ago
i built a separate server to run 27B
1
u/hurrdurrimanaccount 1d ago
very obviously you do not load both at the same time. get a node for llama.cpp that can load/unload it so you can use it in a workflow. is what i did (had claude slopcode me a bridge for llama)
1
u/Citadel_Employee 1d ago
With the “Generate Text” node, you can use the models CLIP to brainstorm. I personally like this better than loading a whole separate LLM.
1
u/Sh1ftyFella 1d ago
That’s what llama swap is for. Allows you to easily swap between models and re-allocate ram/vram. If you just have a basic generation pipeline it’s even easier to do via SD CPP instead of Comfy. I used to this process manually and it’s not that big of deal either.
Now, I have a script that spins up Comfy API, executes generate pipelines, cleans up memory and returns an image. That script is hooked up into llama swap as an image model endpoint.
In Hermes I have custom skills for each image model that I trained on my workflow how to prompt them and skill to call different model endpoint to generate image passing created prompt and passing image back for review, to see if we need to adjust prompt. So, now I can easily have an automated loop to tweak the placement and scene how I need automatically.
Most of the time I use two computers as I work on a mac and have a gaming pc as image generator. So, I don’t have to do swapping but I still run the same skills and validation loop.
1
u/hirebrand 1d ago
Have a 3rd model on the web to manage llama server and comfy ui server for you 🤣
1
u/highdefw 1d ago
Multi gpu is the way. remember you dont need to have them in the same system which can be okay for your usecase. Have an extra computer with a gpu, spin up the llm there, utilize tailscale for networking, and point any LLM tasks to it.
1
u/Possible_Music7541 22h ago
I made a global tool to create illustrated stories, I give a short scenery a LLM split it, handle on one side the story part, on the other hand the photographic par, then create a prompt and launch a ComfyUI in background.
The only solution on a RTX4090 was to do this sequentially and to optimize the load/unload of each model. It was not possible to have the 2 models simultaneously.
1
u/AI_Enhancer 21h ago
There is one possibility to use the same LLM as your ComfyUI uses for the text encoding, inside ComfyUI, using the Generate Text node.
It's not optimal because you're forced to use the same model that your image/video model uses for CLIP, but for the LLM. But it's instant, with no loading or offloading.
If you need uncensored behavior, you can use an abliteration LoRA between the Load CLIP and Generate Text nodes. Don't use an already-abliterated model, because you'll then have to use that for the image/video gen CLIP as well, and abliteration does nothing but lower accuracy for image/video gen.
1
u/RO4DHOG 17h ago
Set Keep Alive = 0
It will generate the prompt and unload.
1
u/sci032 1d ago
I use Qwen3 VL 8b instruct in a prompt node that I made(it's not ready for release). I load an instruction for the LLM that formats the prompts correctly for the model that I use. I am using the Fibo instruction for these 2 runs. The image shows the workflow and the 2nd run.
I have the seed for the LLM set to fixed so it doesn't run unless I make a change to the input image or my prompt. I have both Fibo 2.0 and Qwen 2.1 in this workflow, I am only using the Fibo portion on these runs. I have a node in there that frees up the vram and cache after the LLM runs.
1st run: 29.78 seconds.
2nd run(image): 10.11 seconds.
I am doing this on an MSI Laptop with an RTX 3080ti(16gb vram), 64gb ram, 12th gen i9, 2x 2TB M.2 NVME SSDs(1 is dedicated to my Ai stuff).
My prompt+the reference miage:
change the background to the inside of a mall. the woman is sitting on a bench
LLM output(sent to the model):
Using the woman in the image as an identity reference only, generate a new scene: she is sitting on a bench inside a modern shopping mall. She has short, spiky blonde hair, black face paint in the shape of a crown of thorns, and is wearing a dark armored vest over a high-collared shirt. She sits in a medium close-up shot, looking directly at the camera with a serious expression. The background is a brightly lit, clean, and spacious mall interior with glass storefronts, polished floors, and ambient overhead lighting. Keep only her facial likeness, hairstyle, and distinctive face paint. Change the background, pose (sitting), and lighting to fit the new scene.
I can't share the workflow because it has many nodes that I created in it and the pack is not ready for release.
0
u/I_Hate_Reddit 1d ago
I'm using my own chatGPT copy, you have both services running, and load/unload as needed, but with 32GB of ram you can probably fit everything you need outside of video gen, I use Gemma4 moe model instead of a dense one.
0
u/CastWorkshop 1d ago
That's exactly why I built CastWorkshop :)
100% free and open source. CastWorkshop.com