Skip to content

Sampler Nodes Introduction

Ryu Xin edited this page Feb 29, 2024 · 1 revision

Introduction

comfyui-hiforce-plugin provide several highly practical samplers: Basic Sampler, Loopback Sampler, Two Step Sampler for Mask, Two Step Sampler, and Sampler Upscale - Iterative Latent. Right-click to open the menu, and under "HiFORCE -> Sampler" group menu, you can find these nodes. As follows:

image

Basic Sampler

We can add a basic sampler to the flow canvas (red node in the figure below) to compare the differences between the basic sampler provided in comfyui-hiforce-plugin and the default KSampler and KSampler (Advance) samplers.

image

The basic sampler in comfyui-hiforce-plugin has the following minor differences compared to KSampler:

  • **Provides sampler state (sampler_state): ** If the state is Sample, it will sample process the input latent_image. If the state is Hold, the basic sampler will not process and will pass through the latent_image.
  • Provides full drawing switch: When the full_drawing switch is true, it is a full redraw; false is a partial redraw. This concept is consistent with Stable Diffustion WebUI. Of course, the return_with_leftover_noise in KSampler (Advance) is a similar concept. When return_with_leftover_noise is disabled, it is a full redraw, and when it is enabled, it is a partial redraw.

The sampling state of the basic sampler can be controlled using the sampler switch in comfyui-hiforce-plugin, as shown below:

image

Loopback Sampler

During the process of generating images, there is an important parameter in the sampler, denoise, generally referred to as "denoising". The value ranges from 0.01 to 1.00. The larger the value, the greater the space for AI to play, and the greater the difference between the generated image and the original image in the scene. In some scenarios, a higher redraw magnitude is not necessarily better. In order to generate "progressive" results with the sampler drawn at different redraw magnitudes, we need to use the "Loopback Sampler." The figure below shows a typical configuration of a loopback sampler:

image

The loopback sampler consists of two parts: the loobback sampler itself and the loopback settings. The settings part is separated from the sampler because the strategy for loopback sampling can be continuously enriched. Currently, only a simple method is provided, and more responsible progressive generation strategy settings will be provided in the future.

The settings of the loopback sampler itself are similar to those of the basic sampler, so I won't go into detail here. Here, let's mainly introduce the parameters in the Loopback Settings node:

  • enable: Whether to enable loopback sampling. If it is false, the redraw magnitude will be drawn according to the value in "final_denoise."
  • loops: Number of loops, effective when enable is True.
  • start_denoise: Drawing intensity at the first loop.
  • final_denoise: Drawing intensity at the last loop.
  • policy: There are three policies:
    1. Aggressive: Converge to the final drawing intensity as quickly as possible during the loop.
    2. Lazy: Converge to the final drawing intensity at a slow pace during the loop.
    3. Linear: Converge to the final drawing intensity in a linear growth manner.

The sampling generation process of the progressive sampler can be seen in the following video: https://youtu.be/DrFzvYReXhw

We can see that images generated by the progressive sampler show a progressive refinement process from low to high redraw intensity.

image

TwoStepSamplerForMask

The TwoStepSamplerForMask is more commonly used in the "image to image" scenario, especially in scenarios where there are masks in the image to image process. The red node in the figure below is the TwoStepSamplerForMask:

image

For the TwoStepSamplerForMask sampler, it mainly has four inputs:

  • latent_image: The latent image to be sampled and processed.
  • base_sampler: The basic sampler used to draw areas outside the mask.
  • mask_sampler: The mask sampler used to draw areas inside the mask.

The greatest advantage of the TwoStepSamplerForMask is that different samplers can be used for sampling and drawing in areas inside and outside the mask, respectively. These TwoStepSamplerForMask can use different models, steps, denosing, random seeds, and sampling algorithms. In the TwoStepSamplerForMask, because the noise part is shared, the connection at the edge of the mask will be relatively natural.

The following video demo is an example of an image-to-image process where we need to redraw the entire background (including the model's face). At the same time, I also hope for slight changes in the clothes on the model. We use the TwoStepSamplerForMask to apply redraw intensities of 0.9 and 0.35 outside and inside the mask area, respectively: https://youtu.be/bobp-ONTvAE

Two-step Sampler

The two-step sampler is similar to the TwoStepSamplerForMask in that it also has two samplers as inputs. However, the difference is that the two-step sampler allows different masks to be used in the processing steps of the two samplers. The green node in the figure below is the two-stage sampler:

image

The two-stage sampler allows the samplers in Step 1 and Step 2 to use different models, sampling steps, denoising, random seeds, and sampling algorithms. By setting two different masks, it is possible to refine processing from large to small, layer by layer, for a region. Different regions can use different intensities, models, and algorithms, making the connection between regions more natural.

The following video is an example of AI drawing using a two-step sampler. In this example, we first draw the background outside the character area using a relatively large mask. Then, we redraw the character's face and hair using a relatively small mask: https://youtu.be/onq-uDAjlFU

Sampler Upscale - Iterative Latent

The iterative sampling upscale provided by comfyui-hiforce-plugin is basically consistent with the ComfyUI-Impact-Pack. It is mainly optimized based on the ComfyUI-Impact-Pack, as shown in the figure below:

image

The red node is the iterative sampling amplifier provided by ForceDojo, and the one on the right is provided by ComfyUI-Impact-Pack. The red box indicates the difference, that is, the addition of the enable parameter for whether to enable. When enable is False, no amplification processing will be done, and the samples will be passed through. The advantage of adding this parameter is that in some complex processes, we can control whether to do upscaling processing by defining variables. Like this:

image