Nodes/ComfyUI Neural Network Toolkit NNT /NNT Training Hyperparameters
ComfyUI Node

NNT Training Hyperparameters

Bundle your training settings into one reusable dict

By inventorado·Created 2 years ago·Updated 2 years ago· 69
NNT Training Hyperparameters
    • training_params
    • config_summary
    experiment_nametraining_experiment
    batch_size32
    epochs10
    optimizerAdam
    learning_rate0.0010
    weight_decay0.0001
    momentum0.9
    loss_functionCrossEntropyLoss
    reductionmean
    weight_enabledFalse
    class_weights[]
    margin0.0
    use_lr_schedulerTrue
    scheduler_typeReduceLROnPlateau
    scheduler_step_size3
    scheduler_gamma0.10
    min_lr0.0000
    use_early_stoppingTrue
    patience5
    min_delta0.0010

    NntTrainModel has so many knobs - optimizer, scheduler, early stopping, class weights - that the node itself is a wall of dropdowns. NNT Training Hyperparameters is the answer to that: it collects every one of those settings into a single DICT, bundles it with a name and a summary, and lets you plug the whole configuration into a training node in one wire. Think of it as the "save my experiment settings as a thing" node.

    It exists because NntTrainModel accepts an optional hyperparameters input of type DICT that overrides its built-in settings. This node is the cleanest way to build that dict. Same settings, one reusable package instead of twenty fields.

    What it holds

    The node exposes all the classic training knobs: experiment_name, batch_size (default 32), epochs (default 10), optimizer (12 choices, default Adam), learning_rate (default 0.001), weight_decay, momentum, loss_function (21 choices, default CrossEntropyLoss), reduction, optional class_weights (as a string list like [0.5, 1.0]), margin (for margin-based losses), and the scheduler block - use_lr_scheduler, scheduler_type (StepLR / ReduceLROnPlateau / CosineAnnealingLR), scheduler_step_size, scheduler_gamma, min_lr - plus early stopping (use_early_stopping, patience, min_delta).

    Outputs: training_params (the DICT - wire this into NntTrainModel's hyperparameters input) and config_summary (a readable string of everything you set, which is great for a text display node or for screenshotting an experiment config for a writeup).

    How to use it, and one honest caveat

    Build a hyperparameters node, set your optimizer/epochs/lr, wire training_params into the hyperparameters input of NntTrainModel, and run. The override means whatever you set here wins over the train node's own fields - the code literally does locals().update(hyperparameters.get('training', {})) at the start of training. That's the feature, and also the trap: if you change a setting on the train node itself and forget the hyperparameters node is still wired in, your change silently does nothing. When experiments aren't behaving, check for a stray hyperparameters wire first.

    The natural workflow here is experimentation: build two hyperparameter bundles (say, Adam vs SGD, or lr 1e-3 vs 1e-4), and switch between them by rewiring one input instead of resetting twenty fields. For a learning pack, that's a nice way to make "hyperparameter tuning" concrete - change one bundle, watch the metrics move.

    Install

    Pack-level install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/inventorado/ComfyUI_NNT.git
    cd ComfyUI_NNT
    pip install -r requirements.txt
    

    Restart ComfyUI, or install via Manager by searching "ComfyUI Neural Network Toolkit NNT". No extra dependencies beyond what the pack already needs (torch, sklearn, matplotlib, statsmodels, onnx, shap 0.41.0, and the rest - slow first install, as always with this pack).

    One last note: this node is purely a configuration builder - it doesn't train anything itself. Its training_params dict only has meaning inside NntTrainModel. If you wire it into anything else, it's just a dict of settings looking for a home.

    CategoryNNT Neural Network Toolkit/Models

    Inputs (20)

    NameTypeDefaultDescription
    experiment_nameSTRINGtraining_experiment
    batch_sizeINT321–512
    epochsINT101–1000
    optimizerCOMBOAdam12 options: Adadelta, Adagrad, Adam, AdamW, SparseAdam, Adamax, +6
    learning_rateFLOAT0.00100.000001–1
    weight_decayFLOAT0.00010–0.1
    momentumFLOAT0.90–1
    loss_functionCOMBOCrossEntropyLoss21 options: L1Loss, MSELoss, CrossEntropyLoss, CTCLoss, NLLLoss, PoissonNLLLoss, +15
    reductionCOMBOmean3 options: mean, sum, none
    weight_enabledCOMBOFalse2 options: True, False
    class_weightsSTRING[]
    marginFLOAT0.0-1–1
    use_lr_schedulerCOMBOTrue2 options: True, False
    scheduler_typeCOMBOReduceLROnPlateau3 options: StepLR, ReduceLROnPlateau, CosineAnnealingLR
    scheduler_step_sizeINT31–100
    scheduler_gammaFLOAT0.100.01–1
    min_lrFLOAT0.00001e-7–0.1
    use_early_stoppingCOMBOTrue2 options: True, False
    patienceINT51–50
    min_deltaFLOAT0.00100.0001–0.1

    Outputs (2)

    NameTypeDescription
    training_paramsDICT
    config_summarySTRING