CivArchive
    DPM++ 2M Alt Sampler for ComfyUI - v1.0
    NSFW
    Preview 3052153

    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.

    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. Add dpmpp_2m_alt as a new value and save file, make sure you include the comma and quotes.

    3. Open ComfyUI_windows_portable\ComfyUI\comfy\k_diffusion\sampling.py\

    4. 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
    5. Scroll all the way to the bottom and paste the code as of the screenshot below then save.

      1. Sampler is named dpmpp_2m_alt in ComfyUI.

    Description

    FAQ

    Comments (1)

    544221Jul 24, 2024
    CivitAI

    ; ) Cool

    Other
    SD 1.5

    Details

    Downloads
    1,395
    Platform
    CivitAI
    Platform Status
    Available
    Created
    10/20/2023
    Updated
    5/13/2026
    Deleted
    -

    Files

    dpm2MAltSamplerFor_v10.zip

    Mirrors

    CivitAI (1 mirrors)