Nodes/XB_ToolBox/XB-llama - 🚀 模型加载Pro
ComfyUI Node

XB-llama - 🚀 模型加载Pro

XB_ToolBox's GGUF loader doesn't load anything — and that's the feature

By wjluoxiao·Created 7 months ago·Updated a day ago· 406
XB-llama - 🚀 模型加载Pro
    • llama_model
    • parameters
    ◄model▾►
    ◄mmproj▾►
    ◄chat_handlerNone►
    ◄advanced_settingsfalse►
    ◄n_ctx32768►
    ◄vram_limit-1►
    ◄image_min_tokens0►
    ◄image_max_tokens0►
    ◄max_tokens8192►
    ◄top_k40►
    ◄top_p0.90►
    ◄min_p0.05►
    ◄typical_p1.00►
    ◄temperature0.60►
    ◄repeat_penalty1.05►
    ◄frequency_penalty0.00►
    ◄present_penalty0.00►
    ◄mirostat_mode0►
    ◄mirostat_eta0.10►
    ◄mirostat_tau5.00►
    ◄state_uid-1►
    ◄backendllama-cpp-python►
    ◄gpu_deviceauto►

    XB-llama - 🚀 Model Loader Pro is the front door of XB_ToolBox's LLM branch: one node where you pick a local GGUF, cap how much VRAM it may touch, and set every sampling knob the pack's inference nodes will use. If you've been keeping Ollama running just so a ComfyUI node can rewrite your prompt, this is the in-graph alternative.

    What it is not is a model loader. Get that straight first.

    Why it's called a loader and loads nothing

    Read the source: loadmodel() returns two Python dicts. The first (llama_model, type LLAMACPPMODEL) is just a config - model path, mmproj, chat handler, context length, VRAM limit, image-token caps, backend, GPU index. The second (parameters, type LLAMACPPPARAMS) holds the sampling settings. Weights load later, when a downstream inference node fires and calls LLAMA_CPP_STORAGE.load_model().

    Two consequences in practice: a workflow containing this node allocates no VRAM just by being queued, and if you swap in an online API node the local weights never load at all. Also, there's no "[XB-llama] loading model" line in the console until the downstream node runs - if you're watching the log wondering why nothing's happening, that's the design, not a hang.

    Models come from ComfyUI/models/LLM/ - the pack registers that folder and scans for .gguf, .safetensors, .bin, .ckpt, .pt, .pth. Files with mmproj in the filename are pulled out of the main model list and offered as projectors instead.

    The inputs that matter

    • model - the enum built from that folder. Empty dropdown means the folder is empty or missing.
    • mmproj - None for text-only models. Point it at a projector file and you've built a VLM, with one hard rule the code enforces: chat_handler can't stay None while an mmproj is loaded, or you get an error instead of a model.
    • chat_handler - the chat template for your architecture (Qwen3-VL, MiniCPM, Gemma3, GLM-4.6V and friends). This list is discovered from your installed llama-cpp-python, so an old wheel silently gives you a shorter dropdown.- advanced_settings - off by default, and it hides everything below. Flip it on.
    • n_ctx (32768) and max_tokens (8192) - the author's tooltips are unusually specific here: a short story fits in 32768, a 56-shot script wants 131072–262144, and 6 shots run about 12K output tokens against ~128K for 56. Under-budget these and the model stops mid-storyboard.
    • temperature (0.60) - the tooltip says why: it keeps the [SHOT_START] format strict and cuts hallucination. That marker is the tell for what this branch is built for, which is turning a story into per-shot prompt lines, not writing poetry.
    • repeat_penalty (1.05) - a nudge, not a hammer. Too high and the LLM starts dropping dialogue it already wrote earlier in the story.
    • vram_limit - the interesting one. -1 means unlimited. Give it a number and the loader estimates per-layer size from the GGUF's file size and layer count, then computes how many layers fit in that budget (subtracting the projector's size when one is loaded). That's how a 9B Q4 lives alongside your diffusion model. The author's own tooltip warns it's a reference figure and you can overshoot - so set it below your free VRAM, not equal to it.
    • state_uid - -1 uses the node's own unique id to persist conversation state, so each node keeps its own history.

    Skip backend and gpu_device unless you know something I don't. The backend tooltip admits llama-server isn't wired in at all - picking it records the choice and changes nothing - and gpu_device only ever applied to that unimplemented subprocess path.

    Outputs, and where they go

    llama_model is the config dict that goes into a downstream inference node's model input - the pack's nodes take it as a wildcard type, so the same socket takes either a local config or an online API settings string. parameters carries the sampling settings into that node's optional parameters input. Wire both.

    Install

    ComfyUI Manager, search XB_ToolBox, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/wjluoxiao/XB_ToolBox.git
    

    Restart ComfyUI. Ignore the README's "no extra pip dependencies" line for this branch - requirements.txt lists diskcache and gguf and leaves llama-cpp-python commented out, because you install that wheel yourself: CUDA builds from the JamePeng release page, ROCm/HIP compiled for AMD, matched to your Python version (their example is cp312). Then create ComfyUI/models/LLM/ and drop your GGUFs in it.

    Where people get burned

    • A RuntimeError about llama-cpp-python not being installed: the wheel isn't there, or it's too old for the chat handler you picked. The error text includes the wheel links.
    • Empty model dropdown: empty models/LLM folder, or files in a format outside the extension list.
    • mmproj selected, handler left at None: hard error by design.
    • Expecting vram_limit to be a promise. It's arithmetic on an estimate; leave headroom.
    CategoryXB-llama

    Inputs (23)

    NameTypeDefaultDescription
    modelCOMBO0 options:
    mmprojCOMBO1 options: None
    chat_handlerCOMBONone1 options: None
    advanced_settingsBOOLEANfalse开启后显示上下文长度、显存上限、图像token 及全部推理参数
    n_ctxINT327681024–262144上下文长度上限 Qwen3.5-9B 原生 262144(256K);短篇 32768,56 段调到 131072-262144
    vram_limitINT-1-1–1024显存使用上限(GB), -1=不限制 参考值, 实际可能略超
    image_min_tokensINT00–4096—
    image_max_tokensINT00–4096—
    max_tokensINT81920–262144生成 Token 上限(Qwen3.5-9B 上限 262144) 6 段约 12K,56 段约 128K,请按段数调整
    top_kINT400–1000词汇库检索范围 40 配合 0.60 温度,兼顾格式严谨与词汇多样
    top_pFLOAT0.900–1—
    min_pFLOAT0.050–1—
    typical_pFLOAT1.000–1—
    temperatureFLOAT0.600–2温度 0.60 确保 [SHOT_START] 格式严谨,减少幻觉
    repeat_penaltyFLOAT1.050–10重复惩罚 1.05 轻微防句式复读,同时保留台词(太高会让 LLM 省略已在故事里写过的台词)
    frequency_penaltyFLOAT0.000–1—
    present_penaltyFLOAT0.000–2—
    mirostat_modeINT00–2—
    mirostat_etaFLOAT0.100–1—
    mirostat_tauFLOAT5.000–10—
    state_uidINT-1-1–999999使用特定 ID 保存对话状态 (-1 = 使用节点 unique_id)
    backendCOMBOllama-cpp-python本地推理后端。 llama-cpp-python:进程内后端(XB_ToolBox 当前实现,默认) llama-server:子进程后端,需额外的服务端运行环境;当前 XB 后端尚未接入,选它不会改变实际推理方式(仅记录到配置里)
    gpu_deviceCOMBOautoGPU 设备索引(仅 llama-server 子进程后端使用)。 auto = 自动跟随 ComfyUI 当前显卡;当前 XB 进程内后端始终自动跟随 ComfyUI

    Outputs (2)

    NameTypeDescription
    llama_modelLLAMACPPMODEL—
    parametersLLAMACPPARAMS—