Qwen2 Run Inference
Ask Qwen2-VL what's in your image, mid-workflow
- image
- qwen2_model
- image
- caption
The other half of ComfyUI-ARZUMATA-Qwen2's vision pipeline. "Qwen2 Run Inference" takes the QWEN2MODEL object from the loader, an image, and a text prompt, and hands back the model's answer as a string - plus the original image, passed through untouched. That pass-through is the quietly useful part: you can drop this node into the middle of a graph, have it caption whatever flows past, and keep the pipeline moving without rerouting wires.
Why you'd bother
Batch captioning inside the graph, mostly. Feed it a stream of images (say, a dataset you're about to train a LoRA on), get natural-language descriptions back, and write them next to the images. Qwen2-VL writes sentences rather than comma-separated tags, which is exactly what the newer LLM-encoder generation models want for training captions - the same job JoyCaption and Florence 2 do, just with a Qwen model you already know how to load. If your target base is an anime tag model, this is the wrong tool; that's WD14 territory.
How it works
Under the hood the node builds a chat message - your image plus your text_input - converts the image to a base64 data-URI (using the same helper as the pack's Image2Base64 node), runs it through the Qwen chat template, and calls model.generate with the sampling settings you picked. Then it trims the prompt tokens off the output and decodes the rest. The min_pixels and max_pixels inputs control how the image gets resized before it goes in: they're pixel counts scaled by 28×28 internally, and the model clips the image to keep it inside that range while holding aspect ratio. Small range = faster, less VRAM, less detail. Bigger = sharper reading, costlier.
The inputs that matter
Required, you can't skip these:
- image - any IMAGE tensor.
- qwen2_model - from Qwen2ModelLoader.
- text_input - the prompt, default
"Describe this image in great detail in one paragraph."It's multiline, so go ahead and write a whole instruction.
The optional knobs are the standard LLM sampling set, and the tooltips are the author's own words, so trust them: max_new_tokens (512 default, up to a million), temperature (0.7 - higher, more varied), top_p (0.9), min_p (0), top_k (0, meaning disabled), repetition_penalty (1). Defaults are sane. Leave them alone until output quality actually bugs you.
Two toggles do the real work for this node's actual use case:
- keep_model_loaded - defaults to false, meaning the model gets offloaded and VRAM cache emptied after every run. For a batch, flip it on, or you pay the reload cost per image.
- always_generate_captions - this is the one that saves you from ComfyUI's caching. ComfyUI skips re-running a node whose inputs haven't changed, which is great until you're captioning a changing stream of images and it decides nothing happened. Set this and it re-runs every time.
Outputs
- caption - the STRING the model produced. Wire it to a text-save node or anything that eats strings.
- image - the input image passed straight through, so your workflow doesn't dead-end here.
Gotchas
First inference on a fresh model is slow: the weights load into VRAM that run. If your captions stop updating, check always_generate_captions. If output reads robotic, nudge temperature up; if it repeats itself, repetition_penalty slightly above 1. And the usual Qwen-in-ComfyUI warning applies - the model is a several-gigabyte download that happens on first use, so a "hang" on the first run is usually just the download happening in the console.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| qwen2_model | QWEN2MODEL | — | |
| text_input | STRING | Describe this image in great detail in one paragraph. | — |
| keep_model_loadedopt | BOOLEAN | false | — |
| always_generate_captionsopt | BOOLEAN | false | — |
| max_new_tokensopt | INT | 5121–1000000 | Max New Tokens maximum length of the newly generated generated text.If explicitly set to None it will be the model's max context length minus input length. |
| temperatureopt | FLOAT | 0.70–2 | This setting influences the variety in the model's responses. Lower values lead to more predictable and typical responses, while higher values encourage more diverse and less common responses. At 0, the model always gives the same response for a given input. |
| top_popt | FLOAT | 0.90–1 | This setting limits the model's choices to a percentage of likely tokens: only the top tokens whose probabilities add up to P. A lower value makes the model's responses more predictable, while the default setting allows for a full range of token choices. Think of it like a dynamic Top-K. |
| min_popt | FLOAT | 0.00–1 | Represents the minimum probability for a token to be considered, relative to the probability of the most likely token. (The value changes depending on the confidence level of the most probable token.) If your Min-P is set to 0.1, that means it will only allow for tokens that are at least 1/10th as probable as the best possible option. |
| top_kopt | INT | 00–2048 | This limits the model's choice of tokens at each step, making it choose from a smaller set. A value of 1 means the model will always pick the most likely next token, leading to predictable results. By default this setting is disabled, making the model to consider all choices. |
| repetition_penaltyopt | FLOAT | 1.00.1–5 | Helps to reduce the repetition of tokens from the input. A higher value makes the model less likely to repeat tokens, but too high a value can make the output less coherent (often with run-on sentences that lack small words). Token penalty scales based on original token's probability. |
| min_pixelsopt | INT | 2564–1280 | Images will be resized to maintain their aspect ratio within the range of min_pixels and max_pixels |
| max_pixelsopt | INT | 12804–16384 | Images will be resized to maintain their aspect ratio within the range of min_pixels and max_pixels |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| caption | STRING | — |