ComfyUIのKSampler:steps、cfg、seed、denoiseの設定

ComfyUI Wiki

ComfyUIのKSamplerはモデルとポジティブ・ネガティブ条件付けで潜在画像をデノイズします。steps、cfg、seed、sampler_name、scheduler、denoiseの既定値について解説します。

ComfyUIノード - KSampler | ComfyUIコンポーネントノード

ドキュメンテーション

  • クラス名: KSampler
  • カテゴリ: Sampling
  • 出力ノード: No

KSamplerは次のように動作します。指定された特定のモデルとポジティブ・ネガティブ両方の条件に基づいて、提供された元の潜在画像情報を変更します。 まず、設定されたseedとdenoise強度に従って元の画像データにノイズを追加し、次にプリセットのModelをpositiveおよびnegativeのガイダンス条件と組み合わせて入力し、画像を生成します。

入力パラメータ

パラメータ名データ型必須既定値範囲/オプション説明
Modelcheckpointはいなし-デノイズ処理に使用される入力モデル
seed整数はい00 ~ 18446744073709551615ランダムノイズの生成に使用。同じ「seed」を使用すると同一の画像が生成される
steps整数はい201 ~ 10000デノイズ処理で使用するステップ数。ステップが多いほど結果が正確になる
cfg浮動小数点はい8.00.0 ~ 100.0生成画像が入力条件にどれだけ一致するかを制御。6~8が推奨
sampler_nameUIオプションはいなし複数のアルゴリズムデノイズ用のサンプラーを選択。生成速度とスタイルに影響
schedulerUIオプションはいなし複数のスケジューラーノイズの除去方法を制御。生成プロセスに影響
Positiveconditioningはいなし-デノイズを導くポジティブ条件。画像に表示させたい内容
Negativeconditioningはいなし-デノイズを導くネガティブ条件。画像に表示させたくない内容
Latent_ImageLatentはいなし-デノイズに使用する潜在画像
denoise浮動小数点いいえ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でサインインしてディスカッションに参加しましょう。

コメントを読み込み中…