Nodes/ComfyUI-ArchAi3d-Qwen/πŸ“ Qwen Image Scale
ComfyUI Node

πŸ“ Qwen Image Scale

Dual-output scaling so Qwen-VL and your sampler agree on the image

By amir84ferdosΒ·Created 11 months agoΒ·Updated 5 months agoΒ· 70
πŸ“ Qwen Image Scale
  • image
  • mask
  • image_vl
  • image_latent
  • mask
  • latent_width
  • latent_height
  • debug_text
β—„aspect_ratio_modeautoβ–Ί
β—„preferred_aspect_ratio16:9 (Panorama)β–Ί
β—„vl_target_area147456β–Ί
β—„vl_divisible_by32β–Ί
β—„latent_target_area1763584β–Ί
β—„latent_divisible_by32β–Ί
β—„latent_area_tolerance0.30β–Ί
β—„vl_use_latent_sourcetrueβ–Ί
β—„vl_ignore_latent_letterboxtrueβ–Ί
β—„vl_ignore_latent_croptrueβ–Ί
β—„vl_upscale_methodareaβ–Ί
β—„vl_cropdisabledβ–Ί
β—„vl_letterboxfalseβ–Ί
β—„latent_upscale_methodlanczosβ–Ί
β—„latent_cropcenterβ–Ί
β—„latent_letterboxfalseβ–Ί
β—„debugtrueβ–Ί

Every Qwen-VL editing workflow has a quiet mismatch buried in it: the vision encoder and the latent space want different image sizes. Qwen's encoder is happiest around 147K pixels at a divisible-by-32 dimension; your sampler wants something closer to 1.7MP so the edited result has real resolution. If you hand both paths the same image, one of them is working with the wrong size, and you get either mush or wasted context. ArchAi3D_Qwen_Image_Scale is the pack's original answer to that - the V1 of the scaler this repo revolves around.

How it works

It's a smart resize with a split personality. One input (image), and it computes two outputs with matching aspect ratios but different pixel budgets:

  • image_vl - sized for the Qwen-VL encoder (vl_target_area β‰ˆ 147K, divisible by vl_divisible_by = 32).
  • image_latent - sized for the sampling side (latent_target_area β‰ˆ 1.7MP, also divisible by 32 for VAE compatibility).

The key design choice: by default vl_use_latent_source is True, meaning the VL image is derived from the already-processed latent. That guarantees the encoder literally sees the pixels the sampler is about to denoise - pixel-perfect alignment instead of two independently-resized copies that quietly disagree.

aspect_ratio_mode = auto snaps to the closest of 24 preferred ratios tuned for Qwen (1:1, 2:3, 3:4, 16:9, 21:9, 9:21…); manual lets you force one. latent_area_tolerance (default 0.3) gives the algorithm room to pick dimensions that hit the aspect ratio within Β±30% of the target pixel count - that tolerance is what makes exact-ratio snapping possible.

Inputs worth setting

  • aspect_ratio_mode / preferred_aspect_ratio - the ratio that both outputs will match.
  • vl_use_latent_source - keep True unless you have a specific reason; this is the pixel-perfect guarantee.
  • vl_letterbox / latent_letterbox - add black bars to preserve the whole image instead of cropping. The vl_ignore_latent_* toggles exist because the latent is already letterboxed/cropped, so double-processing would be a bug.
  • upscale_method options (area, bicubic, lanczos…) - only matter if you're upscaling rather than downscaling; lanczos for the latent is the usual choice.
  • mask - optional; resized alongside image_latent with bilinear so a mask stays aligned if you're doing mask-guided edits.
  • debug - detailed console log of ratio selection and tolerance checks.

Outputs

image_vl, image_latent, mask, latent_width, latent_height, and debug_text. The width/height outputs feed an empty-latent or conditioning-size node so the sampler knows exactly what to build.

Install and the one thing to know

Same pack, same route:

cd ComfyUI/custom_nodes
git clone https://github.com/amir84ferdos/ComfyUI-ArchAi3d-Qwen.git
cd ComfyUI-ArchAi3d-Qwen && pip install -r requirements.txt

