{"record":{"id":"cc6797fd6cd987d9","repo":"mudler/LocalAI","slug":"width-and-height-must-be-divisible-by-16","errorCode":null,"errorMessage":"width and height must be divisible by 16","messagePattern":"width and height must be divisible by 16","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/python/longcat-video/longcat_utils.py","lineNumber":196,"sourceCode":"        return 1\n    return 1 + math.ceil((frames - 93) / 80)\n\n\ndef avatar_segments_for_duration(duration_seconds, fps=25):\n    if duration_seconds <= 0:\n        return 1\n    return avatar_segments_for_frames(math.ceil(duration_seconds * fps))\n\n\ndef validate_dimensions(width, height):\n    width = width or 832\n    height = height or 480\n    if width < 256 or height < 256:\n        raise ValueError(\"width and height must each be at least 256\")\n    if width > 1280 or height > 768:\n        raise ValueError(\"width and height must not exceed 1280x768\")\n    if width % 16 != 0 or height % 16 != 0:\n        raise ValueError(\"width and height must be divisible by 16\")\n    if width * height > 1280 * 768:\n        raise ValueError(\"requested video dimensions exceed the 1280x768 pixel limit\")\n    return width, height\n","sourceCodeStart":178,"sourceCodeEnd":200,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/python/longcat-video/longcat_utils.py#L178-L200","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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)","Compute sizes as n * 16 when deriving from aspect ratio","Use the defaults 832x480 which are already aligned"],"exampleFix":"# before\nvalidate_dimensions(854, 480)  # 854 % 16 != 0 -> ValueError\n\n# after\nvalidate_dimensions(848, 480)   # 848 = 16*53","handlingStrategy":"validation","validationCode":"def align16(v, default):\n    v = v or default\n    return max(256, (v // 16) * 16)\n\nw = align16(request.width, 832)\nh = align16(request.height, 480)\nvalidate_dimensions(w, h)","typeGuard":"def is_div16(v) -> bool:\n    return (v or 832) % 16 == 0","tryCatchPattern":"try:\n    w, h = validate_dimensions(w, h)\nexcept ValueError as err:\n    return error_response(str(err), hint='round dimensions to multiples of 16')","preventionTips":["Snap dimensions to a 16px grid before submitting","Compute from aspect ratio as n*16","Avoid 'round' decimal sizes like 500, 854, 1000"],"tags":["python","validation","dimensions","alignment","longcat-video"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}