comfyui-krea2-visualref
Experimental Krea2 visual-token reference conditioning nodes for ComfyUI.
ComfyUI-Krea2-VisualRef
Experimental style-reference conditioning for Krea2 in ComfyUI.
This plugin does not implement Krea's official product-side style reference system. It uses Krea2's Qwen3-VL-4B conditioning path to test whether reference images can influence Krea2 generations through a combination of extracted style text and visual tokens.
Nodes
Krea2 Visual Reference Encode
Inputs:
clip: a Krea2 text encoder loaded with ComfyUICLIPLoadertypekrea2prompt: the generation promptstyle_image: optional reference image. If omitted, the node falls back to ComfyUI nativeclip.tokenize(prompt)text conditioning.strength: visual-reference strength from0.0to1.0, with decimal values supported.0.0uses native text-only conditioning;1.0is full visual-reference weight.visual_onlyuses a2.5power response curve (effective_strength = strength^2.5) so mid values reduce visual dominance.auto_style_text_and_visualkeeps the text style lock atstrength=1.0and applies the directstrengthvalue to the visual-token conditioning.style_text_mode:auto_style_text_only,auto_style_text_and_visual, orvisual_only. The defaultauto_style_text_onlyfirst splits a batchedstyle_imageinto individual reference images, asks Qwen3-VL to describe each transferable style with fixed structured fields, adds algorithmic palette hints computed from each image tensor, then runs a second text-only Qwen3-VL pass to synthesize one strongerTRANSFERABLE STYLE LOCKfor conditioning. The style-description length and seed are fixed internally for deterministic behavior.auto_style_text_and_visualalso keeps all split reference images in the final visual-token conditioning path.visual_onlykeeps the older image-token behavior and does not generate a style description. It returns only the visual-token conditioning instead of merging an extra native text conditioning item, sostrength=1.0is not averaged with a separate text-only condition. Its visual-token guidance is intentionally medium-neutral, uses a style-only system prompt instead of Krea2 native image-description system prompt, adds stronger wording at highstrength, and does not enumerate cartoon, anime, comic, or other unrelated style words. For photographic references it explicitly asks for real-camera photographic realism, natural optics, material realism, and physically plausible light.placement:before_promptorafter_prompt
Output:
CONDITIONING
When style_image is connected and style_text_mode is auto_style_text_only, the node extracts style text and uses text-only conditioning. When style_text_mode is auto_style_text_and_visual, the node does these things:
- splits batched
style_imageinput into individual reference images; - calls
clip.tokenize(style_analysis_prompt, images=[single_reference])andclip.generate(...)once per reference image to extract structured style notes with signature cues, palette, line shape, lighting, texture, rendering medium, and negative subject categories; - computes an algorithmic palette hint from each reference image tensor;
- for multiple references, runs a text-only fusion pass that creates one style lock with a hierarchy and approximate recipe weights, preserving at least one non-subject cue from every reference instead of averaging them into generic neutral wording;
- encodes the original prompt plus the style lock as native text conditioning at
strength=1.0; - in
auto_style_text_and_visual, constructs a full Krea2 chat template with one Qwen3-VL image block per split reference image, callsclip.tokenize(..., images=style_images), and encodes that visual-reference conditioning at directstrength.
When style_text_mode is auto_style_text_only, the final visual-token step is skipped, which is useful when the image token leaks reference subjects or objects into the output. When style_text_mode is visual_only, the node skips step 1 and returns only the visual-token conditioning for comparison with the older high-visual-weight behavior. When style_image is connected and strength is above 0.0, the generation prompt must be non-empty because it is embedded inside the visual-token template. When style_image is not connected, or strength is 0.0, the node behaves like native text encoding by calling clip.tokenize(prompt) directly.
Krea2 Style Prompt Encode
This helper node extracts a text style description from a reference image and returns text-only conditioning plus the final style prompt string. It is useful for inspecting whether Qwen3-VL is describing style or accidentally describing the reference subject. The main Krea2 Visual Reference Encode node now includes the same extraction path by default.
Krea2 Visual Reference Debug
Reports:
- conditioning item count
- tensor shape
- sequence length
- feature width
- whether the width matches Krea2's expected
30720 - attention-mask shape
- metadata written by
Krea2 Visual Reference Encode, includingstyle_text_mode, final unifiedstyle_text, raw per-reference aggregatestyle_text_raw, per-referencestyle_text_raw_items, computedpalette_hint, per-referencepalette_hint_items,style_text_fusion,style_image_count,strength, andeffective_strength
If the conditioning did not come from this plugin, the debug node still reports shape information, but it cannot reliably infer the image-token span.
Install
Place this folder here:
E:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-Krea2-VisualRef
Restart ComfyUI after installation.
Basic Workflow
- Load Krea2 model weights as usual.
- Load
Qwen3-VL-4Btext encoder usingCLIPLoaderwith typekrea2. - Connect the Krea2
CLIPtoKrea2 Visual Reference Encode. - Connect a reference image to
style_image. - Start with
style_text_mode=auto_style_text_onlywhen the reference image subject is leaking into the output. Useauto_style_text_and_visualonly when you still want the final visual-token influence, andvisual_onlywhen comparing against the older behavior. - Start with
strength=0.5or0.75; lower it if the reference image subject overwhelms the prompt or causes collage/panel-like output. - Use
placement=before_promptfirst, then compareafter_prompt. - Use the output conditioning as the positive conditioning for Krea2 sampling.
- Add
Krea2 Visual Reference Debugand check whetherstyle_text_rawdescribes style rather than subject, text, logos, pose, or layout, and whetherpalette_hintmatches the reference image palette.
Development Checks
Run from this plugin directory:
E:\ComfyUI_windows_portable\python_embeded\python.exe -B -m pytest -q --assert=plain
See VALIDATION.md for the full manual ComfyUI acceptance checklist.
Validation Suggestions
Use a fixed prompt, seed, sampler, steps, CFG, resolution, and Krea2 checkpoint. Change only the reference image or visual-reference settings.
Recommended comparisons:
- text-only baseline, generated either with the normal Krea2 text-conditioning path or this VisualRef node with
style_imageunconnected style_text_mode=auto_style_text_onlyversusstyle_text_mode=auto_style_text_and_visualversusstyle_text_mode=visual_only- strong style reference image with several
strengthvalues such as0.25,0.5,0.75, and1.0 before_promptversusafter_prompt- Debug
style_text_rawandpalette_hint; ifstyle_text_rawmentions the reference subject, objects, text, logos, pose, or layout, the generated style prompt can still leak reference content
Expected first milestone:
style image changes Krea2 conditioning
conditioning feature width is 30720
Debug reports a style_text in auto_style_text_only or auto_style_text_and_visual mode
generation changes under fixed seed
Image quality and true style fidelity are experimental and not guaranteed.
Limitations
- The auto style-text path uses the loaded Qwen3-VL CLIP wrapper's
generate(...)anddecode(...); it depends on the local ComfyUI/Krea2 implementation exposing those methods. - The extracted
style_text_raw_itemsmay still mention subject matter or objects. If they do, evenauto_style_text_onlycan leak reference content into the final generation. The algorithmicpalette_hint_itemscan reinforce palette and contrast, but they do not understand semantic style by themselves. Multi-image fusion applies to automatic style text extraction, andauto_style_text_and_visualnow passes one final visual-token placeholder per split batch image. strengthis experimental and uses ComfyUI conditioning metadata; it is not an official Krea reference-strength control.visual_onlyusesstrength^2.5to avoid overpowering the prompt at mid values, whileauto_style_text_and_visualuses the directstrengthvalue for its final visual conditioning so the visual branch is not weakened twice.- The plugin depends on ComfyUI's current Krea2/Qwen3-VL image-token support.
- Krea2 may not have been trained to interpret an image token as a style reference.
- Subject leakage, noisy conditioning, no visible effect, or fallback toward Krea2's default style bias are all possible. If
style_textlooks clean but the output still copies the reference subject, compareauto_style_text_onlyagainstauto_style_text_and_visual; the visual-token path is the likely leakage source.