adieyal / comfyui-dynamicprompts

ComfyUI custom nodes for Dynamic Prompts
MIT License
252 stars 28 forks source link

Fixed dynamic prompt word seed, fixed sampler seed, still sampling. #65

Open wencxxxxxx opened 2 months ago

wencxxxxxx commented 2 months ago

Fixed dynamic prompt word seed, fixed sampler seed, still sampling.

cbaoth commented 2 months ago

I just had the same issue and had a quick look at DPAbstractSamplerNode to fix this issue in the Random Prompts node:

    @classmethod
    def IS_CHANGED(cls, text: str, seed: int, autorefresh: str):
        if autorefresh == "Yes":
            # Force re-evaluation of the node
            return float("NaN")
        else:
            # Re-evaluate only in case the seed and/or text has changed
            m = sha256()
            m.update(str(seed).encode())
            m.update("".encode() if text is None else text.encode())
            # print(f"Hash: {m.hexdigest()}, Seed: {str(seed)}, Text: {text}") # debug
            return m.hexdigest()

The original code always returned float("NaN") meaning the node will always be treated as changed, according to this.

wencxxxxxx commented 2 months ago

Is the author still maintaining this node?

wencxxxxxx commented 2 months ago

Please optimize this bug, can you

PrometheusDante commented 1 month ago

@cbaoth I tried your fix by editing the sampler.py to this :

@classmethod
def IS_CHANGED(cls, text: str, seed: int, autorefresh: str):
    if autorefresh == "Yes":
        # Force re-evaluation of the node
        return float("NaN")
    else:
        # Re-evaluate only in case the seed and/or text has changed
        m = sha256()
        m.update(str(seed).encode())
        m.update("".encode() if text is None else text.encode())
        # print(f"Hash: {m.hexdigest()}, Seed: {str(seed)}, Text: {text}") # debug
        return m.hexdigest()

RETURN_TYPES = ("STRING",)
FUNCTION = "get_prompt"
CATEGORY = "Dynamic Prompts"

But it still insists on sampling over and over unfortunately

cbaoth commented 2 weeks ago

@PrometheusDante Sorry, I forgot to mention that you also need to add the following line ...

from hashlib import sha256

... somewhere on top of the file, e.g. like this:

from __future__ import annotations

import logging
from abc import ABC, abstractproperty
from collections.abc import Iterable
from pathlib import Path
from hashlib import sha256

Otherwise you should see something like this in the console output:

WARNING: name 'sha256' is not defined
PrometheusDante commented 2 weeks ago

@cbaoth Thanks for getting back to me. I switched to the Impact Pack's wildcard processing with a .yaml file in the meantime and like that quite a lot, with the only downside for me being the absence of immediately evaluated variables to use in multiple points of a prompt.