Nodes/ComfyUI-HSWQ-Quantizer/HSWQ FP8 Converter (Legacy V1.2 Logic)
ComfyUI Node

HSWQ FP8 Converter (Legacy V1.2 Logic)

The HSWQ FP8 converter that keeps it boring — and that's the point

By Shiba-2-shiba·Created 7 months ago·Updated 5 months ago· 3
HSWQ FP8 Converter (Legacy V1.2 Logic)
  • model
  • model
hswq_stats_pathoutput/hswq_stats/sdxl_calib_session_01.pt
keep_ratio0.25
log_levelBasic

This is the middle step of the HSWQ workflow: you calibrated an SDXL UNet with the pack's calibration node, and now you actually convert it to fp8. The "Legacy V1.2 Logic" in the name means this node deliberately implements the older, stricter version of the algorithm - fixed optimizer settings, scaled=False forced, no extra ComfyUI metadata buffers injected. Boring on purpose. The tradeoff it makes is flexibility for compatibility: the model it hands back is plain fp8 that any standard loader understands.

For the record, fp8 is generally the good kind of quantization - roughly half the VRAM of fp16 at near-invisible quality cost, which is why it's the default for big models. What this node adds over a naive cast is sensitivity awareness: instead of dumping every weight to 8 bits equally, it keeps the layers your calibration showed to be most sensitive in full fp16 and only crunches the rest.

How it works

The mechanism, grounded in the source:

  1. It loads the calibration stats file you point it at.
  2. It ranks every layer by the output variance your calibration collected - high variance means the layer's output swings a lot with its inputs, which is how it decides what's "sensitive."
  3. It keeps the top keep_ratio of layers in fp16 (casting bf16 to fp16 so downstream stuff doesn't trip over mixed precision).
  4. Everything else gets an FP8 E4M3 amax picked via weighted histogram MSE optimization - a per-layer clipping point, weighted by input-channel importance - then plain clip-and-cast to torch.float8_e4m3fn. Biases go to fp16. Layers that have no stats or are already fp8 are skipped.

The "legacy" constraints are the compatibility story: scaled=False means no side-channel scale factor, and no comfy_quant/weight_scale buffer injection - the current "spec-aligned" sibling node in this same pack adds those as options, but this one deliberately doesn't, because the whole point is output that any standard ComfyUI loader treats as ordinary fp8 weights.

Inputs and outputs

Only three inputs you actually touch. model is your SDXL UNet. hswq_stats_path defaults to output/hswq_stats/sdxl_calib_session_01.pt - it's resolved relative to your ComfyUI output directory, so if you calibrated with the default names, it just works. keep_ratio (default 0.25) is the fraction of layers kept in fp16; the README's recommended calibration used ~256 samples and keep_ratio ~0.25, and that's a sane starting point. log_level just controls console verbosity - set it to Debug if you want to see each layer's amax.

The single output is model, wired straight into your KSampler. The whole conversion runs in-memory; nothing gets written to disk, so the conversion cost happens once when the graph runs.

Installing it

Same pack as the rest of the HSWQ nodes - one install covers all of them. ComfyUI Manager (search "HSWQ") or:

cd ComfyUI/custom_nodes
git clone https://github.com/Shiba-2-shiba/ComfyUI-Unofficial-HSWQ-QuantizerHSWQ-Quantizer

Then restart ComfyUI. The pack needs a PyTorch build that exposes torch.float8_e4m3fn (recent PyTorch), and it uses ComfyUI's newer node API, so keep ComfyUI on current mainline. The README's own clone command is a copy-paste placeholder - ignore it and use the URL above.

Gotchas

The big one: if the stats file is missing or empty, the node doesn't throw. It prints an error to the console and returns the model unchanged, so you can run a graph thinking you're on fp8 and actually still be on fp16. Check the log output for "Starting FP8 Conversion" and the summary line ("Converted FP8: N") before trusting it. Also make sure the stats file matches the calibration session you actually ran - the session name in the calibration node (session_01 etc.) becomes part of the filename, and mismatched names mean "file not found" and that silent no-op. If your GPU's compute is older, you'll still save the VRAM but may not get native fp8 speed - that's the hardware, not the node.

CategoryQuantization

Inputs (4)

NameTypeDefaultDescription
modelMODEL
hswq_stats_pathSTRINGoutput/hswq_stats/sdxl_calib_session_01.pt
keep_ratioFLOAT0.250–1
log_levelCOMBOBasic3 options: Basic, Verbose, Debug

Outputs (1)

NameTypeDescription
modelMODEL