{"record":{"id":"ad7a35f66a25ab84","repo":"invoke-ai/InvokeAI","slug":"latents-or-noise-must-be-provided","errorCode":null,"errorMessage":"'latents' or 'noise' must be provided!","messagePattern":"'latents' or 'noise' must be provided!","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/denoise_latents.py","lineNumber":845,"sourceCode":"        Expected workflows:\n        - Text-to-Image Denoising: `noise` is provided, `latents` is not. `latents` is initialized to zeros.\n        - Image-to-Image Denoising: `noise` and `latents` are both provided.\n        - Text-to-Image SDXL Refiner Denoising: `latents` is provided, `noise` is not.\n        - Image-to-Image SDXL Refiner Denoising: `latents` is provided, `noise` is not.\n\n        NOTE(ryand): I wrote this docstring, but I am not the original author of this code. There may be other workflows\n        I haven't considered.\n        \"\"\"\n        noise = None\n        if noise_field is not None:\n            noise = context.tensors.load(noise_field.latents_name)\n\n        if latents_field is not None:\n            latents = context.tensors.load(latents_field.latents_name)\n        elif noise is not None:\n            latents = torch.zeros_like(noise)\n        else:\n            raise ValueError(\"'latents' or 'noise' must be provided!\")\n\n        if noise is not None and noise.shape[1:] != latents.shape[1:]:\n            raise ValueError(f\"Incompatible 'noise' and 'latents' shapes: {latents.shape=} {noise.shape=}\")\n\n        # The seed comes from (in order of priority): the noise field, the latents field, or 0.\n        seed = 0\n        if noise_field is not None and noise_field.seed is not None:\n            seed = noise_field.seed\n        elif latents_field is not None and latents_field.seed is not None:\n            seed = latents_field.seed\n        else:\n            seed = 0\n\n        return seed, noise, latents\n\n    def invoke(self, context: InvocationContext) -> LatentsOutput:\n        if os.environ.get(\"USE_MODULAR_DENOISE\", False):\n            return self._new_invoke(context)","sourceCodeStart":827,"sourceCodeEnd":863,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/denoise_latents.py#L827-L863","documentation":"prepare_noise_and_latents needs a starting latent tensor: either an explicit `latents` field (image-to-image / img2img continuation) or a `noise` tensor (txt2img, from which zero latents are derived). If both are absent it cannot construct the initial sample and raises this error.","triggerScenarios":"Invoking DenoiseLatents with both `latents` and `noise` inputs unconnected/None — e.g. a graph where neither a NoiseInvocation output nor latents from VAE/previous denoise are wired in.","commonSituations":"Incomplete graphs in the canvas/editor where the noise node was deleted; API calls omitting both fields; copy-pasted partial workflows missing the noise branch.","solutions":["Connect a Noise invocation (with seed) to the DenoiseLatents `noise` input for txt2img","Or supply `latents` (e.g. from a VAE-encode or previous DenoiseLatents output) for img2img","Ensure both fields aren't accidentally set to null in a JSON-built graph"],"exampleFix":"// before\nDenoiseLatents(...)  # noise and latents both None\n// after\nnoise = NoiseInvocation(seed=42)\ndenoise = DenoiseLatents(noise=noise, ...)","handlingStrategy":"validation","validationCode":"if latents_field is None and noise is None:\n    raise ValueError(\"Provide either a noise field (txt2img) or a latents field (img2img) before invoking\")","typeGuard":"def has_init_sample(latents_field, noise) -> bool:\n    return latents_field is not None or noise is not None","tryCatchPattern":"try:\n    out = invocation.invoke(context)\nexcept ValueError as e:\n    if \"'latents' or 'noise' must be provided\" in str(e):\n        invocation.noise = NoiseInvocation(seed=0)\n        out = invocation.invoke(context)\n    else:\n        raise","preventionTips":["Always wire a Noise node into DenoiseLatents for txt2img graphs","Validate graph completeness (all required edges present) before execution","Don't strip the noise branch when editing imported workflows"],"tags":["python","valueerror","latents","missing-input","stable-diffusion"],"backgroundTag":"missing-required-input","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}