Or ComfyUI Manager β†’ search "ArchAi3d Qwen" β†’ restart. If you're starting fresh on a region-edit workflow, go straight to V2 instead - it does everything this node does and adds mask-based cropping plus stitch_data for pasting edits back. V1 is the simpler, no-region version, and it's the one you want if your whole image is the edit target. Both are free personal / paid commercial under the pack's license.

CategoryArchAi3d/Qwen/Image

Inputs (19)

NameTypeDefaultDescription
imageIMAGEβ€”
aspect_ratio_modeoptCOMBOautoAuto: Automatically find closest preferred aspect ratio to input image. Manual: Choose specific preferred ratio (ignores input aspect).
preferred_aspect_ratiooptCOMBO16:9 (Panorama)Manually select preferred aspect ratio (only used in manual mode). These ratios are optimized for QwenVL's training data.
vl_target_areaoptINT1474563000–500000Target pixel area for QwenVL output (e.g., 147456 = ~147K = 384Γ—384). VL dimensions are calculated using preferred aspect ratio to match QwenVL's optimal training ratios. QwenVL works best with ~150K pixels.
vl_divisible_byoptINT321–256Ensures VL width and height are divisible by this number. Recommended: 32 for optimal AI processing.
latent_target_areaoptINT17635843000–4500000Target pixel area for latent output (e.g., 1048576 = ~1M = ~1024Γ—1024). Latent dimensions will EXACTLY match VL's preferred aspect ratio while staying within tolerance range. Higher = better quality but slower.
latent_divisible_byoptINT321–256Ensures latent width and height are divisible by this number. Recommended: 32 for VAE compatibility. Must achieve exact aspect match with VL.
latent_area_toleranceoptFLOAT0.300.1–0.8Flexibility for latent pixel count (Β±%). Default 0.3 = Β±30%, allowing 700K-1.3M when target is 1M. Gives algorithm room to find dimensions that EXACTLY match VL aspect ratio while meeting divisibility constraints. Higher tolerance = easier to find perfect aspect match.
vl_use_latent_sourceoptBOOLEANtrueVL source selection. True (recommended): Use processed Latent as source for pixel-perfect alignment and guaranteed aspect match. False: Use original Input for traditional independent processing.
vl_ignore_latent_letterboxoptBOOLEANtrueWhen using Latent source, ignore vl_letterbox setting. Latent is already letterboxed if needed, prevents double padding.
vl_ignore_latent_cropoptBOOLEANtrueWhen using Latent source, ignore vl_crop setting. Latent is already cropped if needed, prevents double cropping.
vl_upscale_methodoptCOMBOareaResampling algorithm for VL. Area=best for downscaling (sharp), Lanczos=best for upscaling (smooth). Default 'area' optimal since VL is typically downscaled.
vl_cropoptCOMBOdisabledHow to handle aspect ratio mismatch. Usually keep disabled as VL aspect matches Latent exactly. NOTE: Ignored when vl_use_latent_source=True and vl_ignore_latent_crop=True.
vl_letterboxoptBOOLEANfalseAdd black bars to preserve exact aspect ratio. Usually keep disabled as VL aspect matches Latent exactly. NOTE: Ignored when vl_use_latent_source=True and vl_ignore_latent_letterbox=True.
latent_upscale_methodoptCOMBOlanczosResampling algorithm for latent. Lanczos=best for upscaling (smooth, high quality), Area=best for downscaling (sharp). Default 'lanczos' optimal since latent is usually upscaled.
latent_cropoptCOMBOcenterHow to handle aspect ratio mismatch for latent. Center (recommended): Crops input image to fill latent frame completely with preferred aspect ratio. Disabled: Stretches to fit (may distort).
latent_letterboxoptBOOLEANfalseAdd black bars to latent instead of cropping. Enable to preserve entire input image with preferred aspect ratio.
debugoptBOOLEANtrueShow detailed info: aspect ratio selection (auto/manual), preferred ratio match quality, dimensions, tolerance checks, and pixel alignment status.
maskoptMASKOptional mask to scale alongside image_latent. Will be resized to match latent dimensions using bilinear interpolation.

Outputs (6)

NameTypeDescription
image_vlIMAGEβ€”
image_latentIMAGEβ€”
maskMASKβ€”
latent_widthINTβ€”
latent_heightINTβ€”
debug_textSTRINGβ€”