ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

KSampler output on one branch is affected by the execution order of a separate, non-dependent branch

Open sirius422 opened this issue 5 months ago • 2 comments
trafficstars

Expected Behavior

The KSampler node should produce consistent output regardless of branch execution order

Actual Behavior

The images output by the KSampler show slight differences depending on the execution order of the parallel branches. I used Beyond Compare to compare the images. Blue pixels indicate differences within the tolerance range, red indicates differences exceeding the tolerance, and the black-and-white areas represent identical pixels Specifically:

  • 01.png02_upper.png

Image

  • 01.png = 03_upper.png

Image

  • 02_lower.png03_lower.png

Image

Steps to Reproduce

(The workflow where I initially discovered this was more complex; this is a simplified version): Between each step below, I restart ComfyUI to ensure the workflow runs fresh without interference.

  1. STEP_01.json I created a workflow loading the "NoobAI V pred 1.0" checkpoint, then added RescaleCFG, a prompt, and an empty latent image, connected them to a KSampler, and finally to a VAE Decode for output. Let's call the output image from this step 01.png.

Image

  1. STEP_02.json Next, I added a second (lower) branch, sharing the same prompt, model, and empty latent image inputs. In my case, ComfyUI executed the lower branch first, then the upper branch. Let's denote the output from the upper KSampler as 02_upper.png and the lower KSampler as 02_lower.png.

Image

  1. STEP_03.json Then, for reasons I haven't determined (I haven't looked into the source code for execution order logic), ComfyUI sometimes prioritizes the upper branch. In my testing, swapping the positions of the two "Save Image" nodes from step 2 seemed to trigger this change in execution order. Let's denote the output from the upper KSampler in this scenario as 03_upper.png and the lower KSampler as 03_lower.png.

Image

  1. The reproduction of the exact execution order isn't perfectly stable. For instance, after restarting ComfyUI, a workflow that previously executed the lower branch first (producing 02_upper.png from the top KSampler) might then execute the upper branch first. Conversely, a workflow that previously executed the upper branch first (producing 03_upper.png) might switch to executing the lower branch first. However, the inconsistent output persists: the image from a specific KSampler (e.g., the upper one) will differ depending on whether its branch was executed before or after the other parallel branch.

Debug Logs

PS C:\Users\administrator\PyProj\ComfyUI> python .\main.py
[START] Security scan
[DONE] Security scan
## ComfyUI-Manager: installing dependencies done.
** ComfyUI startup time: 2025-05-19 22:53:18.912
** Platform: Windows
** Python version: 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]
** Python executable: C:\Users\administrator\AppData\Local\Programs\Python\Python312\python.exe
** ComfyUI Path: C:\Users\administrator\PyProj\ComfyUI
** ComfyUI Base Folder Path: C:\Users\administrator\PyProj\ComfyUI
** User directory: C:\Users\administrator\PyProj\ComfyUI\user
** ComfyUI-Manager config path: C:\Users\administrator\PyProj\ComfyUI\user\default\ComfyUI-Manager\config.ini
** Log path: C:\Users\administrator\PyProj\ComfyUI\user\comfyui.log

Prestartup times for custom nodes:
   1.9 seconds: C:\Users\administrator\PyProj\ComfyUI\custom_nodes\ComfyUI-Manager

Checkpoint files will always be loaded safely.
Total VRAM 12282 MB, total RAM 31463 MB
pytorch version: 2.7.0+cu128
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA GeForce RTX 4070 SUPER : cudaMallocAsync
Using pytorch attention
Python version: 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]
ComfyUI version: 0.3.34
ComfyUI frontend version: 1.19.9
[Prompt Server] web root: C:\Users\administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\comfyui_frontend_package\static
### Loading: ComfyUI-Manager (V3.32.3)
[ComfyUI-Manager] network_mode: public
### ComfyUI Version: v0.3.34-26-gd8e56628 | Released on '2025-05-18'

Import times for custom nodes:
   0.0 seconds: C:\Users\administrator\PyProj\ComfyUI\custom_nodes\websocket_image_save.py
   0.5 seconds: C:\Users\administrator\PyProj\ComfyUI\custom_nodes\ComfyUI-Manager

Starting server

To see the GUI go to: http://127.0.0.1:8188
[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/alter-list.json
[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/model-list.json
[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/extension-node-map.json
[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json
[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/github-stats.json
FETCH ComfyRegistry Data: 5/85
FETCH ComfyRegistry Data: 10/85
FETCH ComfyRegistry Data: 15/85
FETCH ComfyRegistry Data: 20/85
FETCH ComfyRegistry Data: 25/85
FETCH ComfyRegistry Data: 30/85
FETCH ComfyRegistry Data: 35/85
FETCH ComfyRegistry Data: 40/85
FETCH ComfyRegistry Data: 45/85
FETCH ComfyRegistry Data: 50/85
FETCH ComfyRegistry Data: 55/85
FETCH ComfyRegistry Data: 60/85
FETCH ComfyRegistry Data: 65/85
FETCH ComfyRegistry Data: 70/85
FETCH ComfyRegistry Data: 75/85
FETCH ComfyRegistry Data: 80/85
FETCH ComfyRegistry Data: 85/85
FETCH ComfyRegistry Data [DONE]
[ComfyUI-Manager] default cache updated: https://api.comfy.org/nodes
FETCH DATA from: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json [DONE]
[ComfyUI-Manager] All startup tasks have been completed.
got prompt
model weight dtype torch.float16, manual cast: None
model_type V_PREDICTION
Using pytorch attention in VAE
Using pytorch attention in VAE
VAE load device: cuda:0, offload device: cpu, dtype: torch.bfloat16
Requested to load SDXLClipModel
loaded completely 9.5367431640625e+25 1560.802734375 True
CLIP/text encoder model load device: cuda:0, offload device: cpu, current: cuda:0, dtype: torch.float16
Requested to load SDXL
loaded completely 8014.872101593018 4897.0483474731445 True
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 40/40 [00:09<00:00,  4.03it/s]
Requested to load AutoencoderKL
loaded completely 176.0585174560547 159.55708122253418 True
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 40/40 [00:09<00:00,  4.10it/s]
Prompt executed in 25.84 seconds

Other

Environment:

  • Python: 3.12.4
  • Torch: 2.7.0+cu128
  • ComfyUI Version: commit d8e5662822168101afb5e08a8ba75b6eefff6e02
  • OS: Tested on both Linux and Windows, the issue occurs on both.
  • Custom Nodes: Only ComfyUI-Manager is installed.

sirius422 avatar May 19 '25 15:05 sirius422