Nodes/ComfyUI-HSWQ-Quantizer/SDXL HSWQ FP8 Quantizer (Spec-aligned)
ComfyUI Node

SDXL HSWQ FP8 Quantizer (Spec-aligned)

FP8 your SDXL with a calibration pass, not a blind cast

By Shiba-2-shiba·Created 7 months ago·Updated 5 months ago· 3
SDXL HSWQ FP8 Quantizer (Spec-aligned)
  • model
  • model
hswq_stats_pathoutput/hswq_stats/sdxl_calib_session_01.pt
keep_ratio0.25
bins8192
num_candidates1000
refinement_iterations10
scaledfalse
inject_comfy_metadatatrue
log_levelBasic

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:

  1. Ranks every layer by output variance - the tracked sensitivity signal - and keeps the top keep_ratio of them in FP16. Sensitive layers stay precise; the other ~75% take the FP8 hit.
  2. 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.
  3. Clips and casts to float8_e4m3fn, then optionally injects comfy_quant and weight_scale buffers 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 .pt stats file from the calibration node. Defaults to output/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) - False gives the compatible clip-then-cast path. True scales into FP8's full dynamic range and stashes a weight_scale buffer, 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.

  1. 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.
  2. 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.

CategoryQuantization

Inputs (9)

NameTypeDefaultDescription
modelMODEL
hswq_stats_pathSTRINGoutput/hswq_stats/sdxl_calib_session_01.pt
keep_ratioFLOAT0.250–1
binsINT8192512–65536
num_candidatesINT100050–5000
refinement_iterationsINT100–30
scaledBOOLEANfalse
inject_comfy_metadataBOOLEANtrue
log_levelCOMBOBasic3 options: Basic, Verbose, Debug

Outputs (1)

NameTypeDescription
modelMODEL