ComfyUI Node

优化器配置

Pick the optimizer and LR without touching a config file

By TianDongL·Created 11 months ago·Updated 7 months ago· 69
优化器配置
    • optimizer_config
    optimizer_typeAdamW8bitKahan
    lr0
    beta10.90
    beta20.99
    weight_decay0.010
    eps0

    Every training run needs an optimizer, and the optimizer is where the "just use these settings" advice gets messy. OptimizerConfigNode is the node that packages that decision into something you can pick from a dropdown and wire straight into GeneralConfig. It's the difference between editing a TOML by hand and choosing from four well-known options in ComfyUI.

    The defaults it ships with are telling: the default optimizer is AdamW8bitKahan, not the Prodigy that dominated the SDXL era. That tracks with where the community landed - the modern training docs describe the old Prodigy-default instinct as an SDXL-era thing, replaced by 8-bit AdamW-family optimizers for the current architectures.

    How it works

    You pick an optimizer_type and the node assembles the right config dict for it. It doesn't invent parameters - each optimizer gets exactly the fields that make sense for it:

    • AdamW8bitKahan (default) - 8-bit AdamW with Kahan summation, the VRAM-friendly workhorse. Gets lr, betas, weight_decay.
    • adamw_optimi - full-precision AdamW from torch-optimi. Gets lr, betas, weight_decay, plus eps.
    • Prodigy - the auto-tuned-LR optimizer. Still gets lr, betas, weight_decay (it uses them as starting points).
    • automagic - the "pick the settings for me" option. Only weight_decay is passed; the optimizer figures out the rest.

    The output, optimizer_config, is an OPTIMIZER_CONFIG wire that feeds into GeneralConfig alongside your model config and dataset config. In the example workflow that's exactly where it goes.

    The inputs that matter

    • optimizer_type - the four-way dropdown above. If you don't know, AdamW8bitKahan is the safe modern default.
    • lr - default 2e-5, the single most important number in your run. The modern rule of thumb has drifted from the old SDXL tables; current recipes talk about effective-batch-size-dependent LRs from ~1e-4 down to 2e-5.
    • beta1 / beta2 - default 0.9 / 0.99. Leave them unless you know why you're changing them.
    • weight_decay - default 0.01. Regularization; higher fights overfitting, too high kills learning.

    Install

    Pack-wide: ComfyUI Manager → search "Diffusion_pipe_in_ComfyUI", or:

    cd ComfyUI/custom_nodes
    git clone --recurse-submodules https://github.com/TianDongL/Diffusion_pipe_in_ComfyUI.git
    cd Diffusion_pipe_in_ComfyUI
    git submodule init && git submodule update
    pip install -r requirements.txt
    

    The optimizer libraries (torch-optimi, pytorch-optimizer, bitsandbytes) are in the requirements. Linux/WSL2 only.

    Where people get burned

    The subtle one: some of these optimizers ignore some of the sliders. Set eps on AdamW8bitKahan and it won't be forwarded - that field only ships for adamw_optimi. Likewise automagic ignores your lr entirely. So if you spent ages tuning a number and the run "ignored" it, check whether that optimizer actually consumes it. Also, 2e-5 is a reasonable starting LR but not universal - on the new transformer models, small batch sizes + high LR is exactly the recipe the community warns produces garbage. If you're coming from an old SDXL settings table, read the current guidance before you trust those numbers here.

    CategoryDiffusion-Pipe/Config

    Inputs (6)

    NameTypeDefaultDescription
    optimizer_typeCOMBOAdamW8bitKahan优化器类型选择
    lroptFLOAT01e-8–1学习率
    beta1optFLOAT0.900–1Adam优化器的beta1参数
    beta2optFLOAT0.990–1Adam优化器的beta2参数
    weight_decayoptFLOAT0.0100–1权重衰减系数
    epsoptFLOAT01e-12–0.0001Adam 的数值稳定性参数

    Outputs (1)

    NameTypeDescription
    optimizer_configOPTIMIZER_CONFIG