Nodes/ComfyUI-Lightning/Save Finetuned SpargeAttn Hyperparams
ComfyUI Node

Save Finetuned SpargeAttn Hyperparams

Step 3 of the SpargeAttn tuning dance

By shenduldh·Created 2 years ago·Updated about a year ago· 225
Save Finetuned SpargeAttn Hyperparams
  • model
    filename_prefixspargeattn_hyperparams

    This node does one thing, and you'll only ever touch it if you're deep into the SpargeAttn tuning workflow: it takes the hyperparameters Apply SpargeAttn learned during a tuning run and writes them to disk, so you don't have to redo hours of tuning every session. If you haven't read about Apply SpargeAttn first, start there - this node is meaningless on its own.

    What it is and why you'd reach for it

    SpargeAttn's whole pitch is extra speed on top of SageAttention, but only after you've tuned hyperparameters specific to your exact model. The README lays out the process as a numbered sequence, and this node is step 3 of it: turn on enable_tuning_mode on Apply SpargeAttn, run a batch of generations (the README's own example is 50-step 512x512 images across 10 different prompts - described, accurately, as "very time-consuming"), then use this node to capture what was learned into a file you can reuse. Skip this step and every tuning run is wasted the moment you close ComfyUI.

    Worth knowing before you invest the time: independent testing (Kijai, tuning SpargeAttn against Wan) found the tuning process itself unreliable - hours of tuning that produced only a modest speedup over plain SageAttention, with a significant quality cost, and parameters that don't transfer between model sizes. That's a strike against the whole workflow this node is part of, not against this node specifically - but it's worth weighing before you sink a GPU-hours-long tuning run into it.

    How it works

    Reads whatever hyperparameters the paired Apply SpargeAttn node has accumulated during a tuning run and writes them to a file on disk under a filename you choose. It's a save action, not a transformation - nothing about the model itself changes here.

    The inputs and outputs that matter

    • model - the same model you ran through Apply SpargeAttn's tuning mode. This is how the node knows which learned hyperparameters to pull.
    • filename_prefix (string, default spargeattn_hyperparams) - the base name for the saved file. Change it if you're tuning against multiple models or checkpoints and want to keep the results apart - the model-size specificity mentioned above makes this more than a cosmetic choice.

    This node has no outputs - it's an output/action node (is_output_node: true in its schema), the same category as a Save Image node. Nothing downstream connects to it; it does its job as a side effect when the graph runs.

    How to install it

    • ComfyUI Manager - search "ComfyUI-Lightning", install, restart.
    • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/shenduldh/ComfyUI-Lightning, then restart.

    No downloads for this node itself. But it's useless without SpargeAttn the library installed and working - see the Apply SpargeAttn article for that install (git clone + pip install -e . from thu-ml/SpargeAttn, on top of a working SageAttention/Triton setup).

    Common issues & troubleshooting

    Where does the saved file go, and what do I do with it? The README's own workflow: once saved, place the resulting hyperparameter file in models/checkpoints, then remove or disable this Save node from your graph (you only need it during the tuning session, not for normal generation), and load the file back through Apply SpargeAttn's tuned_hyperparams dropdown.

    I saved hyperparams, but results are still bad when I load them back. That's not this node's doing - it faithfully saves whatever Apply SpargeAttn learned. If the tuning itself produced poor parameters (a real, reported risk with this technique - see that node's article), no amount of correctly saving them fixes the underlying tune. You'd need to retune, possibly with more prompts or steps than the README's baseline example.

    Left this node active after tuning and generation slowed down or behaved oddly. The README explicitly says to remove or disable this node once you've saved your hyperparameters - it has no place in a normal generation graph, only in the tuning session itself.

    Tuned on one model, want to reuse the file on a different one. Don't, at least not without expecting to retune. Hyperparameters learned here are tied to the specific model dimensions they were tuned against; reusing them across model sizes is a known way to get a bad result.

    CategoryLightning/SpargeAttn

    Inputs (2)

    NameTypeDefaultDescription
    modelMODEL
    filename_prefixSTRINGspargeattn_hyperparams

    Outputs (0)

    No outputs