Nodes/LoRA Optimizer/LoRA AutoTuner
ComfyUI Node

LoRA AutoTuner

Let it sweep the merge settings instead of guessing yourself

By ethanfel·Created 5 months ago·Updated 23 days ago· 135
LoRA AutoTuner
  • model
  • lora_stack
  • clip
  • evaluator
  • model
  • clip
  • report
  • analysis_report
  • tuner_data
  • lora_data
output_strength1.00
clip_strength_multiplier1.00
top_n3
normalize_keysenabled
scoring_svddisabled
scoring_devicegpu
architecture_presetauto
auto_strength_floor-1.00
community_cachedisabled
cache_patchesenabled
diff_cache_modeauto
diff_cache_ram_pct0.50
vram_budget0.00
scoring_speedturbo
scoring_formulav2
output_modemerge
decision_smoothing0.25
smooth_slerp_gatefalse
memory_modeauto
selection1
record_datasetdisabled

LoRA Optimizer's per-prefix heuristics are good defaults, but they're still defaults - general-purpose settings tuned to work reasonably across every kind of stack. AutoTuner is the node for when "reasonable" isn't good enough and you want the actual best config for your specific LoRAs. It sweeps merge mode, sparsification, density, dampening, and quality level across a large parameter space, scores every combination with cheap heuristics, then does a real merge-and-measure pass on just the top candidates, so you get a genuinely optimized result without paying full merge cost for every option it considered.

How it works

One Pass 1 analysis run (same conflict/magnitude sampling the plain Optimizer does), then the heuristic scoring pass ranks every parameter combination against a subset of the model's weight prefixes - not all of them, by default, which is a deliberate speed/accuracy tradeoff you control via scoring_speed. The top top_n candidates then get a real merge and a real quality measurement, and the winner becomes your MODEL/CLIP output directly. Everything else it evaluated is still available afterward through tuner_data, so you're not locked into the #1 pick - a Merge Selector node lets you try #2 or #3 without re-running the sweep.

The diff cache is the other piece worth understanding: recomputing each LoRA's raw diff from scratch for every candidate is redundant work, since the diffs only depend on the LoRA files, not the merge config. diff_cache_mode=auto (default) caches diffs in RAM up to a budget, then recomputes overflow on demand rather than spilling to disk - worth knowing about before you assume a slow sweep is just "how it is."

The inputs and outputs that matter

  • model / lora_stack (required) - same as the plain Optimizer.
  • output_strength (default 1.0, -1 for auto) - same semantics as everywhere else in the pack.
  • top_n (default 3) - how many of the ranked candidates actually get merged and quality-measured. Higher explores more but takes proportionally longer.
  • scoring_speed (default turbo) - full scores every prefix (slowest, most accurate - worth it when your LoRAs are very different from each other, like style + character + concept), turbo/turbo+ sample fewer prefixes for speed. Every candidate is scored on the same subset, so ranking stays fair even at lower settings.
  • memory_mode (default auto) - caches a stack's tuning result across ComfyUI sessions, keyed by LoRA content and config, so re-running the identical stack skips the whole sweep and replays the winning config instantly. This is the single biggest time-saver once you're iterating on the same LoRA combination repeatedly.
  • community_cache (default disabled) - optionally download precomputed results for your exact LoRA files from a shared Hugging Face dataset, keyed by content hash rather than filename, so it matches across users even with different folder layouts. Downloading is anonymous; uploading your own results back requires an HF_TOKEN environment variable.
  • evaluator (optional) - plug in a Build AutoTuner Python Evaluator if you want custom scoring blended into the ranking.

Outputs: model/clip for your sampler, report and analysis_report for Show Text, tuner_data for Merge Selector, lora_data for Save Merged LoRA.

How to install it

ComfyUI Manager: search "LoRA Optimizer", install, restart. Manually:

cd ComfyUI/custom_nodes/
git clone https://github.com/ethanfel/ComfyUI-LoRA-Optimizer.git

Restart - nodes appear under loaders. No model downloads required for the sweep itself; community_cache is the one feature that talks to the network, and only if you turn it on.

Common issues & troubleshooting

It's eating a lot of RAM, especially on video models. This is a real, reported issue, not a hypothetical: someone running the AutoTuner on 3 LoRAs for Wan 2.2 hit a ComfyUI crash after nearly filling 96GB of system RAM. The pack's own author confirmed it directly when asked - the AutoTuner "is rather heavy on resource, there's option to use disk as cache." Concretely: switch diff_cache_mode to disk instead of ram/auto, lower diff_cache_ram_pct, and on video-model stacks specifically, consider merging with the plain Optimizer first and saving the result rather than running a full sweep on every iteration.

A full sweep feels slow. That's expected on a large stack - it's evaluating far more configurations than a single Optimizer run. Drop scoring_speed to turbo+, lower top_n, or lean on memory_mode=auto so you only pay the full cost once per unique stack rather than on every re-run.

You want to explore an alternative to the winning config. Don't re-run the sweep - the tuner_data output already has the ranked list. Feed it into a Merge Selector and change selection to try the 2nd- or 3rd-ranked candidate instead.

Community cache upload isn't working. Uploads specifically need an HF_TOKEN environment variable with write access; downloads (upload_and_download or just reading precomputed results) don't require any setup. If uploads silently don't happen, check that the token is actually set in the environment ComfyUI is running in.

CategoryLoRA Optimizer

Inputs (25)

