Comfy-Org/ComfyUI · error · ValueError
Attempting to resize to a 0 x 0 image. Resized height should
Error message
Attempting to resize to a 0 x 0 image. Resized height should be divisible by {side_mult}. What it means
In comfy/text_encoders/gemma4.py, _get_aspect_ratio_preserving_size computes a resize that fits an image into a max_patches patch budget while keeping aspect ratio, rounding each side down to a multiple of side_mult = pooling_kernel_size * patch_size. If the source image is so small (or the budget so tight) that both rounded sides floor to 0, it raises this ValueError before attempting a 0x0 resize.
Source
Thrown at comfy/text_encoders/gemma4.py:1390
return x
class Gemma4AudioProjector(Gemma4RMSNormProjector):
def __init__(self, config, dtype=None, device=None, ops=None):
super().__init__(config.get("audio_output_proj_dims", 1536), config.get("text_hidden_size", 2560), dtype=dtype, device=device, ops=ops)
# Tokenizer and Wrappers
def _get_aspect_ratio_preserving_size(height, width, patch_size, max_patches, pooling_kernel_size):
target_px = max_patches * patch_size ** 2
factor = math.sqrt(target_px / (height * width))
side_mult = pooling_kernel_size * patch_size
target_height = math.floor(factor * height / side_mult) * side_mult
target_width = math.floor(factor * width / side_mult) * side_mult
if target_height == 0 and target_width == 0:
raise ValueError(f"Attempting to resize to a 0 x 0 image. Resized height should be divisible by {side_mult}.")
max_side_length = (max_patches // pooling_kernel_size ** 2) * side_mult
if target_height == 0:
target_height = side_mult
target_width = min(math.floor(width / height) * side_mult, max_side_length)
elif target_width == 0:
target_width = side_mult
target_height = min(math.floor(height / width) * side_mult, max_side_length)
if target_height * target_width > target_px:
raise ValueError(f"Resizing [{height}x{width}] to [{target_height}x{target_width}] exceeds the patch budget.")
return target_height, target_width
class Gemma4_Tokenizer():
tokenizer_json_data = None
prime_empty_thought = FalseView on GitHub (pinned to 1c6d8d45b3)
Solutions
- Upscale small inputs to at least a few multiples of patch_size * pooling_kernel_size (e.g. >= 128px on the short side) before feeding the encoder.
- Increase max_patches for the encoder config if it was lowered.
- Skip/replace degenerate images (near-zero dimensions) rather than sending them through the vision path.
Example fix
# before
image = Image.open('16x16_icon.png') # both sides floor to 0 -> ValueError
# after
if min(image.size) < 128:
image = image.resize((max(image.size[0], 128), max(image.size[1], 128)))
emb = tokenizer.encode_image(image) Defensive patterns
Strategy: validation
Validate before calling
side_mult = pooling_kernel_size * patch_size
assert height >= side_mult and width >= side_mult, f'image {height}x{width} too small; each side must be >= {side_mult}' Type guard
def is_gemma4_image_ok(h: int, w: int, patch: int, pool: int) -> bool:
side_mult = pool * patch
return h >= side_mult and w >= side_mult and h * w > 0 Prevention
- Reject or upscale sub-100px images before the vision encoder.
- Filter degenerate (near-zero dimension) images out of multimodal batches.
When it happens
Trigger: Passing tiny images (e.g. 8x8 or 16x4 pixels) to the Gemma4 vision encoder; a max_patches/patch config that makes factor < side_mult / max(side); extreme aspect ratios where the short side rounds to zero pixels.
Common situations: Thumbnail or icon-sized images in a multimodal workflow; placeholder/blank images generated at minimal resolution; custom configs that shrink the patch budget; division behavior when height or width is very small relative to the other.
Related errors
- Resizing [{height}x{width}] to [{target_height}x{target_widt
- gemma4: chunked prefill past the sliding window is not suppo
- INVALID_TAG_FILTER
- UNSUPPORTED_MEDIA_TYPE
- INVALID_BODY
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/b5878882f4fd5f88.
Report an issue: GitHub.