Nodes/ComfyUI GLM-4 Wrapper/GLM-4 Inferencing
ComfyUI Node

GLM-4 Inferencing

A local LLM you can chain into your workflow

By Nojahhh·Created 2 years ago·Updated about a year ago· 30
GLM-4 Inferencing
  • GLMPipeline
  • image
  • output_text
system_prompt
user_prompt
max_new_tokens250
temperature0.70
top_k50
top_p1.00
repetition_penalty1.00
seed42
unload_modelfalse

This is the pack's general-purpose chat node, and it's the one you reach for when "enhance this prompt" isn't enough. GLM-4 Inferencing takes a system prompt, a user prompt, and optionally an image, and returns free-form text from a GLM-4 model running on your machine. No API calls, no key - same open-weights THUDM/Z.ai family as the rest of this pack, downloaded automatically on first run.

The difference from the Prompt Enhancer matters: there, the node dictates the whole conversation to produce one caption. Here, you own the instructions. Want the model to critique an image you just generated and suggest lighting changes? That's a system prompt. Want a caption in a specific format for a video model? You write the format. It's the node you'd use when the enhancer's one-size-fits-all prompt isn't giving you what you want.

How it works

Feed it the GLMPipeline from the pack's Model Loader, and it builds a proper chat template - system message plus user message - runs transformer.generate() with your sampling settings, then strips the messages back out of the reply. Two details from the source worth knowing:

  • With a vision model (glm-4v-9b or the GPTQ variants), the system and user prompts are merged into one message and an optional image rides along, so you can ask questions about a picture. Text-only models get a normal system/user split.
  • The node trims the response at the last period. It's an artifact of cleaning up the model's output, and it means a reply that ends in quotes, a URL, or code will get clipped. If your output keeps ending mid-sentence, that's why - pad your system prompt accordingly or leave a sentence-ending period on purpose.

Inputs and outputs that matter

  • GLMPipeline - from the Model Loader. Required.
  • system_prompt - multiline. The instructions/role for the model ("You are a strict critic who never praises…"). Empty by default.
  • user_prompt - multiline. What you're actually asking.
  • image (optional) - only vision models. This is what turns the node into an image question-answerer.
  • max_new_tokens (250) - response length cap.
  • temperature / top_k / top_p / repetition_penalty - sampling. Defaults here are looser than the Enhancer's (0.7 / 50 / 1 / 1), which fits open-ended chat. Crank temperature down for factual, repeatable answers.
  • seed - reproducibility.
  • unload_model - free VRAM after the call. Off by default, so the model stays warm if you're looping; turn it on inside a heavy image-gen workflow.

The single output, output_text, is a STRING - chain it into the Prompt Enhancer's prompt slot, into a text encoder, or into another Inferencing node if you're feeling brave about multi-stage reasoning.

Installing it

It's in the same pack as everything else, so ComfyUI Manager (search "GLM-4", install ComfyUI GLM-4 Wrapper) or:

cd ComfyUI/custom_nodes
git clone https://github.com/Nojahhh/ComfyUI_GLM4_Wrapper
cd ComfyUI_GLM4_Wrapper
python -m pip install -r requirements.txt

Then restart ComfyUI. The dependency list is the same heavy one as the rest of the pack - transformers from the GitHub source, bitsandbytes, accelerate, sentence-transformers - and the model download on first run is the real time cost. glm-4-9b is ~18 GB; the vision model is ~26 GB; the GPTQ quantized vision models are ~8 GB and additionally want auto-gptq (a known Windows headache, installable from source).

Where people get burned

Mostly it's the model choice. If you feed this node a text-only model, the image input silently does nothing - image support only exists on the vision models. And remember the output gets cut at the last period, so don't build a workflow that depends on the model emitting trailing punctuation. Otherwise it behaves like any local LLM: first run downloads a lot, and everything after that is fast.

CategoryGLM4Wrapper

Inputs (11)

NameTypeDefaultDescription
GLMPipelineGLMPipelineProvide a GLM-4 pipeline.
system_promptSTRINGProvide a system prompt for inferencing. (Instructions for the model)
user_promptSTRINGProvide a user prompt for inferencing
max_new_tokensINT250Limit the number of output tokens
temperatureFLOAT0.70Temperature parameter for sampling
top_kINT50Top-k parameter for sampling
top_pFLOAT1.00Top-p parameter for sampling
repetition_penaltyFLOAT1.00Repetition penalty for sampling
seedINT420–4294967295
imageoptIMAGEProvide an image to use as input for inferencing. Only supported for glm-4v-9b, glm-4v-9b-gptq-4bit and glm-4v-9b-gptq-3bit models.
unload_modeloptBOOLEANfalseUnload the model after use to free up memory

Outputs (1)

NameTypeDescription
output_textSTRING