Save Imatrix
Turn your generations into a better GGUF, one .dat at a time
- model
- image_not_used
Save Imatrix is the payoff node of this pack. ImatrixUNETLoader spends its life quietly accumulating activation statistics while you generate; this node reads those stats off the loaded model and writes them to a file llama.cpp can actually consume. Everything else in the pack is setup. This is the export.
The format it writes is llama.cpp's own .imatrix binary - the same thing llama-imatrix produces for LLM quantization. The whole trick of this pack is that you built it by hand, from your images, instead of from a generic text corpus. That matters at the low end of the GGUF ladder (Q2_K, Q3_K), where a well-targeted imatrix is one of the few honest ways to win back quality the quantizer would otherwise chew off.
What it does under the hood
The node walks the loaded model's modules, grabs the per-channel importance values recorded during inference, and does two pieces of bookkeeping:
- Conv layers: it repeats each channel's value across the kernel positions, since the recorder tracks input channels and the quantizer needs the full tensor-shaped scale.
- 256 alignment: GGUF tensors get reshaped so their first dimension is a multiple of 256 - that's a hard constraint of the QX_K family. The node pads by repeating values until the count hits the next multiple.
Then it writes everything in llama.cpp's format to imatrix_data/ inside the pack folder, named <file_name>.dat.
Inputs are simple: model (the MODEL straight from ImatrixUNETLoader), file_name (default imatrix). There's one optional input worth knowing: image_not_used, an IMAGE slot the author admits is a dummy. It exists purely to control when the node runs - hook your KSampler's image output into it and the save happens right after generation, which is exactly when you want it.
The averaging trick
The model's statistics are a running average over every forward pass since loading. The author's own advice: run several generations, then add this node only on the last one and save once. Save mid-way and you get a partial average; save at the end and you've blended the whole session.
Actually using the .dat
Convert the model to a float GGUF with ComfyUI-GGUF's convert.py - the pack bundles a patched copy in its tools/ folder - then run the quantizer with your imatrix:
llama-quantize model-f16.gguf model-q2_k.gguf Q2_K --imatrix imatrix.dat
That's the whole loop: collect, export, quantize, enjoy a Q2_K that's less embarrassing.
Gotchas
The output file lands inside the pack's folder (ComfyUI/custom_nodes/ComfyUI-Imatrix/imatrix_data/), not your models folder - easy to lose, easy to forget to back up. And the README is honest that some architectures need the bundled convert.py patched before the 256-multiple and conv handling works cleanly. Treat the result as an experiment: verify your low-bit quant actually improved before you commit a workflow to it.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| file_name | STRING | imatrix | — |
| image_not_usedopt | IMAGE | — |
Outputs (0)
No outputs