ModelsOther

DPM++ 2M Alt Sampler for ComfyUI

DPM++ 2M Alt Sampler for ComfyUI

DPM++ 2M Alt Sampler for ComfyUI

Made the DPM++ 2M Alt Karras Sampler to work with ComfyUI.

Comparison: Left DPMPP 2M Karras | Right DPMPP 2M Alt Karras

Note: The face isn’t an accurate comparison due to different seed in facedetailer, other parts of the picture is using the same seed.

DPM++ 2M Alt Sampler for ComfyUI

Credits to hallastore, original thread: https://github.com/AUTOMATIC1111/stable-diffusion-webui/discussions/8457

Instructions:

Unzip method:

  1. IMPORTANT: Make backup of these two files of just in case new update affects the samplers.

    For ComfyUI Portable:

  • ComfyUI_windows_portable\ComfyUI\comfy\samplers.py

  • ComfyUI_windows_portable\ComfyUI\comfy\k_diffusion\sampling.py

    For Automatic 1111:

  • Stable-diffusion-webui\extensions\sd-webui-comfyui\ComfyUI\comfy\samplers.py

  • Stable-diffusion-webui\extensions\sd-webui-comfyui\ComfyUI\comfy\k_diffusion\sampling.py

  1. Unpack zip to directory

  • For Portable ComfyUI: ComfyUI_windows_portable\ComfyUI\comfy

  • For Automatic 1111 ComfyUI extension: Stable-diffusion-webui\extensions\sd-webui-comfyui\ComfyUI\comfy

  1. Sampler is named dpmpp_2m_alt in ComfyUI

Manual Method:

  1. IMPORTANT: Make backup of these two files of just in case new update affects the samplers.

    For ComfyUI Portable:

  • ComfyUI_windows_portable\ComfyUI\comfy\samplers.py

  • ComfyUI_windows_portable\ComfyUI\comfy\k_diffusion\sampling.py

    For Automatic 1111:

  • Stable-diffusion-webui\extensions\sd-webui-comfyui\ComfyUI\comfy\samplers.py

  • Stable-diffusion-webui\extensions\sd-webui-comfyui\ComfyUI\comfy\k_diffusion\sampling.py

    Tips: The following instructions is for ComfyUI Portable but it is the same for Automatic 1111, just navigate to the path given above for the *.py files with the same name.

  1. Open ComfyUI_windows_portable\ComfyUI\comfy\samplers.py

    search for KSAMPLER_NAMES

  2. DPM++ 2M Alt Sampler for ComfyUI
  3. Add dpmpp_2m_alt as a new value and save file, make sure you include the comma and quotes.

  4. DPM++ 2M Alt Sampler for ComfyUI
  5. Open ComfyUI_windows_portable\ComfyUI\comfy\k_diffusion\sampling.py\

  6. Copy the following code.

    @torch.no_grad()
    def sample_dpmpp_2m_alt(model, x, sigmas, extra_args=None, callback=None, disable=None):
        """DPM-Solver++(2M)."""
        extra_args = {} if extra_args is None else extra_args
        s_in = x.new_ones([x.shape[0]])
        sigma_fn = lambda t: t.neg().exp()
        t_fn = lambda sigma: sigma.log().neg()
        old_denoised = None
    
        for i in trange(len(sigmas) - 1, disable=disable):
            denoised = model(x, sigmas[i] * s_in, **extra_args)
            if callback is not None:
                callback({'x': x, 'i': i, 'sigma': sigmas[i], 'sigma_hat': sigmas[i], 'denoised': denoised})
            t, t_next = t_fn(sigmas[i]), t_fn(sigmas[i + 1])
            h = t_next - t
            
            t_min = min(sigma_fn(t_next), sigma_fn(t))
            t_max = max(sigma_fn(t_next), sigma_fn(t))
    
            if old_denoised is None or sigmas[i + 1] == 0:
                x = (t_min / t_max) * x - (-h).expm1() * denoised
            else:
                h_last = t - t_fn(sigmas[i - 1])
    
                h_min = min(h_last, h)
                h_max = max(h_last, h)
                r = h_max / h_min
    
                h_d = (h_max + h_min) / 2
                denoised_d = (1 + 1 / (2 * r)) * denoised - (1 / (2 * r)) * old_denoised
                x = (t_min / t_max) * x - (-h_d).expm1() * denoised_d
    
            old_denoised = denoised
        return x
  7. Scroll all the way to the bottom and paste the code as of the screenshot below then save.

  8. DPM++ 2M Alt Sampler for ComfyUI
    1. Sampler is named dpmpp_2m_alt in ComfyUI.

Related Model

Transformers Model
Transformers Model
Matrix Lora
Matrix Lora
DEN_lizyahmet_style
DEN_lizyahmet_style
Saint Patrick – Ghibli style
Saint Patrick - Ghibli style
Kisou Style Lora
Kisou Style Lora
SDXL – Let It Flourish
SDXL - Let It Flourish

No comments

No comments...