NameTypeDefaultDescription
modelMODELBase model to merge LoRAs into.
lora_stackLORA_STACKLoRA stack from a LoRA Stack node.
output_strengthFLOAT1.00-1–10Master volume for the merged result. Set to -1 for auto (uses suggested max strength).
clipoptCLIPOptional CLIP model for text-encoder LoRA keys.
clip_strength_multiplieroptFLOAT1.000–10Multiplier for CLIP LoRA strengths.
top_noptINT31–10Number of top configurations to evaluate via actual merge. Higher = slower but explores more options.
normalize_keysoptCOMBOenabledMakes LoRAs from different training tools compatible.
scoring_svdoptCOMBOdisabledSVD-based scoring for ranking configurations. disabled: fast norm-only scoring (usually sufficient). merge_quality: SVD on merged diff tensors — more thorough quality measurement. lora_rank: effective rank of LoRA factors — experimental, changes ranking. full: both merge_quality + lora_rank. With Triton installed, SVD modes are hardware-accelerated and add minimal overhead.
scoring_deviceoptCOMBOgpuDevice for scoring computations. GPU is much faster with SVD scoring modes.
architecture_presetoptCOMBOautoArchitecture-aware threshold tuning. 'auto' detects from LoRA keys. 'acestep_dit' is tuned for ACE-Step music LoRA voice preservation.
auto_strength_flooroptFLOAT-1.00-1–1Floor on how much auto-strength may shrink your LoRA strengths — a uniform down-scale multiplier (never scales UP, never flips signs). 1.0 = don't shrink at all, 0.5 = shrink to at most half, 0 = no floor at all (remove the limit — auto-strength may shrink strengths all the way down), -1 = architecture-aware default. Applies to negative LoRAs by magnitude (sign kept) and to >1.0 strengths. An explicit value ≥0 applies to EVERY stack, not just orthogonal ones.
evaluatoroptAUTOTUNER_EVALUATOROptional external evaluator spec. Use this to blend prompt/reference scoring from your own generation code with the built-in merge metrics.
community_cacheoptCOMBOdisabledCommunity-backed cache on Hugging Face. upload_only: run locally and upload results; do NOT replay HF cache hits (useful for backfill reruns). upload_and_download: download precomputed results and contribute yours back. Requires huggingface-cli login or HF_TOKEN env var.
cache_patchesoptCOMBOenabledCache the AutoTuner result in RAM so re-execution with the same inputs skips the full sweep. Disable to free RAM after merge (recommended for video models).
diff_cache_modeoptCOMBOautoCache LoRA diffs across candidates to skip redundant computation. 'disabled' recomputes each time (no extra memory). 'auto' (recommended) uses RAM up to diff_cache_ram_pct of free memory then recomputes the overflow — low-rank diffs are recomputed anyway (cheaper than a cache read). 'ram' caches entirely in memory (fastest, unbounded). 'disk' caches to temp files (opt-in; only worth it for diffs expensive to recompute on a fast temp volume). Diffs are cached in fp32 so a cache hit is identical to a recompute. WARNING: ram/disk can use significant memory/storage on large models.
diff_cache_ram_pctoptFLOAT0.500.1–0.9Fraction of free system RAM to use for diff cache in 'auto' mode. 0.5 = use up to 50% of available RAM; diffs past that budget are recomputed on demand (not spilled to disk).
vram_budgetoptFLOAT0.000–1Fraction of free VRAM to use for storing merged patches. 0 = all CPU (default), 1.0 = use all free VRAM. Reduces RAM usage on GPU systems.
scoring_speedoptCOMBOturboControls how many prefixes Phase 2 scores per candidate. All candidates are scored on the same subset so ranking stays fair. • full — Score every prefix. Best accuracy, slowest. Use when merging very different LoRAs (e.g. style + character + concept) where block behavior varies a lot. • fast — Every 2nd prefix (~50%% faster). Good default for most merges. • turbo — Every 3rd prefix (~67%% faster). Works well when your LoRAs have similar conflict across blocks (e.g. multiple characters from the same trainer). • turbo+ — Every 4th prefix (~75%% faster). Best for large models (DiT/Flux/WAN) or when iterating quickly. May miss subtle block-level differences on SD/SDXL.
scoring_formulaoptCOMBOv2Phase 2 scoring formula. v2: arch-aware sparsity + energy metrics (recommended). v1: legacy scoring with fixed 40% sparsity target.
output_modeoptCOMBOmergemerge: output the top-ranked merged model. tuning_only: skip the final merge and pass the base model through so a downstream optimizer can apply the selected AutoTuner settings.
decision_smoothingoptFLOAT0.250–1Smooth per-group decision metrics toward each block average before candidate ranking and final merge. 0 disables smoothing.
smooth_slerp_gateoptBOOLEANfalseWhen enabled, uses smoothed cosine (decision_cosine) for SLERP gate instead of raw avg_cos_sim. Can affect SLERP/weighted_average ratio.
memory_modeoptCOMBOautoPersistent memory for tuning results across sessions. auto: Load cached results if available, save after tuning. auto_ignore_strength: Same as auto but the cache key ignores LoRA strengths — useful when sweeping strengths on orthogonal LoRAs where rankings don't change. read_only: Use cached results but don't save new ones. clear_and_run: Delete cached entry and re-tune from scratch. Cache key uses LoRA names + strengths (order-independent) and tuning settings. Does not track LoRA file contents — if you retrain a LoRA with the same filename, use clear_and_run.
selectionoptINT11–10Which ranked configuration to apply (1 = top-ranked). Change this to try a different config without re-running the full sweep.
record_datasetoptCOMBOdisabledAppend analysis metrics and all scored configs to user/lora_optimizer_reports/autotuner_dataset.jsonl for threshold-tuning research. Entries are recorded only when a full sweep runs (cache/memory replays don't add entries).

Outputs (6)

NameTypeDescription
modelMODEL
clipCLIP
reportSTRING
analysis_reportSTRING
tuner_dataTUNER_DATA
lora_dataLORA_DATA