{"record":{"id":"b9c9a2d55c58075d","repo":"invoke-ai/InvokeAI","slug":"noise-type-noise-width-and-height-must-be-a-mult","errorCode":null,"errorMessage":"{noise_type} noise width and height must be a multiple of {multiple_of}","messagePattern":"(.+?) noise width and height must be a multiple of (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/latent_noise.py","lineNumber":19,"sourceCode":"from typing import Literal\n\nimport torch\n\nfrom invokeai.app.invocations.constants import LATENT_SCALE_FACTOR\nfrom invokeai.backend.util.devices import TorchDevice\n\nLatentNoiseType = Literal[\"SD\", \"FLUX\", \"FLUX.2\", \"SD3\", \"CogView4\", \"Z-Image\", \"Anima\"]\n\n\ndef validate_noise_dimensions(noise_type: LatentNoiseType, width: int, height: int) -> None:\n    multiple_of = 8\n    if noise_type in (\"FLUX\", \"FLUX.2\", \"SD3\", \"Z-Image\"):\n        multiple_of = 16\n    elif noise_type == \"CogView4\":\n        multiple_of = 32\n\n    if width % multiple_of != 0 or height % multiple_of != 0:\n        raise ValueError(f\"{noise_type} noise width and height must be a multiple of {multiple_of}\")\n\n\ndef get_expected_noise_shape(\n    noise_type: LatentNoiseType,\n    width: int,\n    height: int,\n) -> tuple[int, ...]:\n    validate_noise_dimensions(noise_type, width, height)\n\n    if noise_type == \"SD\":\n        return (1, 4, height // LATENT_SCALE_FACTOR, width // LATENT_SCALE_FACTOR)\n    if noise_type == \"FLUX\":\n        return (1, 16, height // LATENT_SCALE_FACTOR, width // LATENT_SCALE_FACTOR)\n    if noise_type == \"FLUX.2\":\n        return (1, 32, height // LATENT_SCALE_FACTOR, width // LATENT_SCALE_FACTOR)\n    if noise_type == \"SD3\":\n        return (1, 16, height // LATENT_SCALE_FACTOR, width // LATENT_SCALE_FACTOR)\n    if noise_type == \"CogView4\":","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/latent_noise.py#L1-L37","documentation":"validate_noise_dimensions enforces model-specific pixel-dimension constraints before generating latent noise: FLUX/FLUX.2/SD3/Z-Image require width and height to be multiples of 16, CogView4 multiples of 32, and other types multiples of 8 (the default). If width % multiple_of or height % multiple_of is nonzero, a ValueError naming the noise type and required multiple is raised. This ensures the latent shapes produced by dividing by LATENT_SCALE_FACTOR are valid for the transformer's patching scheme.","triggerScenarios":"Calling validate_noise_dimensions, get_expected_noise_shape, or generate_noise_tensor with width/height not divisible by the model's required multiple — e.g. width=1025 for FLUX (needs multiple of 16) or width=1000 for CogView4 (needs multiple of 32); typically from user-entered image dimensions or a workflow with an arbitrary resize node upstream.","commonSituations":"Users type odd resolutions in the UI (e.g. 1366x768 for FLUX); a FLUX workflow fed dimensions from an SD-sized default (like 512) is fine, but e.g. 520x520 is not; CogView4 workflows reusing FLUX-sized dimensions that are multiples of 16 but not 32.","solutions":["Round width and height down (or to nearest) to the required multiple before invoking: 16 for FLUX/FLUX.2/SD3/Z-Image, 32 for CogView4, 8 otherwise.","Insert a resize/crop step in the workflow so the noise dimensions match the model constraint.","If writing code, compute dimensions as (width // multiple_of) * multiple_of before calling generate_noise_tensor."],"exampleFix":"// before\ngenerate_noise_tensor(\"FLUX\", 1026, 770, seed, device, dtype)\n// after\nwidth = (1026 // 16) * 16   # 1024\nheight = (770 // 16) * 16   # 768\ngenerate_noise_tensor(\"FLUX\", width, height, seed, device, dtype)","handlingStrategy":"validation","validationCode":"def check_dims(noise_type: str, width: int, height: int) -> None:\n    multiple_of = 8\n    if noise_type in (\"FLUX\", \"FLUX.2\", \"SD3\", \"Z-Image\"):\n        multiple_of = 16\n    elif noise_type == \"CogView4\":\n        multiple_of = 32\n    assert width % multiple_of == 0 and height % multiple_of == 0, \\\n        f\"{noise_type} requires width/height multiples of {multiple_of}, got {width}x{height}\"","typeGuard":null,"tryCatchPattern":"try:\n    noise = generate_noise_tensor(noise_type, width, height, seed, device, dtype)\nexcept ValueError as e:\n    if \"must be a multiple of\" in str(e):\n        mult = int(str(e).rsplit(\" \", 1)[-1])\n        width, height = (width // mult) * mult, (height // mult) * mult\n        noise = generate_noise_tensor(noise_type, width, height, seed, device, dtype)\n    else:\n        raise","preventionTips":["Use the UI's resolution presets, which already satisfy each model's multiple-of constraint.","Snap custom resolutions: multiples of 8 for SD, 16 for FLUX/FLUX.2/SD3/Z-Image, 32 for CogView4.","When piping dimensions between nodes, add a round-down step for the active model type.","Validate user-supplied dimensions at workflow input time, before noise generation."],"tags":["validation","dimensions","noise","configuration"],"backgroundTag":"dimension-not-multiple-of-required-size","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}