ComfyUI Node

NNT Load Model

Seven formats in, one trained model out

By inventorado·Created 2 years ago·Updated 2 years ago· 69
NNT Load Model
    • model
    • report
    filenamemodel.pth
    directory
    load_formatPyTorch Model
    load_optimizerFalse

    You trained a model in NNT, saved it, and now you want it back - or you want to poke at something exported from plain PyTorch. NNT Load Model is the front door: it reads a saved model back into the toolkit as an NNT MODEL you can then run through NntInference, NntEvaluatePredictions, or NntEditModelLayers. Seven file formats behind one node, which is both convenient and the source of its sharpest gotcha.

    What it actually does

    It resolves the file (defaulting to ComfyUI/models/nnt_models/ if you leave directory empty), then loads by format: a full PyTorch save (.pth), a state dict (.pt/state-dict format), TorchScript (.pt), ONNX (.onnx), TorchScript Mobile (.ptl), quantized (.quantized.pth), or SafeTensors (.safetensors). For state-dict-style formats it reconstructs the model architecture from the saved model_config and loads the weights. If you toggle load_optimizer on, it restores the optimizer state too - useful if you're resuming a training run rather than doing inference. Outputs are the loaded model and a report string that tells you what it found.

    Inputs that matter

    • load_format - the dropdown: PyTorch Model, State Dict, TorchScript, ONNX, TorchScript Mobile, Quantized, SafeTensors. Match this to how you saved the file.
    • filename - the file name. Note the node strips the extension and searches for the right one per format, so model finds model.pth, model.onnx, etc.
    • directory - leave empty to use the pack's nnt_models folder, or type an absolute path.
    • load_optimizer - restore optimizer state on top of the weights; only relevant for formats that carry it.

    The gotchas (and there are real ones)

    Two things bite people. First, the ONNX path imports onnx2pytorch, which is not in the pack's requirements.txt - the pack installs onnx but not the converter. If you pick ONNX and hit ModuleNotFoundError: onnx2pytorch, that's not your fault:

    pip install onnx2pytorch
    

    Second, SafeTensors loading rebuilds a nn.Sequential by guessing layer types from the state-dict key names (linearLinear, convConv2d). That works for straightforward feedforward models you saved from this pack, but don't expect it to resurrect an arbitrary third-party architecture with exotic layers. And the SafeTensors path needs the file to actually be named .safetensors - match the format to the file or you'll get the "no model file found" error. Which, by the way, is returned as (None, "Error...") in the model output - so if your downstream nodes start erroring on a None model, read the report output first; it's the honest error message.

    Installing NNT

    Part of inventorado/ComfyUI_NNT. ComfyUI Manager (search "ComfyUI Neural Network Toolkit") or:

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

    Restart ComfyUI after. The requirements are a heavy scientific stack - torch, scikit-learn, pandas, transformers, onnx, shap - so the first install takes a while. The pack's own "load and infer" MNIST workflow in workflows/ shows the intended round-trip (train → save → load → infer).

    CategoryNNT Neural Network Toolkit/Models

    Inputs (4)

    NameTypeDefaultDescription
    filenameSTRINGmodel.pth
    directorySTRING
    load_formatCOMBOPyTorch Model7 options: PyTorch Model, State Dict, TorchScript, ONNX, TorchScript Mobile, Quantized, +1
    load_optimizerCOMBOFalse2 options: True, False

    Outputs (2)

    NameTypeDescription
    modelMODEL
    reportSTRING