SDXL HSWQ FP8 Quantizer (Spec-aligned)
FP8 your SDXL with a calibration pass, not a blind cast
- model
- model
Let's be honest about SDXL first: at 3.5B parameters the UNet fits on almost everything, so quantizing it to FP8 is not a rescue mission the way it was for Flux. You reach for this node for one of three reasons: you're squeezing SDXL onto a genuinely small card, you want fp8's native speed on a 40-series GPU, or you want to actually understand quantization instead of downloading someone's pre-cast weights. This is the reference way to do the last one in ComfyUI.
SDXL HSWQ FP8 Quantizer (Spec-aligned) is part of the ComfyUI-HSWQ-Quantizer pack, an unofficial ComfyUI port of Hybrid Sensitivity Weighted Quantization by ussoewwin. HSWQ's pitch: don't quantize every layer equally. Rank layers by how sensitive they are to precision loss, keep the fragile top of the list in FP16, and clip only the rest down to torch.float8_e4m3fn. That's a real improvement over the "just cast everything" fp8 files floating around, and it's why the "Spec-aligned" name isn't just branding - the algorithm here is faithful to the original repo.
How it actually works
The node loads a stats file your workflow produced during a calibration run, then walks the UNet's Linear/Conv2d layers:
- Ranks every layer by output variance - the tracked sensitivity signal - and keeps the top
keep_ratioof them in FP16. Sensitive layers stay precise; the other ~75% take the FP8 hit. - For each remaining layer, picks the FP8 clip value (
amax) by a weighted histogram MSE optimization, weighting the histogram by per-channel input importance from calibration. That's the HSWQ core: the optimal clip is the one that minimizes quantize-then-dequantize error on your activations, not a generic guess. - Clips and casts to
float8_e4m3fn, then optionally injectscomfy_quantandweight_scalebuffers so downstream ComfyUI loaders interpret the FP8 weights correctly.
The output is a MODEL - wire it into your sampler like any other model. Note what this isn't: it doesn't write a .safetensors to disk. The quantized model lives in memory for your session, so you're not producing a reusable checkpoint file here.
The inputs that matter
- model - your SDXL UNet model.
- hswq_stats_path - points at the
.ptstats file from the calibration node. Defaults tooutput/hswq_stats/sdxl_calib_session_01.pt, and the node is smart enough to resolve that relative to ComfyUI's output directory. - keep_ratio (0.25 default) - the fraction of top-sensitivity layers kept in FP16. Higher = safer but smaller savings; the original HSWQ guidance is ~0.25.
- bins / num_candidates / refinement_iterations - knobs for the amax search. Defaults are fine to start; the original repo recommends pushing optimization toward 20–25 refinement iterations if you want to squeeze quality.
- scaled (default off) -
Falsegives the compatible clip-then-cast path.Truescales into FP8's full dynamic range and stashes aweight_scalebuffer, but that only helps if your downstream loader knows to read it. Leave it off unless you know you need spec-aligned V1 behavior. - inject_comfy_metadata (default on) - writes the FP8 marker buffers. Keep it on; it's what lets standard loaders read the result.
Install
No model downloads, no heavy deps - this is one of the lighter packs out there. It ships no requirements.txt; you need recent PyTorch (2.1+, which has float8_e4m3fn) and nothing else, unless you want the pack's benchmark node (then pip install lpips open_clip_torch).
cd ComfyUI/custom_nodes
git clone https://github.com/Shiba-2-shiba/ComfyUI-HSWQ-Quantizer
Restart ComfyUI. ComfyUI Manager works too - search for ComfyUI-HSWQ-Quantizer. (The README's clone line has a copy-paste URL bug with a <yourname> placeholder; ignore it, the real repo is the one above.)
The workflow: calibrate first, or nothing happens
The trap beginners hit: you feed this node a model and a default stats path, and the model comes out unchanged. That's the fail-safe kicking in - there's no stats file yet. HSWQ is a two-stage thing, and the quantizer is stage two.
- Drop SDXL HSWQ Calibration (Dual Monitor V2) into your workflow, in front of the sampler, and generate. It hooks the UNet forward pass and accumulates output variance + input importance per layer. Run it several times - the original repo suggests roughly 256 samples total - and stats accumulate across sessions with atomic saves.
- Replace/keep the calibration node and add this quantizer with the generated stats path.
Common issues
- "Model unchanged, no FP8" - either the stats path is wrong or you haven't calibrated. Check the console output; it prints a clear
[HSWQ] Error: Stats file not found. torch.float8_e4m3fn is not available- your PyTorch predates 2.1. Upgrade, or this pack simply can't run (fp8 storage itself needs the dtype).- No native speedup on 30-series - FP8 weights still save VRAM on older cards, but native fp8 math is an RTX 40-series-and-newer thing. On a 3060 you're doing this for memory, not speed.
If the node throws on import, check custom_nodes/ComfyUI-HSWQ-Quantizer/hswq_import_error.log - the pack writes a readable stack trace there instead of silently dying.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| hswq_stats_path | STRING | output/hswq_stats/sdxl_calib_session_01.pt | — |
| keep_ratio | FLOAT | 0.250–1 | — |
| bins | INT | 8192512–65536 | — |
| num_candidates | INT | 100050–5000 | — |
| refinement_iterations | INT | 100–30 | — |
| scaled | BOOLEAN | false | — |
| inject_comfy_metadata | BOOLEAN | true | — |
| log_level | COMBO | Basic | 3 options: Basic, Verbose, Debug |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| model | MODEL | — |