The same prompt word, the random seed is set to random, but the comfyui tool generates the same image. #6557

Closed
opened 2026-02-21 18:16:17 -05:00 by yindo · 11 comments
Owner

Originally created by @majestichou on GitHub (Nov 5, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.10.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I created a painting app using the following yaml file:

app:
  description: ''
  icon: 🤖
  icon_background: '#FFEAD5'
  mode: advanced-chat
  name: 文生图--异常版本
  use_icon_as_answer_icon: false
kind: app
version: 0.1.2
workflow:
  conversation_variables: []
  environment_variables: []
  features:
    file_upload:
      allowed_file_extensions:
      - .JPG
      - .JPEG
      - .PNG
      - .GIF
      - .WEBP
      - .SVG
      allowed_file_types:
      - image
      allowed_file_upload_methods:
      - local_file
      - remote_url
      enabled: false
      fileUploadConfig:
        audio_file_size_limit: 50
        batch_count_limit: 5
        file_size_limit: 15
        image_file_size_limit: 10
        video_file_size_limit: 100
      image:
        enabled: false
        number_limits: 3
        transfer_methods:
        - local_file
        - remote_url
      number_limits: 3
    opening_statement: ''
    retriever_resource:
      enabled: true
    sensitive_word_avoidance:
      enabled: false
    speech_to_text:
      enabled: false
    suggested_questions: []
    suggested_questions_after_answer:
      enabled: false
    text_to_speech:
      enabled: false
      language: ''
      voice: ''
  graph:
    edges:
    - data:
        isInIteration: false
        sourceType: tool
        targetType: answer
      id: 1730706119831-source-answer-target
      selected: false
      source: '1730706119831'
      sourceHandle: source
      target: answer
      targetHandle: target
      type: custom
      zIndex: 0
    - data:
        isInIteration: false
        sourceType: start
        targetType: tool
      id: 1730376121968-source-1730706119831-target
      source: '1730376121968'
      sourceHandle: source
      target: '1730706119831'
      targetHandle: target
      type: custom
      zIndex: 0
    nodes:
    - data:
        desc: ''
        selected: false
        title: 开始
        type: start
        variables: []
      height: 54
      id: '1730376121968'
      position:
        x: 930
        y: 281
      positionAbsolute:
        x: 930
        y: 281
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        answer: '{{#1730706119831.files#}}'
        desc: ''
        selected: false
        title: 直接回复
        type: answer
        variables: []
      height: 103
      id: answer
      position:
        x: 1568
        y: 281
      positionAbsolute:
        x: 1568
        y: 281
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        provider_id: comfyui
        provider_name: comfyui
        provider_type: builtin
        selected: false
        title: 工作流
        tool_configurations:
          image_ids: null
          workflow_json: '{   "6": {     "inputs": {       "text": "{{positive_prompt}}",       "clip":
            [         "11",         0       ]     },     "class_type": "CLIPTextEncode",     "_meta":
            {       "title": "CLIP Text Encode (Positive Prompt)"     }   },   "8":
            {     "inputs": {       "samples": [         "13",         0       ],       "vae":
            [         "10",         0       ]     },     "class_type": "VAEDecode",     "_meta":
            {       "title": "VAE Decode"     }   },   "9": {     "inputs": {       "filename_prefix":
            "ComfyUI",       "images": [         "8",         0       ]     },     "class_type":
            "SaveImage",     "_meta": {       "title": "Save Image"     }   },   "10":
            {     "inputs": {       "vae_name": "ae.safetensors"     },     "class_type":
            "VAELoader",     "_meta": {       "title": "Load VAE"     }   },   "11":
            {     "inputs": {       "clip_name1": "t5xxl_fp16.safetensors",       "clip_name2":
            "clip_l.safetensors",       "type": "flux"     },     "class_type": "DualCLIPLoader",     "_meta":
            {       "title": "DualCLIPLoader"     }   },   "12": {     "inputs": {       "unet_name":
            "flux1-dev.safetensors",       "weight_dtype": "default"     },     "class_type":
            "UNETLoader",     "_meta": {       "title": "Load Diffusion Model"     }   },   "13":
            {     "inputs": {       "noise": [         "25",         0       ],       "guider":
            [         "22",         0       ],       "sampler": [         "16",         0       ],       "sigmas":
            [         "17",         0       ],       "latent_image": [         "27",         0       ]     },     "class_type":
            "SamplerCustomAdvanced",     "_meta": {       "title": "SamplerCustomAdvanced"     }   },   "16":
            {     "inputs": {       "sampler_name": "euler"     },     "class_type":
            "KSamplerSelect",     "_meta": {       "title": "KSamplerSelect"     }   },   "17":
            {     "inputs": {       "scheduler": "simple",       "steps": 20,       "denoise":
            1,       "model": [         "30",         0       ]     },     "class_type":
            "BasicScheduler",     "_meta": {       "title": "BasicScheduler"     }   },   "22":
            {     "inputs": {       "model": [         "30",         0       ],       "conditioning":
            [         "26",         0       ]     },     "class_type": "BasicGuider",     "_meta":
            {       "title": "BasicGuider"     }   },   "25": {     "inputs": {       "noise_seed":
            949997509248481     },     "class_type": "RandomNoise",     "_meta": {       "title":
            "RandomNoise"     }   },   "26": {     "inputs": {       "guidance": 3.5,       "conditioning":
            [         "6",         0       ]     },     "class_type": "FluxGuidance",     "_meta":
            {       "title": "FluxGuidance"     }   },   "27": {     "inputs": {       "width":
            1024,       "height": 1024,       "batch_size": 1     },     "class_type":
            "EmptySD3LatentImage",     "_meta": {       "title": "EmptySD3LatentImage"     }   },   "30":
            {     "inputs": {       "max_shift": 1.15,       "base_shift": 0.5,       "width":
            1024,       "height": 1024,       "model": [         "12",         0       ]     },     "class_type":
            "ModelSamplingFlux",     "_meta": {       "title": "ModelSamplingFlux"     }   }
            }'
        tool_label: 工作流
        tool_name: workflow
        tool_parameters:
          negative_prompt:
            type: mixed
            value: ''
          positive_prompt:
            type: mixed
            value: '{{#sys.query#}}'
        type: tool
      height: 116
      id: '1730706119831'
      position:
        x: 1256.0000000000002
        y: 281
      positionAbsolute:
        x: 1256.0000000000002
        y: 281
      selected: true
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    viewport:
      x: -371.8135330515688
      y: -1.080979998461487
      zoom: 1.0000000000000002

