{"record":{"id":"b5b5c92619bd3300","repo":"invoke-ai/InvokeAI","slug":"denoising-start-should-be-0-when-initial-latents-a-b5b5c9","errorCode":null,"errorMessage":"denoising_start should be 0 when initial latents are not provided.","messagePattern":"denoising_start should be 0 when initial latents are not provided\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/krea2_denoise.py","lineNumber":373,"sourceCode":"                device,\n            )\n            neg_prompt_embeds = neg_extension.regional_text_conditioning.prompt_embeds\n\n        # Load initial latents (img2img).\n        init_latents = context.tensors.load(self.latents.latents_name) if self.latents else None\n        if init_latents is not None:\n            init_latents = init_latents.to(device=device, dtype=inference_dtype)\n            if init_latents.dim() == 5:\n                init_latents = init_latents.squeeze(2)\n\n        noise = self._get_noise(self.height, self.width, inference_dtype, device, self.seed)\n\n        if init_latents is not None:\n            s_0 = sigmas_sched[0].item()\n            latents = s_0 * noise + (1.0 - s_0) * init_latents\n        else:\n            if self.denoising_start > 1e-5:\n                raise ValueError(\"denoising_start should be 0 when initial latents are not provided.\")\n            latents = noise\n\n        # Pack latents into 2x2 patches: (B, C, H, W) -> (B, grid_h*grid_w, C*4).\n        latents = pack_latents(latents, 1, KREA2_LATENT_CHANNELS, latent_height, latent_width)\n\n        # Position ids: text tokens at origin, image tokens carry their grid coords.\n        text_seq_len = pos_prompt_embeds.shape[1]\n        position_ids = prepare_position_ids(text_seq_len, grid_height, grid_width, device)\n        # The negative prompt can tokenize to a different length than the positive prompt, so it needs its\n        # own position ids. Reusing the positive ids would leave the rotary embedding (text + image tokens)\n        # a different length than the uncond query sequence and crash in the transformer's apply_rotary_emb.\n        neg_position_ids = (\n            prepare_position_ids(neg_prompt_embeds.shape[1], grid_height, grid_width, device)\n            if neg_prompt_embeds is not None\n            else None\n        )\n\n        # Inpaint extension operates in 4D, so unpack/repack around each merge.","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/krea2_denoise.py#L355-L391","documentation":"Without initial latents, denoising starts from pure noise at sigma_0, which corresponds to denoising_start == 0. `_run_diffusion` raises this ValueError when no init latents are supplied but denoising_start is greater than a small epsilon (1e-5), because skipping the early steps requires an initial latent to start from.","triggerScenarios":"Running the krea2_denoise invocation in pure txt2img mode (latents=None) with denoising_start > 1e-5 — e.g. a refiner-style start fraction applied without an img2img latent input.","commonSituations":"Users copying refiner settings (denoising_start=0.7) onto a txt2img graph; template workflows that enable a start fraction but lack the image-to-latents branch; scripts setting start values unconditionally.","solutions":["Set denoising_start to 0 when no initial latents are provided.","Provide initial latents (VAE Encode of an image) if a nonzero denoising_start is intended (img2img mode).","Guard caller code: only apply the refiner start fraction when init latents exist."],"exampleFix":"// before: txt2img with a refiner start\ndenoise = Krea2Denoise(latents=None, denoising_start=0.7, denoising_end=1.0)\n// after\ndenoise = Krea2Denoise(latents=None, denoising_start=0.0, denoising_end=1.0)\n# or wire latents=vae_encode.latents for img2img","handlingStrategy":"validation","validationCode":"if latents is None and denoising_start > 1e-5:\n    raise ValueError(\"Set denoising_start=0 for txt2img, or supply initial latents for img2img.\")","typeGuard":"def start_matches_mode(latents, denoising_start: float) -> bool:\n    return latents is not None or denoising_start <= 1e-5","tryCatchPattern":"try:\n    out = invoke_krea2_denoise(latents=latents, denoising_start=start)\nexcept ValueError as e:\n    if \"denoising_start should be 0\" in str(e):\n        out = invoke_krea2_denoise(latents=latents, denoising_start=0.0, denoising_end=end)\n    else:\n        raise","preventionTips":["Only apply refiner-style start fractions when an init-latents branch exists.","Reset denoising_start to 0 when switching a graph from img2img to txt2img.","Gate start-fraction settings behind the presence of an input image."],"tags":["invokeai","krea2","denoising-range","validation"],"backgroundTag":"invalid-parameter-combination","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}