mudler/LocalAI · error · ValueError

width and height must be divisible by 16

Error message

width and height must be divisible by 16

What it means

Raised by validate_dimensions() in longcat-video when width or height is not a multiple of 16. Video diffusion models require dimensions aligned to the patch/VAE stride, hence the divisibility constraint enforced after range checks.

Source

Thrown at backend/python/longcat-video/longcat_utils.py:196

        return 1
    return 1 + math.ceil((frames - 93) / 80)


def avatar_segments_for_duration(duration_seconds, fps=25):
    if duration_seconds <= 0:
        return 1
    return avatar_segments_for_frames(math.ceil(duration_seconds * fps))


def validate_dimensions(width, height):
    width = width or 832
    height = height or 480
    if width < 256 or height < 256:
        raise ValueError("width and height must each be at least 256")
    if width > 1280 or height > 768:
        raise ValueError("width and height must not exceed 1280x768")
    if width % 16 != 0 or height % 16 != 0:
        raise ValueError("width and height must be divisible by 16")
    if width * height > 1280 * 768:
        raise ValueError("requested video dimensions exceed the 1280x768 pixel limit")
    return width, height

View on GitHub (pinned to 44413a9d06)

Solutions

  1. Round dimensions to the nearest multiple of 16 (e.g. 848 -> 832 or 848? use 832/848 = 16*52.5 no; use 832 or 864)
  2. Compute sizes as n * 16 when deriving from aspect ratio
  3. Use the defaults 832x480 which are already aligned

Example fix

# before
validate_dimensions(854, 480)  # 854 % 16 != 0 -> ValueError

# after
validate_dimensions(848, 480)   # 848 = 16*53
Defensive patterns

Strategy: validation

Validate before calling

def align16(v, default):
    v = v or default
    return max(256, (v // 16) * 16)

w = align16(request.width, 832)
h = align16(request.height, 480)
validate_dimensions(w, h)

Type guard

def is_div16(v) -> bool:
    return (v or 832) % 16 == 0

Try / catch

try:
    w, h = validate_dimensions(w, h)
except ValueError as err:
    return error_response(str(err), hint='round dimensions to multiples of 16')

Prevention

When it happens

Trigger: Calling validate_dimensions with any dimension not divisible by 16: 850x480, 832x475, 1000x600. Common because 'round' numbers like 500 or 1000 are not multiples of 16.

Common situations: Users entering arbitrary pixel sizes (854x480 widescreen, 1080-related values), or computing dimensions from aspect-ratio math that does not round to the 16-pixel grid.

Related errors


AI-assisted analysis of mudler/LocalAI@44413a9d06 (2026-08-15). Data as JSON: /api/errors/cc6797fd6cd987d9. Report an issue: GitHub.