XB-llama - 🗑️ 卸载模型
Kick the LLM off your GPU when you're done with it
- any
- any
The XB-llama family runs your language model as a ComfyUI node, which is great right up until the moment you remember you also need VRAM for the actual diffusion model. XB_llamaUnloadModel is the cleanup step: it forces the loaded llama model out of GPU memory and hands whatever you passed in straight through.
There's nothing clever here, and that's the point. It exists because of a specific failure mode in LLM-in-the-graph workflows: the language model loads, writes your prompt, and then stays resident, eating the exact VRAM your sampler needs next. You can't just ignore it, because on an 8GB or 12GB card the difference between "prompt written" and "model unloaded" is often the difference between a clean generation and an OOM.
How it works
The node takes one required input, any (any type - it doesn't care what you wire in), calls LLAMA_CPP_STORAGE.clean() on the XB-llama model storage, and returns the same any value back out as any. The model object is released, GPU memory is freed, and the input continues down the graph as if nothing happened.
The pass-through behavior is the part beginners miss. This node isn't a dead end - you're meant to place it in the flow so it executes at the right moment. The input type is a wildcard, so you can hang it off the end of your llama XB_llamaInstruct output, or off a text line, or off nothing meaningful at all. What actually matters is its position in the graph: when it runs, the unload happens.
How to use it
The common pattern is at the end of the prompt-writing phase, before the sampler:
XB_llamaModelLoader→XB_llamaInstruct→XB_llamaUnpackCodeBlock→ your encoder- Your encoder output →
XB_llamaUnloadModel→ sampler
If you want it to fire early, wire it off the first thing that executes after the LLM is done. If you just want it to run once per queue regardless of order, drop it as a side branch off any node that runs at that point in the graph.
You'll know it worked: the console prints [XB-llama] 卸载 Llama 模型... when it fires.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/WJLUOXIAO/XB_ToolBox.git
# or: ComfyUI Manager → "XB_ToolBox"
pip install llama-cpp-python
The pip install llama-cpp-python is the gotcha the README won't tell you: the pack claims zero pip dependencies, but the entire XB-llama family - this node included - only registers when llama-cpp-python imports successfully. No install, no node.
Common issues
- It says the model unloads but nothing frees up - a second llama model (or a diffusion model) can still be resident from a previous run. This node only unloads the XB-llama model, not everything. If you need a bigger sweep, the pack's
XB_ROCmMemCleaneror thecleanupoption on its "原版优化" samplers does the nuclear version. - Node doesn't show up - llama-cpp-python missing, same as the rest of the family.
- Unloading every run is slow - yes, reloading costs a few seconds. That's the trade being offered: give up the reload time to get the VRAM back. If your card fits both models comfortably, skip this node entirely and let them coexist.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| any | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| any | * | — |