Nodes/ComfyUI-DyPE/HAP Calibrate (HRDiT)
ComfyUI Node

HAP Calibrate (HRDiT)

Make HAP's speed trick work on your model, once

By wildminder·Created 11 months ago·Updated a day ago· 625
HAP Calibrate (HRDiT)
  • model
  • positive
  • negative
  • reference_latent
  • scope_plan
  • plan_path
  • summary
width1024
height1024
num_prompts5
num_scopes50
budget_ratio0.10
bins4000
chunk256
text_len512
anchor_stride32
calib_sigma1.00
seed3407
loss_typeoutput_norm
runtrue
prompts
prompts_file
output_namescope_plan_calibrated.json
purge_between_promptsfalse

HAP's whole trick is "each attention head only attends to what it needs" - but what it needs depends on the model and the resolution. The pack ships a scope plan for FLUX, and if that's what you run, you can stop reading. If you run Qwen, Z-Image, Anima, a fine-tune that behaves differently, or just want a tighter speed budget than the shipped plan, you need your own plan - and that's exactly what HAP Calibrate does, in-graph, without ever leaving ComfyUI.

Calibration is a one-time job per model + resolution, and the tooltip is explicit that the payoff is reuse: "Calibrate once per model+resolution; reuse the plan for all subsequent generations." The node runs one denoising step per calibration prompt at a chosen sigma, collects attention-gradient scores from every head, then solves a scope-selection knapsack to pick the per-head scopes that keep the most useful attention within your compute budget. The result is a SCOPE_PLAN you link straight into the HAP node - no file round-trip - plus a copy written to disk and a human-readable summary.

The inputs that matter

The one rule that will save you an hour: connect the same model you'll run HAP on, unpruned. The tooltip warns directly - "Do NOT connect a HAP-patched model (calibrate unpruned)." Then positive/negative from a CLIP Text Encode (keep them representative of your real prompts), and these:

  • width / height - calibration resolution. Calibrate at ≤ 2K to fit memory; the plan then reuses at higher resolutions.
  • num_prompts (default 5) - prompts actually run; the paper used 30. More prompts = better averaging, longer calibration.
  • budget_ratio (default 0.1) - fraction of full attention compute retained. Lower = faster sampling but more aggressive pruning.
  • num_scopes (default 50) and bins (default 4000) - solver granularity. Leave them alone unless you're chasing the last few percent.
  • chunk (default 256) - memory knob: fewer query rows per calibration chunk = less VRAM, slower.
  • loss_type - output_norm (default) needs no external data (MSE of the denoised prediction vs zero); reference_mse compares against a reference_latent you connect.
  • run - the master switch. false returns an empty plan so you can wire the graph safely before committing GPU time.

The three outputs: scope_plan (link into HAP), plan_path (absolute path of the written JSON, also usable in HAP's scope_plan_path), and summary (the calibration report - worth a glance to see per-head pruning).

Installing and running it

HAP Calibrate ships inside ComfyUI-DyPE, so install the pack: ComfyUI Manager → search "ComfyUI-DyPE" → install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/wildminder/ComfyUI-DyPE.git

Restart. No extra dependencies and nothing to download. If you'd rather calibrate headlessly, the pack also ships calibration/calibrate_hap.py - with a --dry_run flag that exercises the whole pipeline on a toy model with no GPU, and a real-model mode that loads a checkpoint through ComfyUI:

python calibration/calibrate_hap.py --dry_run --out tmp/scope_plan_toy.json

Honest positioning

This is the fiddliest node in the pack, and that's by design - it exists because scope plans are model-specific and there's no way around measuring your model's attention. Most people will never touch it (the FLUX default just works). But if you're on a non-FLUX model, this is the difference between HAP being a toy and HAP being real. Two things to expect: it's a real GPU run, not instant - pick your prompts, set num_prompts to 30 for quality, and let it cook; and on a low-VRAM card, enable purge_between_prompts and calibrate at 2K, not 4K. The plan you get is validated and directly loadable, which is more than most calibration tooling in this ecosystem bothers to guarantee.

CategoryWMNodes/image

Inputs (21)

NameTypeDefaultDescription
modelMODELThe model to calibrate. Must be the SAME model + resolution you will run HAP on. Do NOT connect a HAP-patched model (calibrate unpruned).
positiveCONDITIONINGPositive conditioning (from a CLIP Text Encode node). Keep it representative of your typical prompts. The same conditioning is used for every calibration prompt; each prompt index varies the noise seed.
negativeCONDITIONINGNegative conditioning (from a CLIP Text Encode node).
widthINT1024256–8192Calibration resolution width. Calibrate at <= 2K (memory); reuse the plan at higher resolutions.
heightINT1024256–8192Calibration resolution height. Calibrate at <= 2K (memory); reuse the plan at higher resolutions.
num_promptsINT51–64Number of calibration prompts to actually run (first N of the list). Paper: 30. More prompts = better averaging but longer calibration.
num_scopesINT502–200Candidate scopes N_scope. Paper: 50. More scopes = finer granularity but slower solver.
budget_ratioFLOAT0.100.01–1Attention cost ratio r_c (fraction of full attention compute retained). Paper: 0.1. Lower = faster but more pruning.
binsINT4000100–20000Knapsack discretization resolution.
chunkINT2561–4096Query rows per calibration chunk (memory knob; result-invariant). Lower = less VRAM but slower.
text_lenINT5120–4096Number of leading text tokens (never pruned). 512 = FLUX convention.
anchor_strideINT320–1024Global anchor blocks in the cost model. 32 = HRDiT default. 0 = off.
calib_sigmaFLOAT1.000–1Denoising sigma at which the single calibration step runs. 1.0 = first step (max noise). Lower values probe mid-trajectory behaviour.
seedINT34070–2147483648Noise seed base (prompt i uses seed + i).
loss_typeCOMBOoutput_normCalibration loss. 'output_norm' = MSE of the denoised prediction vs zero (no external data needed). 'reference_mse' = MSE vs a reference latent (connect the reference_latent input).
runBOOLEANtrueMaster switch. False = return empty plan without running (for safe graph wiring).
promptsoptSTRINGCalibration prompts, one per line. Empty = built-in default list (5 prompts). Paper uses 30.
prompts_fileoptSTRINGOptional text file with one prompt per line (overrides the 'prompts' input). Relative paths resolve against the ComfyUI-DyPE folder.
reference_latentoptLATENTTarget latent for 'reference_mse' loss (e.g. an encoded real image). Only needed when loss_type='reference_mse'.
output_nameoptSTRINGscope_plan_calibrated.jsonJSON file name inside <output>/dype_hap/. The written file is also loadable by the HAP node's scope_plan_path.
purge_between_promptsoptBOOLEANfalseRun gc + VRAM cache purge between calibration prompts (low-VRAM cards). Slower; results identical.

Outputs (3)

NameTypeDescription
scope_planSCOPE_PLANValidated scope plan dict — link into the HAP node's scope_plan input.
plan_pathSTRINGAbsolute path of the written JSON (also usable in HAP's scope_plan_path).
summarySTRINGHuman-readable calibration report.