ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

[BUG] Seed RNG changes persist between workflows

Open MalikKillian opened this issue 1 year ago • 1 comments

So the "bug" is actually the fault of a custom node BUT it doesn't seem like there's any reasonable way the custom node could've avoided this issue. I originally noticed this because I use Comfy on multiple machines (hosted on one but web interface is shared) and I realized I couldn't reproduce some images despite saving them with the SaveImage node.

Steps to reproduce:

  1. Install ComfyUI_smZNodes
  2. Restart/start ComfyUI
  3. Load the default ComfyUI workflow and set the KSampler control_after_generate widget to "fixed"
  4. Generate the image (henceforth referred to as "image_001")
  5. Add on the smZ_Settings node between the CheckpointLoader and one of the CLIPTextEncode nodes. Set the RNG widget to "nv"
  6. Generate the image (henceforth referred to as "image_002"). You may need to increment the seed, generate, decrement the seed, then generate because Comfy may see the workflow as otherwise unchanged. The two images should look different and if they do not the directions were not followed properly
  7. Remove the smZ_Settings node and relink to fix the workflow. Generate the image ("image_003"). Again, you might need to fiddle with the seeds to make Comfy do the generation.

Expected result: image_001 and image_003 should match

Actual result: image_002 and image_003 match

It seems pretty clear that the "nv" generator is being used despite smZ_Settings being removed. I've looked through their code and some monkeypatching is involved, which ComfyUI is unaware of, so it doesn't know to restore the original RNG.

I think ComfyUI should do a restore of the RNG at the beginning of every workflow or at the very least mention something about the RNG as a part of the workflow metadata (something like "RNG": "custom" or "RNG": "cpu").

MalikKillian avatar Dec 30 '23 22:12 MalikKillian

I'm aware of this issue. It's a bug with that node and it should be reported to that repo. It'll be fixed soon.

shiimizu avatar Dec 31 '23 00:12 shiimizu