From the above yaml file, you can see "class_type": "RandomNoise". So every time I type the same prompt word, I should get a different picture.

But that's not the case. I typed the same word twice, and each time I got the same picture. It's not exactly what I wanted.

Then I used the native ComfyUI workflow (https://github.com/comfyanonymous/ComfyUI, ) and set RandomNoise to random. Each time you enter the same prompt word, a different picture is generated.

✔️ Expected Behavior

The same prompt word, the random seed is set to random, but the comfyui tool generates different image.

Actual Behavior

The same prompt word, the random seed is set to random, but the comfyui tool generates the same image.

Originally created by @majestichou on GitHub (Nov 5, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.10.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I created a painting app using the following yaml file: ``` app: description: '' icon: 🤖 icon_background: '#FFEAD5' mode: advanced-chat name: 文生图--异常版本 use_icon_as_answer_icon: false kind: app version: 0.1.2 workflow: conversation_variables: [] environment_variables: [] features: file_upload: allowed_file_extensions: - .JPG - .JPEG - .PNG - .GIF - .WEBP - .SVG allowed_file_types: - image allowed_file_upload_methods: - local_file - remote_url enabled: false fileUploadConfig: audio_file_size_limit: 50 batch_count_limit: 5 file_size_limit: 15 image_file_size_limit: 10 video_file_size_limit: 100 image: enabled: false number_limits: 3 transfer_methods: - local_file - remote_url number_limits: 3 opening_statement: '' retriever_resource: enabled: true sensitive_word_avoidance: enabled: false speech_to_text: enabled: false suggested_questions: [] suggested_questions_after_answer: enabled: false text_to_speech: enabled: false language: '' voice: '' graph: edges: - data: isInIteration: false sourceType: tool targetType: answer id: 1730706119831-source-answer-target selected: false source: '1730706119831' sourceHandle: source target: answer targetHandle: target type: custom zIndex: 0 - data: isInIteration: false sourceType: start targetType: tool id: 1730376121968-source-1730706119831-target source: '1730376121968' sourceHandle: source target: '1730706119831' targetHandle: target type: custom zIndex: 0 nodes: - data: desc: '' selected: false title: 开始 type: start variables: [] height: 54 id: '1730376121968' position: x: 930 y: 281 positionAbsolute: x: 930 y: 281 selected: false sourcePosition: right targetPosition: left type: custom width: 244 - data: answer: '{{#1730706119831.files#}}' desc: '' selected: false title: 直接回复 type: answer variables: [] height: 103 id: answer position: x: 1568 y: 281 positionAbsolute: x: 1568 y: 281 selected: false sourcePosition: right targetPosition: left type: custom width: 244 - data: desc: '' provider_id: comfyui provider_name: comfyui provider_type: builtin selected: false title: 工作流 tool_configurations: image_ids: null workflow_json: '{ "6": { "inputs": { "text": "{{positive_prompt}}", "clip": [ "11", 0 ] }, "class_type": "CLIPTextEncode", "_meta": { "title": "CLIP Text Encode (Positive Prompt)" } }, "8": { "inputs": { "samples": [ "13", 0 ], "vae": [ "10", 0 ] }, "class_type": "VAEDecode", "_meta": { "title": "VAE Decode" } }, "9": { "inputs": { "filename_prefix": "ComfyUI", "images": [ "8", 0 ] }, "class_type": "SaveImage", "_meta": { "title": "Save Image" } }, "10": { "inputs": { "vae_name": "ae.safetensors" }, "class_type": "VAELoader", "_meta": { "title": "Load VAE" } }, "11": { "inputs": { "clip_name1": "t5xxl_fp16.safetensors", "clip_name2": "clip_l.safetensors", "type": "flux" }, "class_type": "DualCLIPLoader", "_meta": { "title": "DualCLIPLoader" } }, "12": { "inputs": { "unet_name": "flux1-dev.safetensors", "weight_dtype": "default" }, "class_type": "UNETLoader", "_meta": { "title": "Load Diffusion Model" } }, "13": { "inputs": { "noise": [ "25", 0 ], "guider": [ "22", 0 ], "sampler": [ "16", 0 ], "sigmas": [ "17", 0 ], "latent_image": [ "27", 0 ] }, "class_type": "SamplerCustomAdvanced", "_meta": { "title": "SamplerCustomAdvanced" } }, "16": { "inputs": { "sampler_name": "euler" }, "class_type": "KSamplerSelect", "_meta": { "title": "KSamplerSelect" } }, "17": { "inputs": { "scheduler": "simple", "steps": 20, "denoise": 1, "model": [ "30", 0 ] }, "class_type": "BasicScheduler", "_meta": { "title": "BasicScheduler" } }, "22": { "inputs": { "model": [ "30", 0 ], "conditioning": [ "26", 0 ] }, "class_type": "BasicGuider", "_meta": { "title": "BasicGuider" } }, "25": { "inputs": { "noise_seed": 949997509248481 }, "class_type": "RandomNoise", "_meta": { "title": "RandomNoise" } }, "26": { "inputs": { "guidance": 3.5, "conditioning": [ "6", 0 ] }, "class_type": "FluxGuidance", "_meta": { "title": "FluxGuidance" } }, "27": { "inputs": { "width": 1024, "height": 1024, "batch_size": 1 }, "class_type": "EmptySD3LatentImage", "_meta": { "title": "EmptySD3LatentImage" } }, "30": { "inputs": { "max_shift": 1.15, "base_shift": 0.5, "width": 1024, "height": 1024, "model": [ "12", 0 ] }, "class_type": "ModelSamplingFlux", "_meta": { "title": "ModelSamplingFlux" } } }' tool_label: 工作流 tool_name: workflow tool_parameters: negative_prompt: type: mixed value: '' positive_prompt: type: mixed value: '{{#sys.query#}}' type: tool height: 116 id: '1730706119831' position: x: 1256.0000000000002 y: 281 positionAbsolute: x: 1256.0000000000002 y: 281 selected: true sourcePosition: right targetPosition: left type: custom width: 244 viewport: x: -371.8135330515688 y: -1.080979998461487 zoom: 1.0000000000000002 ``` From the above yaml file, you can see **`"class_type": "RandomNoise"`**. So every time I type the same prompt word, I should get a different picture. **But that's not the case. I typed the same word twice, and each time I got the same picture. It's not exactly what I wanted.** **Then I used the native ComfyUI workflow (https://github.com/comfyanonymous/ComfyUI, ) and set RandomNoise to random. Each time you enter the same prompt word, a different picture is generated.** ### ✔️ Expected Behavior The same prompt word, the random seed is set to random, but the comfyui tool generates different image. ### ❌ Actual Behavior The same prompt word, the random seed is set to random, but the comfyui tool generates the same image.
yindo added the 🐞 bug label 2026-02-21 18:16:17 -05:00
yindo closed this issue 2026-02-21 18:16:17 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 5, 2024):

In the Dify platform, the behavior of the RandomNoise class can be influenced by the seed parameter in the YAML workflow. If the seed is set to a specific value, it will generate the same output for the same input, which might be causing the issue you're experiencing. To ensure different outputs for the same prompt, you need to ensure that the noise_seed in the RandomNoise class is set to a random value each time.

In your YAML configuration, the noise_seed is set to a fixed value (949997509248481). To achieve different outputs, you should modify this to use a random seed. You can achieve this by setting the noise_seed to a random integer, for example, using a function or method that generates a random number each time the workflow is executed.

If you want to mimic the behavior of the native ComfyUI workflow, ensure that the noise_seed is dynamically generated, similar to how the text2img method in the ComfyuiStableDiffusionTool class sets a random seed using random.randint(0, 100000000) [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Nov 5, 2024): <!-- Answer --> In the Dify platform, the behavior of the `RandomNoise` class can be influenced by the `seed` parameter in the YAML workflow. If the `seed` is set to a specific value, it will generate the same output for the same input, which might be causing the issue you're experiencing. To ensure different outputs for the same prompt, you need to ensure that the `noise_seed` in the `RandomNoise` class is set to a random value each time. In your YAML configuration, the `noise_seed` is set to a fixed value (`949997509248481`). To achieve different outputs, you should modify this to use a random seed. You can achieve this by setting the `noise_seed` to a random integer, for example, using a function or method that generates a random number each time the workflow is executed. If you want to mimic the behavior of the native ComfyUI workflow, ensure that the `noise_seed` is dynamically generated, similar to how the `text2img` method in the `ComfyuiStableDiffusionTool` class sets a random seed using `random.randint(0, 100000000)` <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/tools/provider/builtin/comfyui/tools/comfyui_client.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/tools/provider/builtin/comfyui/tools/comfyui_stable_diffusion.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@hjlarry commented on GitHub (Nov 5, 2024):

It seems a bug of RandomNoise node, when I import your comfy workflow, I see the config of control_after_generate is randomize. but this config is not in the exported json.
image

@hjlarry commented on GitHub (Nov 5, 2024): It seems a bug of `RandomNoise` node, when I import your comfy workflow, I see the config of `control_after_generate` is `randomize`. but this config is not in the exported json. ![image](https://github.com/user-attachments/assets/da478f08-05ad-49bf-b328-323388ae3e1d)
Author
Owner

@hjlarry commented on GitHub (Nov 5, 2024):

how about add this option to the exported json file yourself ?

@hjlarry commented on GitHub (Nov 5, 2024): how about add this option to the exported json file yourself ?
Author
Owner

@majestichou commented on GitHub (Nov 5, 2024):

@hjlarry

I add this option to the exported json

    "25": {
        "inputs": {
            "noise_seed": 949997509248481,
            "control_after_generate": "randomize"
        },
        "class_type": "RandomNoise",
        "_meta": {
            "title": "RandomNoise"
        }
    },

However, the problem still is there. Sad………………

@majestichou commented on GitHub (Nov 5, 2024): @hjlarry I add this option to the exported json ``` "25": { "inputs": { "noise_seed": 949997509248481, "control_after_generate": "randomize" }, "class_type": "RandomNoise", "_meta": { "title": "RandomNoise" } }, ``` However, the problem still is there. Sad………………
Author
Owner

@majestichou commented on GitHub (Nov 5, 2024):

@hjlarry
I discovered that when I asked the question for the second time, the flux model was not called at all to generate images, and the image output speed was extremely fast. I guess dify reads the cache

@majestichou commented on GitHub (Nov 5, 2024): @hjlarry I discovered that when I asked the question for the second time, the flux model was not called at all to generate images, and the image output speed was extremely fast. I guess dify reads the cache
Author
Owner

@hjlarry commented on GitHub (Nov 5, 2024):

@hjlarry I discovered that when I asked the question for the second time, the flux model was not called at all to generate images, and the image output speed was extremely fast. I guess dify reads the cache

dify just send a request to comfy, the cache is from comfy, maybe you can try another random node?

@hjlarry commented on GitHub (Nov 5, 2024): > @hjlarry I discovered that when I asked the question for the second time, the flux model was not called at all to generate images, and the image output speed was extremely fast. I guess dify reads the cache dify just send a request to comfy, the cache is from comfy, maybe you can try another random node?
Author
Owner

@majestichou commented on GitHub (Nov 5, 2024):

@hjlarry I discovered that when I asked the question for the second time, the flux model was not called at all to generate images, and the image output speed was extremely fast. I guess dify reads the cache

dify just send a request to comfy, the cache is from comfy, maybe you can try another random node?

How can I try another random node? What should i do? Can you give me some examples?

@majestichou commented on GitHub (Nov 5, 2024): > > @hjlarry I discovered that when I asked the question for the second time, the flux model was not called at all to generate images, and the image output speed was extremely fast. I guess dify reads the cache > > dify just send a request to comfy, the cache is from comfy, maybe you can try another random node? How can I try another random node? What should i do? Can you give me some examples?
Author
Owner

@hjlarry commented on GitHub (Nov 5, 2024):

How can I try another random node? What should i do? Can you give me some examples?

I tried some other random noise node, they all not support export the control_after_generate option. I have no idea about this. How about change your prompt one more special char each time?

@hjlarry commented on GitHub (Nov 5, 2024): > How can I try another random node? What should i do? Can you give me some examples? I tried some other random noise node, they all not support export the `control_after_generate` option. I have no idea about this. How about change your prompt one more special char each time?
Author
Owner

@majestichou commented on GitHub (Nov 6, 2024):

@hjlarry
Each time you enter a different prompt word, a different picture will be generated. For example, the following two prompt words produce a different picture.

one dog,
one dog.

@majestichou commented on GitHub (Nov 6, 2024): @hjlarry Each time you enter a different prompt word, a different picture will be generated. For example, the following two prompt words produce a different picture. `one dog,` `one dog.`
Author
Owner

@hjlarry commented on GitHub (Nov 7, 2024):

so I think maybe add one more space to the prompt each time for a temporary solution
and make an issue in the Comfy project to discuss why control_after_generate can't be exported

@hjlarry commented on GitHub (Nov 7, 2024): so I think maybe add one more space to the prompt each time for a temporary solution and make an issue in the Comfy project to discuss why control_after_generate can't be exported
Author
Owner

@majestichou commented on GitHub (Nov 7, 2024):

I made an issue in the Comfy project. @hjlarry Thank you for your contributions
https://github.com/comfyanonymous/ComfyUI/issues/5521

@majestichou commented on GitHub (Nov 7, 2024): I made an issue in the Comfy project. @hjlarry Thank you for your contributions https://github.com/comfyanonymous/ComfyUI/issues/5521
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6557