invoke-ai/InvokeAI · error · ValueError
'latents' or 'noise' must be provided!
Error message
'latents' or 'noise' must be provided!
What it means
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.
Source
Thrown at invokeai/app/invocations/denoise_latents.py:845
Expected workflows:
- Text-to-Image Denoising: `noise` is provided, `latents` is not. `latents` is initialized to zeros.
- Image-to-Image Denoising: `noise` and `latents` are both provided.
- Text-to-Image SDXL Refiner Denoising: `latents` is provided, `noise` is not.
- Image-to-Image SDXL Refiner Denoising: `latents` is provided, `noise` is not.
NOTE(ryand): I wrote this docstring, but I am not the original author of this code. There may be other workflows
I haven't considered.
"""
noise = None
if noise_field is not None:
noise = context.tensors.load(noise_field.latents_name)
if latents_field is not None:
latents = context.tensors.load(latents_field.latents_name)
elif noise is not None:
latents = torch.zeros_like(noise)
else:
raise ValueError("'latents' or 'noise' must be provided!")
if noise is not None and noise.shape[1:] != latents.shape[1:]:
raise ValueError(f"Incompatible 'noise' and 'latents' shapes: {latents.shape=} {noise.shape=}")
# The seed comes from (in order of priority): the noise field, the latents field, or 0.
seed = 0
if noise_field is not None and noise_field.seed is not None:
seed = noise_field.seed
elif latents_field is not None and latents_field.seed is not None:
seed = latents_field.seed
else:
seed = 0
return seed, noise, latents
def invoke(self, context: InvocationContext) -> LatentsOutput:
if os.environ.get("USE_MODULAR_DENOISE", False):
return self._new_invoke(context)View on GitHub (pinned to 0b6a024f2f)
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
Example fix
// before DenoiseLatents(...) # noise and latents both None // after noise = NoiseInvocation(seed=42) denoise = DenoiseLatents(noise=noise, ...)
Defensive patterns
Strategy: validation
Validate before calling
if latents_field is None and noise is None:
raise ValueError("Provide either a noise field (txt2img) or a latents field (img2img) before invoking") Type guard
def has_init_sample(latents_field, noise) -> bool:
return latents_field is not None or noise is not None Try / catch
try:
out = invocation.invoke(context)
except ValueError as e:
if "'latents' or 'noise' must be provided" in str(e):
invocation.noise = NoiseInvocation(seed=0)
out = invocation.invoke(context)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Incompatible 'noise' and 'latents' shapes: ${latents.shape=}
- Unexpected T2I-Adapter base model type: '${t2i_adapter_model
- Negative conditioning is required when guidance_scale > 1.0
- denoising_start must be 0 when no initial latents are provid
- Latents to blend must be the same size.
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/ad7a35f66a25ab84.
Report an issue: GitHub.