INNER CODE UNIT · Python

make_sampler_pre_cfg_automatic_cfg_function

Extraltodeus/ComfyUI-AutomaticCFG · nodes.py:87

def make_sampler_pre_cfg_automatic_cfg_function(minimum_sigma_to_disable_uncond=0, maximum_sigma_to_enable_uncond=1000000, disabled_cond_start=10000,disabled_cond_end=10000):
    def sampler_pre_cfg_automatic_cfg_function(sigma, uncond, cond, cond_scale, **kwargs):
        if sigma[0] < minimum_sigma_to_disable_uncond or sigma[0] > maximum_sigma_to_enable_uncond:
            uncond = None
        if sigma[0] <= disabled_cond_start and sigma[0] > disabled_cond_end:
            cond = None
        return uncond, cond, cond_scale
    return sampler_pre_cfg_automatic_cfg_function

def get_entropy(tensor):
    hist = np.histogram(tensor.cpu(), bins=100)[0]
    hist = hist / hist.sum()
    hist = hist[hist > 0]
    return -np.sum(hist * np.log2(hist))

def map_sigma(sigma, sigmax, sigmin):
    return 1 + ((sigma - sigmax) * (0 - 1)) / (sigmin - sigmax)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…