Nodes/Pirog's Nodes for ComfyUI/LM Studio Unload Model
ComfyUI Node

LM Studio Unload Model

A polite 'please free my VRAM' node — with a pass-through so it never breaks your chain

By Pirog17000·Created about a year ago·Updated 10 months ago· 3
LM Studio Unload Model
  • images
  • system_prompt
  • user_prompt
  • images
  • generated_texts
model_ref
server_urlhttp://localhost:1234
system_prompt
user_prompt
generated_texts

LM Studio is a great way to run a local LLM, but its models like to sit in memory after you're done with them - and if you're on the same GPU that's also trying to run diffusion, that's VRAM you don't have to spare. LM Studio Unload Model is the companion node to LM Studio Query that kicks a loaded model out of memory when you're finished with it.

The clever bit isn't the unloading, it's the passthrough. The node takes in your system_prompt, user_prompt, images, and generated_texts and returns all four unchanged, so you can drop it into the middle of a chain without rewiring anything. It unloads the model and lets the data keep flowing to whatever comes next. That's the difference between a node you have to design around and a node you just insert.

How it works

You give it model_ref - the exact model key that LM Studio uses, the same model_ref that LM Studio Query outputs - and server_url. It derives the host:port from the URL and calls LM Studio's SDK to unload that model by key. If the SDK isn't installed, the model reference is empty, or the server is unreachable, it logs a warning and still passes everything through. Failures are loud-ish in the log but never fatal to your graph.

The inputs and outputs

  • model_ref - the model to unload. This is required, but if it's empty the node just passes through.
  • server_url - defaults to http://localhost:1234.
  • system_prompt, user_prompt, images, generated_texts - optional passthroughs, all returned untouched.

Outputs: the same four, in order: system_prompt, user_prompt, images, generated_texts. Yes, you read that right - the outputs are named identically to the inputs, because they are the inputs.

Installing it

This is the one node in the pack with a real extra dependency: the lmstudio SDK is how it actually unloads. It's in the pack's requirements.txt:

cd ComfyUI/custom_nodes
git clone https://github.com/Pirog17000/Pirogs-Nodes
pip install -r Pirogs-Nodes/requirements.txt

If you skip that step, the node still exists and passes data through - it just can't unload anything and tells you so in the console.

Gotchas

model_ref must match LM Studio's key for the loaded model exactly - a partial or fuzzy name won't unload. The cleanest way to guarantee it matches is to wire model_ref from LM Studio Query's output rather than typing it. And if your workflow has no chain to pass through, this node still needs its required inputs satisfied, so wire the prompt/image outputs from the query node in even if you don't care about them. It's a "nice to place at the end of your LLM segment" node, not a "forget it exists" node.

Categorypirog/ai

Inputs (6)

NameTypeDefaultDescription
model_refSTRINGReference to the model name to unload from LM Studio
server_urlSTRINGhttp://localhost:1234LM Studio server URL
system_promptoptSTRINGPassthrough for system prompt
user_promptoptSTRINGPassthrough for user prompt
imagesoptIMAGEPassthrough for images
generated_textsoptSTRINGPassthrough for generated texts

Outputs (4)

NameTypeDescription
system_promptSTRINGPassthrough system prompt
user_promptSTRINGPassthrough user prompt
imagesIMAGEPassthrough images
generated_textsSTRINGPassthrough generated texts