ComfyUI KSampler 가이드: 스텝, CFG, 시드 및 디노이즈 설정

ComfyUI Wiki

ComfyUI의 KSampler는 모델과 긍정 및 부정 조건화로 잠재 데이터의 노이즈를 제거합니다. steps, cfg, seed, sampler_name, scheduler, denoise의 기본값과 역할을 설명합니다.

ComfyUI 노드 - KSampler | ComfyUI 컴포넌트 노드

문서화

  • 클래스 이름: KSampler
  • 카테고리: Sampling
  • 출력 노드: 아니오

KSampler는 다음과 같이 동작합니다. 특정 모델과 긍정 및 부정 조건을 기반으로 제공된 원본 잠재 이미지 정보를 수정합니다. 먼저 설정된 시드와 디노이즈 강도에 따라 원본 이미지 데이터에 노이즈를 추가한 다음, 미리 설정된 모델과 긍정 및 부정 가이드 조건을 결합해 입력하여 이미지를 생성합니다.

입력 파라미터

파라미터 이름데이터 타입필수기본값범위/옵션설명
Modelcheckpoint예없음-디노이징 과정에 사용되는 입력 모델
seedInt예00 ~ 18446744073709551615무작위 노이즈를 생성하는 데 사용되며, 동일한 "시드"를 사용하면 동일한 이미지가 생성됩니다
stepsInt예201 ~ 10000디노이징 과정에서 사용할 스텝 수, 스텝이 많을수록 결과가 더 정확합니다
cfgfloat예8.00.0 ~ 100.0생성된 이미지가 입력 조건과 얼마나 일치하는지 제어하며, 6-8을 권장합니다
sampler_nameUI 옵션예없음여러 알고리즘디노이징에 사용할 샘플러를 선택하며, 생성 속도와 스타일에 영향을 줍니다
schedulerUI 옵션예없음여러 스케줄러노이즈가 제거되는 방식을 제어하며, 생성 과정에 영향을 줍니다
Positiveconditioning예없음-디노이징을 안내하는 긍정 조건으로, 이미지에 나타나길 원하는 요소입니다
Negativeconditioning예없음-디노이징을 안내하는 부정 조건으로, 이미지에 나타나지 않길 원하는 요소입니다
Latent_ImageLatent예없음-디노이징에 사용되는 잠재 이미지
denoisefloat아니오1.00.0 ~ 1.0노이즈 제거 비율을 결정하며, 값이 낮을수록 입력 이미지와의 연결이 줄어듭니다
control_after_generateUI 옵션아니오없음Random/Inc/Dec/Keep각 프롬프트 이후에 시드를 변경할 수 있는 기능을 제공합니다

출력

파라미터 이름기능
Latent샘플러 디노이징 이후의 잠재 데이터를 출력합니다

소스 코드

[2025년 5월 15일 업데이트 됨]

def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent, denoise=1.0, disable_noise=False, start_step=None, last_step=None, force_full_denoise=False):
    latent_image = latent["samples"]
    latent_image = comfy.sample.fix_empty_latent_channels(model, latent_image)

    if disable_noise:
        noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
    else:
        batch_inds = latent["batch_index"] if "batch_index" in latent else None
        noise = comfy.sample.prepare_noise(latent_image, seed, batch_inds)

    noise_mask = None
    if "noise_mask" in latent:
        noise_mask = latent["noise_mask"]

    callback = latent_preview.prepare_callback(model, steps)
    disable_pbar = not comfy.utils.PROGRESS_BAR_ENABLED
    samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
                                  denoise=denoise, disable_noise=disable_noise, start_step=start_step, last_step=last_step,
                                  force_full_denoise=force_full_denoise, noise_mask=noise_mask, callback=callback, disable_pbar=disable_pbar, seed=seed)
    out = latent.copy()
    out["samples"] = samples
    return (out, )


class KSampler:
    @classmethod
    def INPUT_TYPES(s):
        return {
            "required": {
                "model": ("MODEL", {"tooltip": "The model used for denoising the input latent."}),
                "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "control_after_generate": True, "tooltip": "The random seed used for creating the noise."}),
                "steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "The number of steps used in the denoising process."}),
                "cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step":0.1, "round": 0.01, "tooltip": "The Classifier-Free Guidance scale balances creativity and adherence to the prompt. Higher values result in images more closely matching the prompt however too high values will negatively impact quality."}),
                "sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"tooltip": "The algorithm used when sampling, this can affect the quality, speed, and style of the generated output."}),
                "scheduler": (comfy.samplers.KSampler.SCHEDULERS, {"tooltip": "The scheduler controls how noise is gradually removed to form the image."}),
                "positive": ("CONDITIONING", {"tooltip": "The conditioning describing the attributes you want to include in the image."}),
                "negative": ("CONDITIONING", {"tooltip": "The conditioning describing the attributes you want to exclude from the image."}),
                "latent_image": ("LATENT", {"tooltip": "The latent image to denoise."}),
                "denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The amount of denoising applied, lower values will maintain the structure of the initial image allowing for image to image sampling."}),
            }
        }

    RETURN_TYPES = ("LATENT",)
    OUTPUT_TOOLTIPS = ("The denoised latent.",)
    FUNCTION = "sample"

    CATEGORY = "sampling"
    DESCRIPTION = "Uses the provided model, positive and negative conditioning to denoise the latent image."

    def sample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=1.0):
        return common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)

댓글

GitHub로 로그인하고 토론에 참여하세요.

댓글을 불러오는 중…