π Qwen Image Scale
Dual-output scaling so Qwen-VL and your sampler agree on the image
- image
- mask
- image_vl
- image_latent
- mask
- latent_width
- latent_height
- debug_text
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 byvl_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. Thevl_ignore_latent_*toggles exist because the latent is already letterboxed/cropped, so double-processing would be a bug.upscale_methodoptions (area,bicubic,lanczosβ¦) - only matter if you're upscaling rather than downscaling;lanczosfor the latent is the usual choice.mask- optional; resized alongsideimage_latentwith 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.
Inputs (19)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | β | |
| aspect_ratio_modeopt | COMBO | auto | Auto: Automatically find closest preferred aspect ratio to input image. Manual: Choose specific preferred ratio (ignores input aspect). |
| preferred_aspect_ratioopt | COMBO | 16:9 (Panorama) | Manually select preferred aspect ratio (only used in manual mode). These ratios are optimized for QwenVL's training data. |
| vl_target_areaopt | INT | 1474563000β500000 | Target 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_byopt | INT | 321β256 | Ensures VL width and height are divisible by this number. Recommended: 32 for optimal AI processing. |
| latent_target_areaopt | INT | 17635843000β4500000 | Target 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_byopt | INT | 321β256 | Ensures latent width and height are divisible by this number. Recommended: 32 for VAE compatibility. Must achieve exact aspect match with VL. |
| latent_area_toleranceopt | FLOAT | 0.300.1β0.8 | Flexibility 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_sourceopt | BOOLEAN | true | VL 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_letterboxopt | BOOLEAN | true | When using Latent source, ignore vl_letterbox setting. Latent is already letterboxed if needed, prevents double padding. |
| vl_ignore_latent_cropopt | BOOLEAN | true | When using Latent source, ignore vl_crop setting. Latent is already cropped if needed, prevents double cropping. |
| vl_upscale_methodopt | COMBO | area | Resampling algorithm for VL. Area=best for downscaling (sharp), Lanczos=best for upscaling (smooth). Default 'area' optimal since VL is typically downscaled. |
| vl_cropopt | COMBO | disabled | How 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_letterboxopt | BOOLEAN | false | Add 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_methodopt | COMBO | lanczos | Resampling algorithm for latent. Lanczos=best for upscaling (smooth, high quality), Area=best for downscaling (sharp). Default 'lanczos' optimal since latent is usually upscaled. |
| latent_cropopt | COMBO | center | How 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_letterboxopt | BOOLEAN | false | Add black bars to latent instead of cropping. Enable to preserve entire input image with preferred aspect ratio. |
| debugopt | BOOLEAN | true | Show detailed info: aspect ratio selection (auto/manual), preferred ratio match quality, dimensions, tolerance checks, and pixel alignment status. |
| maskopt | MASK | Optional mask to scale alongside image_latent. Will be resized to match latent dimensions using bilinear interpolation. |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| image_vl | IMAGE | β |
| image_latent | IMAGE | β |
| mask | MASK | β |
| latent_width | INT | β |
| latent_height | INT | β |
| debug_text | STRING | β |