Nodes/ComfyUI GLM-4 Wrapper/GLM-4 Prompt Enhancer
ComfyUI Node

GLM-4 Prompt Enhancer

Your prompts, but somebody actually read them first

By Nojahhh·Created 2 years ago·Updated about a year ago· 30
GLM-4 Prompt Enhancer
  • GLMPipeline
  • image
  • enhanced_prompt
prompt
max_new_tokens200
temperature0.10
top_k40
top_p0.70
repetition_penalty1.10
unload_modelfalse
seed42

The name tells you most of what you need: type "a girl on the beach" and this node hands back a long, detailed description a diffusion model can actually work with. Nothing is sent to an API. No key, no account, no credit card - it runs GLM-4, an open-weights 9B model from THUDM (the Tsinghua lab that now calls itself Z.ai), entirely on your own GPU. The model even downloads itself the first time you run the workflow, which saves you from hunting through Hugging Face for the right files.

There's a lineage worth knowing. This node is a local port of the prompt enhancer THUDM ships inside the CogVideoX-5B demo (convert_demo.py). The author built it because that demo only worked through the OpenAI API, and he wanted the same trick offline. So you're getting a battle-tested few-shot prompt, not some random "make it better" instruction slapped together.

LLM-assisted prompting is mainstream now, and it fits the hardware instead of fighting it. A 9B chat model writing your prompt is basically translation between two things that speak the same language - and it helps on CLIP-era models (SDXL, FLUX) just as much as on the new LLM-encoded ones. The one place it fights you: tag-based models like Pony or Illustrious want comma-separated booru tags, and this node emits prose. Use it for natural-language models and you'll be glad you did.

How it works

You chain it behind the pack's GLM-4 Model Loader, which provides the GLMPipeline input. The enhancer stuffs your prompt into a long internal system prompt - the "you work with an assistant bot that will draw anything you say in square brackets" routine from THUDM's demo, complete with worked examples - runs generation, then strips its own scaffolding out of the reply so you get clean text.

Here's the subtle bit that catches people: the model you load changes what it writes. Text-only GLM models produce image descriptions. The vision model (glm-4v-9b or the GPTQ versions), fed an optional image, switches to image-to-video captioning - it describes motion starting from that frame, which is exactly what CogVideoX or Wan want as a caption. If all you want is better FLUX prompts, load a text model; if you're captioning frames for a video model, load a vision one.

Inputs and outputs that matter

  • GLMPipeline - comes from the Model Loader. Required.
  • prompt - your base prompt. Can be left empty if you're feeding an image to a vision model.
  • image (optional) - only used by the vision models. Wire an image in and you get an image-to-video caption out.
  • max_new_tokens (200) - how long the caption can get. 200 is usually plenty.
  • temperature / top_k / top_p / repetition_penalty - sampling knobs. The defaults (0.1 / 40 / 0.7 / 1.1) are already tuned for detailed, low-drama captions; leave them alone until you know why you're changing them.
  • seed - set for reproducibility.
  • unload_model - off by default, which means the model stays warm in VRAM between runs. If this lives inside a bigger workflow (FLUX, CogVideoX), flip it on so the 9B model frees your VRAM after each pass. Just know the next enhance will reload it.

The single output, enhanced_prompt, is a STRING - wire it straight into your CLIP Text Encode's positive input or into a video model's prompt slot.

Installing it

Easiest route is ComfyUI Manager: search "GLM-4" and install the ComfyUI GLM-4 Wrapper pack. Manual install is the standard song and dance:

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. That requirements.txt is heavy - transformers straight from the GitHub repo, bitsandbytes, accelerate, sentence-transformers - so give it a few minutes. Disk is the other bill: glm-4-9b is ~18 GB, the vision model ~26 GB. The quantized GPTQ versions are the cheap seats (~8 GB) and need auto-gptq installed (pip install auto-gptq; on Windows, from source).

Where people get burned

First run downloads gigabytes, and there's no progress bar in the node - it just sits there, so give it time and watch the console. On Windows, the GPTQ models are the classic failure point: auto-gptq with CUDA extensions is genuinely fiddly there, and the author's own Reddit thread has users stuck on it. If you're on Windows and just want it working, skip the GPTQ models and use the regular 4-bit quantization on glm-4v-9b - a few more GB of VRAM, far fewer tears.

CategoryGLM4Wrapper

Inputs (10)

NameTypeDefaultDescription
GLMPipelineGLMPipelineProvide a GLM-4 pipeline.
promptSTRINGProvide a base prompt to enhance. Can be empty if image is provided and glm-4v-9b, glm-4v-9b-gptq-4bit or glm-4v-9b-gptq-3bit model is chosen.
max_new_tokensINT200Limit the number of output tokens
temperatureFLOAT0.10Temperature parameter for sampling
top_kINT40Top-k parameter for sampling
top_pFLOAT0.70Top-p parameter for sampling
repetition_penaltyFLOAT1.10Repetition penalty for sampling
unload_modelBOOLEANfalseUnload the model after use to free up memory
seedINT420–4294967295
imageoptIMAGEProvide an image to enhance the prompt. Only supported for glm-4v-9b, glm-4v-9b-gptq-4bit and glm-4v-9b-gptq-3bit models.

Outputs (1)

NameTypeDescription
enhanced_promptSTRING