Nodes/GLM-4V Image Descriptor/GLM-4V Batch Generate
ComfyUI Node

GLM-4V Batch Generate

Caption a whole folder of images with GLM-4V Batch Generate

By linjian-ufo·Created about a year ago·Updated about a year ago· 5
GLM-4V Batch Generate
    • batch_results
    • statistics
    image_folder_pathC:/path/to/your/images
    promptdescribe this image,Describe in long sentence form, without using Markdown format.
    model_nameglmv4_4bit
    image_extensionsjpg,jpeg,png,bmp,tiff,webp
    max_images10
    save_resultstrue
    output_formatTXT
    unload_policyAfter 5 mins

    Point a single-image captioner at a folder of a few hundred images and you'll be there all day. GLM-4V Batch Generate exists to solve exactly that: you give it a directory, it runs Zhipu's GLM-4V vision model over every image inside, and drops a .txt file with the same base name next to each one. sunset_beach.jpg becomes sunset_beach.txt. That's the headline feature, and for captioning a training set it's the whole game.

    It's the batch sibling to Glm4vNode in the same linjian-ufo/ComfyUI_GLM4V_voltspark pack - same model, same mechanism, one extra layer of folder handling. The model is the open MIT-licensed GLM-4V from Zhipu/Z.ai (the Tsinghua spin-off behind CogVideoX), so everything runs locally with no API key and no filter. In the natural-language captioning space, people typically reach for JoyCaption or Florence 2; GLM-4V is the "also great, and it's a full chat model" alternative that holds its own. Because it writes sentences rather than Danbooru tags, it's the right tool when your destination is an LLM-encoder checkpoint like Flux - the exact opposite of the WD14 tagger workflow you'd use for Illustrious or Pony.

    How it works

    Under the hood it's honest about its laziness: it creates a Glm4vNode internally and calls its generate() per image while forcing unload_policy to Never for the loop, so the ~6.7GB model loads once, not per file. It globs the folder for the extensions you list (case-insensitive), caps the count at max_images, converts each image to a tensor, and records per-file status, description, and processing time. With save_results on, it writes two things into that same folder: the same-name .txt per image, and a combined timestamped results file in your chosen format. Output is greedy, deterministic, up to 8192 tokens.

    The inputs that matter

    • image_folder_path - the one that's obviously load-bearing. Absolute path to your images; the node fails cleanly if it doesn't exist.
    • image_extensions - defaults to jpg,jpeg,png,bmp,tiff,webp. Comma-separated; it matches both cases.
    • max_images - a hard cap (1–1000, default 10). Bump it up before you run, or you'll caption ten images and wonder where the rest went. Remember the model loads once, so batches are cheap once warm.
    • save_results and output_format - output_format (TXT/JSON/CSV) controls the combined results file; the same-name .txt files are always written regardless.
    • prompt, model_name, unload_policy - same as the single node, with the batch default on unload_policy being After 5 mins rather than Always, which is the sane choice here.

    Outputs are two STRINGs: batch_results (per-file status + description, for wiring into a Save Text node or log) and statistics (totals, success/failure counts, average seconds per image).

    Installing it

    It's the same pack as Glm4vNode, so the install is identical:

    cd ComfyUI/custom_nodes
    git clone https://github.com/linjian-ufo/ComfyUI_GLM4V_voltspark
    pip install -r ComfyUI_GLM4V_voltspark/requirements.txt
    

    or just search "GLM-4V" in ComfyUI Manager. Dependencies: torch, transformers==4.54.0 (pinned - beware it downgrading a newer env), accelerate, bitsandbytes, Pillow, numpy, sentencepiece, protobuf. And the same gotcha as the single node: the README claims the model auto-downloads from Hugging Face, but the code actually raises FileNotFoundError if ComfyUI/models/glmv4_4bit/ isn't already on disk. Download the weights yourself and drop the folder there before running.

    Where people get burned

    • It writes into your source folder. Same-name .txt files and the combined results file land right next to the images. Point it at a folder you're fine having written into - don't aim it at your precious originals.
    • CUDA-only, like its sibling; no Macs or CPU mode. It'll error out clearly if it can't find a GPU.
    • VRAM. The 4-bit model is ~6.7GB, and if you're short the code auto-falls back to NF4 quantization with CPU offload. That works, but it's slow - the full-precision GLM-4.1V-9B-Thinking option is roughly double the footprint, so don't pick it on a small card.
    • Individual failures don't kill the batch - they're logged with status: error in the results and the loop keeps going. Check statistics at the end rather than assuming silence means success.
    CategoryGLM4V

    Inputs (8)

    NameTypeDefaultDescription
    image_folder_pathSTRINGC:/path/to/your/images
    promptSTRINGdescribe this image,Describe in long sentence form, without using Markdown format.
    model_nameCOMBOglmv4_4bit2 options: glmv4_4bit, GLM-4.1V-9B-Thinking
    image_extensionsSTRINGjpg,jpeg,png,bmp,tiff,webp
    max_imagesINT101–1000
    save_resultsBOOLEANtrue
    output_formatCOMBOTXT3 options: TXT, JSON, CSV
    unload_policyCOMBOAfter 5 mins6 options: Always, Never, After 1 min, After 2 mins, After 5 mins, After 10 mins

    Outputs (2)

    NameTypeDescription
    batch_resultsSTRING
    statisticsSTRING